summaryrefslogtreecommitdiff
path: root/src/datetime.rs
diff options
context:
space:
mode:
authorBotahamec <botahamec@outlook.com>2022-01-17 17:19:53 -0500
committerBotahamec <botahamec@outlook.com>2022-01-17 17:19:53 -0500
commit923e30b1bac5485075df893e8c5ef2d0346bf251 (patch)
treefad517c55f4a5291f1d089935015d4203c041377 /src/datetime.rs
parentdb37142af48a821fe69f9d6a5ea933e65bd0436f (diff)
simple but useless datetime with time zones
Diffstat (limited to 'src/datetime.rs')
-rw-r--r--src/datetime.rs31
1 files changed, 30 insertions, 1 deletions
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<Tz: TimeZone> {
+ utc_datetime: NaiveDateTime,
+ timezone: Tz,
+}
+
+impl<Tz: TimeZone> DateTime<Tz> {
+ // 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