1
1
use bytes:: BytesMut ;
2
2
use chrono_04:: { DateTime , Duration , FixedOffset , Local , NaiveDate , NaiveDateTime , NaiveTime , Utc } ;
3
3
use postgres_protocol:: types;
4
- use std:: convert:: TryInto ;
5
4
use std:: error:: Error ;
6
5
7
6
use crate :: { FromSql , IsNull , ToSql , Type } ;
@@ -23,13 +22,9 @@ impl<'a> FromSql<'a> for NaiveDateTime {
23
22
24
23
impl ToSql for NaiveDateTime {
25
24
fn to_sql ( & self , _: & Type , w : & mut BytesMut ) -> Result < IsNull , Box < dyn Error + Sync + Send > > {
26
- let time = match self
27
- . signed_duration_since ( base ( ) )
28
- . whole_microseconds ( )
29
- . try_into ( )
30
- {
31
- Ok ( time) => time,
32
- Err ( _) => return Err ( "value too large to transmit" . into ( ) ) ,
25
+ let time = match self . signed_duration_since ( base ( ) ) . num_microseconds ( ) {
26
+ Some ( time) => time,
27
+ None => return Err ( "value too large to transmit" . into ( ) ) ,
33
28
} ;
34
29
types:: timestamp_to_sql ( time, w) ;
35
30
Ok ( IsNull :: No )
@@ -122,7 +117,7 @@ impl<'a> FromSql<'a> for NaiveDate {
122
117
123
118
impl ToSql for NaiveDate {
124
119
fn to_sql ( & self , _: & Type , w : & mut BytesMut ) -> Result < IsNull , Box < dyn Error + Sync + Send > > {
125
- let jd = self . signed_duration_since ( base ( ) . date ( ) ) . whole_days ( ) ;
120
+ let jd = self . signed_duration_since ( base ( ) . date ( ) ) . num_days ( ) ;
126
121
if jd > i64:: from ( i32:: max_value ( ) ) || jd < i64:: from ( i32:: min_value ( ) ) {
127
122
return Err ( "value too large to transmit" . into ( ) ) ;
128
123
}
@@ -147,9 +142,9 @@ impl<'a> FromSql<'a> for NaiveTime {
147
142
impl ToSql for NaiveTime {
148
143
fn to_sql ( & self , _: & Type , w : & mut BytesMut ) -> Result < IsNull , Box < dyn Error + Sync + Send > > {
149
144
let delta = self . signed_duration_since ( NaiveTime :: from_hms ( 0 , 0 , 0 ) ) ;
150
- let time = match delta. whole_microseconds ( ) . try_into ( ) {
151
- Ok ( time) => time,
152
- Err ( _ ) => return Err ( "value too large to transmit" . into ( ) ) ,
145
+ let time = match delta. num_microseconds ( ) {
146
+ Some ( time) => time,
147
+ None => return Err ( "value too large to transmit" . into ( ) ) ,
153
148
} ;
154
149
types:: time_to_sql ( time, w) ;
155
150
Ok ( IsNull :: No )
0 commit comments