#date-time #duration #time #date #leap-year

rapid_time

A library for datetimes and durations, which are useful to model times in combinatorial optimization problems

3 releases

0.1.2 Jul 8, 2024
0.1.1 Jul 8, 2024
0.1.0 Jul 8, 2024

#148 in Date and time


Used in rapid_solve

MIT license

40KB
851 lines

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

No runtime deps