use crate::Error;
use crate::Formatable;
use crate::NaiveDateSpan;
use crate::Span;
use crate::Spanable;
use chrono::format::{DelayedFormat, StrftimeItems};
use chrono::{Date, Duration, TimeZone};
use std;
impl<T: TimeZone> Spanable for Date<T>
where
<T as TimeZone>::Offset: std::marker::Copy,
{
#[inline]
fn signed_duration_since(self, other: Self) -> Duration {
Date::signed_duration_since(self, other)
}
}
impl<T: TimeZone> Formatable for Date<T>
where
<T as TimeZone>::Offset: std::fmt::Display,
{
#[inline]
fn format<'a>(&self, fmt: &'a str) -> DelayedFormat<StrftimeItems<'a>> {
Date::format(self, fmt)
}
}
pub type DateSpan<T> = Span<Date<T>>;
impl<T: TimeZone> DateSpan<T> {
pub fn from_local_datespan(span: &NaiveDateSpan, tz: &T) -> Result<Self, Error> {
Ok(DateSpan {
start: tz
.from_local_date(&span.start)
.single()
.ok_or(Error::LocalAmbigious)?,
end: tz
.from_local_date(&span.end)
.single()
.ok_or(Error::LocalAmbigious)?,
})
}
pub fn from_utc_datespan(span: &NaiveDateSpan, tz: &T) -> Self {
DateSpan {
start: tz.from_utc_date(&span.start),
end: tz.from_utc_date(&span.end),
}
}
}