summaryrefslogtreecommitdiff
path: root/src/datetime.rs
diff options
context:
space:
mode:
authorFredrik Meringdal <fmeringdal@hotmail.com>2020-10-25 23:00:50 +0100
committerFredrik Meringdal <fmeringdal@hotmail.com>2020-10-25 23:00:50 +0100
commitdc44e5f2312bbb8ac411b9dc0b3b52eb3b351b6c (patch)
treeee75b9aeac7c4b18d21b5dd0cb37e9c2098cfc54 /src/datetime.rs
parent55db5800701e9965b19ede01266442b11956b54b (diff)
downloadrust_rrule-dc44e5f2312bbb8ac411b9dc0b3b52eb3b351b6c.zip
restructure files
Diffstat (limited to 'src/datetime.rs')
-rw-r--r--src/datetime.rs16
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,