From 923e30b1bac5485075df893e8c5ef2d0346bf251 Mon Sep 17 00:00:00 2001 From: Botahamec Date: Mon, 17 Jan 2022 17:19:53 -0500 Subject: simple but useless datetime with time zones --- src/datetime.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'src/datetime.rs') diff --git a/src/datetime.rs b/src/datetime.rs index 54685ec..c739d46 100644 --- a/src/datetime.rs +++ b/src/datetime.rs @@ -1,4 +1,4 @@ -use crate::{Date, Month, Time, Year}; +use crate::{timezone::UtcOffset, Date, Month, Time, TimeZone, Year}; #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct NaiveDateTime { @@ -6,6 +6,35 @@ pub struct NaiveDateTime { time: Time, } +#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] +pub struct DateTime { + utc_datetime: NaiveDateTime, + timezone: Tz, +} + +impl DateTime { + // TODO unix epoch constant + + pub fn from_utc(utc_datetime: NaiveDateTime, timezone: Tz) -> Self { + Self { + utc_datetime, + timezone, + } + } + + pub fn offset(&self) -> UtcOffset { + self.timezone.utc_offset(self.utc_datetime) + } + + pub fn timezone(&self) -> &Tz { + &self.timezone + } + + pub fn naive_utc(&self) -> NaiveDateTime { + self.utc_datetime + } +} + impl NaiveDateTime { // TODO docs -- cgit v1.2.3