fastdate/
lib.rs

1#![allow(unused_assignments)]
2
3pub extern crate time1;
4
5pub mod error;
6pub mod sys;
7
8mod date;
9mod datetime;
10mod time;
11
12pub use date::*;
13pub use datetime::*;
14use std::time::Duration;
15pub use time::*;
16
17// get a character from the bytes as as a decimal
18macro_rules! get_digit {
19    ($bytes:ident, $index:expr, $error:expr) => {
20        match $bytes.get($index) {
21            Some(c) if c.is_ascii_digit() => c - b'0',
22            _ => return Err(Error::E($error.to_string())),
23        }
24    };
25}
26pub(crate) use get_digit;
27// as above without bounds check, requires length to checked first!
28macro_rules! get_digit_unchecked {
29    ($bytes:ident, $index:expr, $error:expr) => {
30        match $bytes.get_unchecked($index) {
31            c if c.is_ascii_digit() => c - b'0',
32            _ => return Err(Error::E($error.to_string())),
33        }
34    };
35}
36pub(crate) use get_digit_unchecked;
37
38pub trait DurationFrom {
39    fn from_minute(minute: u64) -> Self;
40    fn from_hour(hour: u64) -> Self;
41    fn from_day(day: u64) -> Self;
42}
43
44impl DurationFrom for Duration {
45    #[inline]
46    fn from_minute(minute: u64) -> Self {
47        Duration::from_secs(minute * 60)
48    }
49    #[inline]
50    fn from_hour(hour: u64) -> Self {
51        Duration::from_minute(hour * 60)
52    }
53    #[inline]
54    fn from_day(day: u64) -> Self {
55        Duration::from_hour(day * 24)
56    }
57}