Crate movement

source ·
Expand description

A simple library that helps with time calculations. The most common use case would be to calculate the end time of a watch given the start time and the time span. Internally, the library uses i64 to represent time in seconds. From there, you can convert the time to a string in either 12h or 24h format by using the fmt::Display trait.

Usage

Initialize a watch with the start time and meridiem option as the arguments. The start time can be in either 12h or 24h format. The meridiem option is a bool that represents whether the watch is in 12h or 24h format (true for 12h). The default display format is HH:MM:SS and +/- days.

Examples

use movement::Watch;

let mut watch = Watch::new("13:34", true);
watch += "01:23:45";
watch += 43434343;
println!("{}", watch);
// 08:03:28 AM +503 days
use movement::Watch;

let mut watch = Watch::new("01:34 AM", false);
watch += "01:23:45";
watch -= 1000000;
println!("{}", watch);
// 13:11:05 -12 days
use movement::Watch;

let mut watch = Watch::new("13:34", true);
let new_watch = watch + "01:23:45";
println!("{}", new_watch);
// 02:57:45 PM

Structs

  • A struct that represents a watch which keeps track of the start time, offset, and meridiem. Can be addded and subtracted with i64 and &str. i64 will be treated as seconds and &str will be treated as a time string (e.g. “01:23:45”). The default display format is HH:MM:SS and +/- days.