2 unstable releases

0.2.0 Jun 12, 2023
0.1.0 Jun 10, 2023

#463 in Date and time

MIT license

12KB
216 lines

movement

Build Status Downloads Version License

Simple library and command to help out with time calculations (e.g. 1:23 PM + 3:30)

Installation

cargo add movement

Usage

fn adding_with_str() {
    let mut watch = Watch::new("2:15:01 A.M", true);
    watch += "3:14";
    println!("{}", watch);
    // outputs 05:29:01 AM
}

fn subtracting_with_secs() {
    let mut watch = Watch::new("13:34", true);
    watch += 4343;
    println!("{}", watch);
    // outputs 02:46:23 PM
}

lib.rs:

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

No runtime deps