Add FromSql to chrono DateTime<Local>
extern crate chrono;
use self::chrono::naive::MAX_DATE;
-use self::chrono::{DateTime, Duration, NaiveDate, NaiveDateTime, NaiveTime, TimeZone, Utc};
+use self::chrono::{DateTime, Duration, Local, NaiveDate, NaiveDateTime, NaiveTime, TimeZone, Utc};
use std::io::Write;
use super::{PgDate, PgTime, PgTimestamp};
@@ -64,6 +64,13 @@ impl FromSql<Timestamptz, Pg> for DateTime<Utc> {
}
}
+impl FromSql<Timestamptz, Pg> for DateTime<Local> {
+ fn from_sql(bytes: Option<PgValue<'_>>) -> deserialize::Result<Self> {
+ let naive_date_time = <NaiveDateTime as FromSql<Timestamptz, Pg>>::from_sql(bytes)?;
+ Ok(Local::from_utc_datetime(&Local, &naive_date_time))
+ }
+}
+
impl<TZ: TimeZone> ToSql<Timestamptz, Pg> for DateTime<TZ> {
fn to_sql<W: Write>(&self, out: &mut Output<W, Pg>) -> serialize::Result {
ToSql::<Timestamptz, Pg>::to_sql(&self.naive_utc(), out)
