Skip to content

Commit

Permalink
feat: add type conversion DatePerhapsTime <-> NaiveDate
Browse files Browse the repository at this point in the history
  • Loading branch information
arichtman committed Nov 7, 2024
1 parent 1aa79db commit 8a4e353
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/components/date_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,17 @@ pub fn with_timezone<T: chrono::TimeZone + chrono_tz::OffsetName>(
.into()
}

impl From<DatePerhapsTime> for NaiveDate {
fn from(dt: DatePerhapsTime) -> Self {
match dt {
DatePerhapsTime::Date(date) => date,
DatePerhapsTime::DateTime(CalendarDateTime::Floating(date_time)) => date_time.date(),
DatePerhapsTime::DateTime(CalendarDateTime::Utc(date_time)) => date_time.date_naive(),
DatePerhapsTime::DateTime(CalendarDateTime::WithTimezone { date_time, tzid: _ }) => date_time.date(),
}
}
}

impl From<CalendarDateTime> for DatePerhapsTime {
fn from(dt: CalendarDateTime) -> Self {
Self::DateTime(dt)
Expand Down

0 comments on commit 8a4e353

Please sign in to comment.