countrs

Crates.iocountrs
lib.rscountrs
version0.1.6
sourcesrc
created_at2023-04-06 07:02:04.654594
updated_at2023-04-06 11:25:01.515483
descriptionA simple countdown (or up!) with adjustable start and end times
homepage
repositoryhttps://github.com/Fittiboy/countrs
max_upload_size
id831971
size53,891
Fitti (Fittiboy)

documentation

README

About

A counter stores start and end times, and implements Display to either show the time passed since start, or until end, formatted as HH(+):MM:SS.
The timer will not go down past 00:00:00.

Examples

Basic functionality is very simple:

let now = TimeStamp::now();
let mut counter = Counter::down(
    Some(now - 600),
    Some(now + 600)
);

// A small amount of time will have passed since `now` was assigned
assert_eq!(counter.to_string(), "00:09:59");
counter.flip();
// It now counts up from `start`
assert_eq!(counter.to_string(), "00:10:00")

Both start and end times are adjustable:

let mut counter = Counter::up(Some(TimeStamp::now()), None);
counter.try_move_start(-30).unwrap();

assert_eq!(counter.to_string(), "00:00:30")

Documentation

The full documentation is available here on docs.rs!

Motivation

The primary motivation for the creation of this library is the concept of a marathon livestream, where the stream begins with a timer set to e.g. 4 hours at the beginning, and viewers can increase this time by paying.

Commit count: 62

cargo fmt