Skip to content

Commit

Permalink
add datelike impl for Day<Tz>
Browse files Browse the repository at this point in the history
  • Loading branch information
esheppa committed Feb 27, 2023
1 parent d4f8d84 commit f28add5
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions src/day.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use core::ops::Sub;

use crate::oldtime;
use crate::DateTime;
use crate::Datelike;
use crate::Days;
use crate::NaiveDate;
use crate::NaiveTime;
Expand Down Expand Up @@ -119,6 +120,75 @@ where
}
}

impl<Tz> Datelike for Day<Tz>
where
Tz: TimeZone + Copy + Display,
{
fn year(&self) -> i32 {
self.date.year()
}

fn month(&self) -> u32 {
self.date.month()
}

fn month0(&self) -> u32 {
self.date.month0()
}

fn day(&self) -> u32 {
self.date.day()
}

fn day0(&self) -> u32 {
self.date.day0()
}

fn ordinal(&self) -> u32 {
self.date.ordinal()
}

fn ordinal0(&self) -> u32 {
self.date.ordinal0()
}

fn weekday(&self) -> crate::Weekday {
self.date.weekday()
}

fn iso_week(&self) -> crate::IsoWeek {
self.date.iso_week()
}

fn with_year(&self, year: i32) -> Option<Self> {
Some(Self { date: self.date.with_year(year)?, tz: self.tz })
}

fn with_month(&self, month: u32) -> Option<Self> {
Some(Self { date: self.date.with_month(month)?, tz: self.tz })
}

fn with_month0(&self, month0: u32) -> Option<Self> {
Some(Self { date: self.date.with_month0(month0)?, tz: self.tz })
}

fn with_day(&self, day: u32) -> Option<Self> {
Some(Self { date: self.date.with_day(day)?, tz: self.tz })
}

fn with_day0(&self, day0: u32) -> Option<Self> {
Some(Self { date: self.date.with_day0(day0)?, tz: self.tz })
}

fn with_ordinal(&self, ordinal: u32) -> Option<Self> {
Some(Self { date: self.date.with_ordinal(ordinal)?, tz: self.tz })
}

fn with_ordinal0(&self, ordinal0: u32) -> Option<Self> {
Some(Self { date: self.date.with_ordinal0(ordinal0)?, tz: self.tz })
}
}

impl<Tz> Debug for Day<Tz>
where
Tz: TimeZone + Copy + Display,
Expand Down

0 comments on commit f28add5

Please sign in to comment.