@@ -3,7 +3,7 @@ extern crate chrono;
33use std:: error;
44use std:: io:: prelude:: * ;
55use byteorder:: { ReadBytesExt , WriteBytesExt , BigEndian } ;
6- use self :: chrono:: { Duration , NaiveDate , NaiveTime , NaiveDateTime , DateTime , UTC } ;
6+ use self :: chrono:: { Duration , NaiveDate , NaiveTime , NaiveDateTime , DateTime , UTC , Local , FixedOffset } ;
77
88use Result ;
99use error:: Error ;
@@ -52,6 +52,45 @@ impl ToSql for DateTime<UTC> {
5252 to_sql_checked ! ( ) ;
5353}
5454
55+ impl FromSql for DateTime < Local > {
56+ fn from_sql < R : Read > ( type_ : & Type , raw : & mut R , info : & SessionInfo ) -> Result < DateTime < Local > > {
57+ let utc = try!( DateTime :: < UTC > :: from_sql ( type_, raw, info) ) ;
58+ Ok ( utc. with_timezone ( & Local ) )
59+ }
60+
61+ accepts ! ( Type :: TimestampTZ ) ;
62+ }
63+
64+ impl ToSql for DateTime < Local > {
65+ fn to_sql < W : Write +?Sized > ( & self , type_ : & Type , mut w : & mut W , info : & SessionInfo )
66+ -> Result < IsNull > {
67+ self . with_timezone ( & UTC ) . to_sql ( type_, w, info)
68+ }
69+
70+ accepts ! ( Type :: TimestampTZ ) ;
71+ to_sql_checked ! ( ) ;
72+ }
73+
74+ impl FromSql for DateTime < FixedOffset > {
75+ fn from_sql < R : Read > ( type_ : & Type , raw : & mut R , info : & SessionInfo )
76+ -> Result < DateTime < FixedOffset > > {
77+ let utc = try!( DateTime :: < UTC > :: from_sql ( type_, raw, info) ) ;
78+ Ok ( utc. with_timezone ( & FixedOffset :: east ( 0 ) ) )
79+ }
80+
81+ accepts ! ( Type :: TimestampTZ ) ;
82+ }
83+
84+ impl ToSql for DateTime < FixedOffset > {
85+ fn to_sql < W : Write +?Sized > ( & self , type_ : & Type , mut w : & mut W , info : & SessionInfo )
86+ -> Result < IsNull > {
87+ self . with_timezone ( & UTC ) . to_sql ( type_, w, info)
88+ }
89+
90+ accepts ! ( Type :: TimestampTZ ) ;
91+ to_sql_checked ! ( ) ;
92+ }
93+
5594impl FromSql for NaiveDate {
5695 fn from_sql < R : Read > ( _: & Type , raw : & mut R , _: & SessionInfo ) -> Result < NaiveDate > {
5796 let jd = try!( raw. read_i32 :: < BigEndian > ( ) ) ;
0 commit comments