use ::chrono::TimeZone as _;
use super::common::Sealed;
use super::DateBackend;
#[derive(Debug, Clone, Copy)]
pub struct Chrono;
impl Sealed for Chrono {}
impl DateBackend for Chrono {
type Date = ::chrono::NaiveDate;
type DateTime = ::chrono::DateTime<::chrono::Utc>;
type Time = ::chrono::NaiveTime;
fn parse_date(s: &str) -> Option<Self::Date> {
::chrono::NaiveDate::parse_from_str(s, "%Y-%m-%d").ok()
}
fn parse_time(s: &str) -> Option<Self::Time> {
::chrono::NaiveTime::parse_from_str(s, "%H:%M:%S%.f").ok()
}
fn naive_to_utc(naive: &str, offset_seconds: i32) -> Option<Self::DateTime> {
let ndt = ::chrono::NaiveDateTime::parse_from_str(naive, "%Y-%m-%dT%H:%M:%S%.f").ok()?;
::chrono::FixedOffset::east_opt(offset_seconds)?
.from_local_datetime(&ndt)
.single()
.map(|dt| dt.with_timezone(&::chrono::Utc))
}
fn today() -> Self::Date {
::chrono::Utc::now().date_naive()
}
fn now() -> Self::DateTime {
::chrono::Utc::now()
}
fn format_datetime(dt: &Self::DateTime) -> String {
dt.to_rfc3339()
}
}
pub type ZDate = super::ZDate<Chrono>;
pub type ZDateTime = super::ZDateTime<Chrono>;
pub fn date() -> ZDate {
ZDate::new()
}
pub fn datetime() -> ZDateTime {
ZDateTime::new()
}
pub type ZTime = super::ZTime<Chrono>;
pub fn time() -> ZTime {
ZTime::new()
}