rapid_time

Crates.iorapid_time
lib.rsrapid_time
version0.1.2
sourcesrc
created_at2024-07-08 20:04:20.219172
updated_at2024-07-08 21:53:14.265551
descriptionA library for datetimes and durations, which are useful to model times in combinatorial optimization problems.
homepage
repositoryhttps://github.com/LeonSering/rapid_time
max_upload_size
id1296329
size39,195
Leon Sering (LeonSering)

documentation

README

RapidTime RapidTime crate RapidTime documentation

This crate defines two types: DateTime and Duration, which are useful to model times in combinatorial optimization problems.

Usage

  • Basic Usage
use rapid_time::{DateTime, Duration};
let tour_start = DateTime::new("2024-02-28T08:00:00");
let tour_length = Duration::new("100:00:00");
let tour_end = DateTime::new("2024-03-03T12:00:00");
assert_eq!(tour_start + tour_length, tour_end);
assert_eq!(tour_end - tour_start, tour_length);
assert_eq!(tour_end - tour_length, tour_start);
// Note that 2024 is a leap year.
# use rapid_time::{DateTime, Duration};
assert_eq!(DateTime::Earliest + Duration::new("10000:00:00"), DateTime::Earliest);
assert_eq!(DateTime::new("0000-01-01T00:00:00") + Duration::Infinity, DateTime::Latest);
assert_eq!(DateTime::Latest - DateTime::Earliest, Duration::Infinity);
assert_eq!(DateTime::Earliest + Duration::Infinity, DateTime::Latest);
# use rapid_time::{DateTime, Duration};
assert_eq!(Duration::new("1:00:00") + Duration::from_seconds(120), Duration::new("1:02:00"));
assert_eq!(Duration::new("100:00:00").in_sec().unwrap(), 100 * 3600);
assert_eq!(Duration::from_iso("P10DT2H00M59S").in_min().unwrap(), 10 * 24 * 60 + 2 * 60);
// Duration::from_seconds(10) - Duration::from_seconds(20); // panics
# use rapid_time::{DateTime, Duration};
assert_eq!(DateTime::new("2024-02-28T08:30").as_iso(), "2024-02-28T08:30:00");
// DateTime::new("2024-01-01T08:00") - DateTime::new("2024-01-01T09:00"); // panics
Commit count: 11

cargo fmt