1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#![allow(unused_assignments)]

pub extern crate time1;

pub mod error;
#[cfg(not(tarpaulin_include))]
pub mod sys;

mod date;
mod datetime;
mod time;

pub use date::*;
pub use datetime::*;
use std::time::Duration;
pub use time::*;

// get a character from the bytes as as a decimal
macro_rules! get_digit {
    ($bytes:ident, $index:expr, $error:expr) => {
        match $bytes.get($index) {
            Some(c) if (b'0'..=b'9').contains(&c) => c - b'0',
            _ => return Err(Error::E($error.to_string())),
        }
    };
}
pub(crate) use get_digit;
// as above without bounds check, requires length to checked first!
macro_rules! get_digit_unchecked {
    ($bytes:ident, $index:expr, $error:expr) => {
        match $bytes.get_unchecked($index) {
            c if (b'0'..=b'9').contains(&c) => c - b'0',
            _ => return Err(Error::E($error.to_string())),
        }
    };
}
pub(crate) use get_digit_unchecked;

pub trait DurationFrom {
    fn from_minute(minute: u64) -> Self;
    fn from_hour(hour: u64) -> Self;
    fn from_day(day: u64) -> Self;
}

impl DurationFrom for Duration {
    #[inline]
    fn from_minute(minute: u64) -> Self {
        Duration::from_secs(minute * 60)
    }
    #[inline]
    fn from_hour(hour: u64) -> Self {
        Duration::from_minute(hour * 60)
    }
    #[inline]
    fn from_day(day: u64) -> Self {
        Duration::from_hour(day * 24)
    }
}