diff options
author | Fredrik Meringdal <fmeringdal@hotmail.com> | 2020-10-25 23:00:50 +0100 |
---|---|---|
committer | Fredrik Meringdal <fmeringdal@hotmail.com> | 2020-10-25 23:00:50 +0100 |
commit | dc44e5f2312bbb8ac411b9dc0b3b52eb3b351b6c (patch) | |
tree | ee75b9aeac7c4b18d21b5dd0cb37e9c2098cfc54 /src/datetime.rs | |
parent | 55db5800701e9965b19ede01266442b11956b54b (diff) | |
download | rust_rrule-dc44e5f2312bbb8ac411b9dc0b3b52eb3b351b6c.zip |
restructure files
Diffstat (limited to 'src/datetime.rs')
-rw-r--r-- | src/datetime.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/datetime.rs b/src/datetime.rs index 871ccfa..2e06d24 100644 --- a/src/datetime.rs +++ b/src/datetime.rs @@ -1,3 +1,19 @@ +use chrono::prelude::*; +use chrono_tz::Tz; + + +pub type DTime = DateTime<Tz>; + +pub fn from_ordinal(ordinal: isize) -> DateTime<Utc> { + let timestamp = ordinal * 24 * 60 * 60; + let naive = NaiveDateTime::from_timestamp(timestamp as i64, 0); + DateTime::from_utc(naive, Utc) +} + +pub fn to_ordinal(date: &DateTime<Utc>) -> isize { + (date.timestamp() / 60 / 60 / 24) as isize +} + #[derive(Debug)] pub struct Time { pub hour: usize, |