summaryrefslogtreecommitdiff
path: root/src/datetime.rs
diff options
context:
space:
mode:
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,