From 8a4e353127c3cf93a1a975806e9ed5a9fbdb0000 Mon Sep 17 00:00:00 2001 From: Ariel Richtman <10679234+arichtman@users.noreply.github.com> Date: Fri, 8 Nov 2024 09:53:03 +1000 Subject: [PATCH] feat: add type conversion DatePerhapsTime <-> NaiveDate Refs: #118 --- src/components/date_time.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/components/date_time.rs b/src/components/date_time.rs index 0ecb569..b45bd33 100644 --- a/src/components/date_time.rs +++ b/src/components/date_time.rs @@ -281,6 +281,17 @@ pub fn with_timezone( .into() } +impl From 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 for DatePerhapsTime { fn from(dt: CalendarDateTime) -> Self { Self::DateTime(dt)