@@ -3,7 +3,7 @@ extern crate chrono;
3
3
use std:: error;
4
4
use std:: io:: prelude:: * ;
5
5
use 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 } ;
7
7
8
8
use Result ;
9
9
use error:: Error ;
@@ -52,6 +52,45 @@ impl ToSql for DateTime<UTC> {
52
52
to_sql_checked ! ( ) ;
53
53
}
54
54
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
+
55
94
impl FromSql for NaiveDate {
56
95
fn from_sql < R : Read > ( _: & Type , raw : & mut R , _: & SessionInfo ) -> Result < NaiveDate > {
57
96
let jd = try!( raw. read_i32 :: < BigEndian > ( ) ) ;
0 commit comments