Skip to content

Commit 278f240

Browse files
committed
Revert "Update APIs for fork of chrono"
This reverts commit bef6bc0.
1 parent bef6bc0 commit 278f240

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

postgres-types/src/chrono_04.rs

+7-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use bytes::BytesMut;
22
use chrono_04::{DateTime, Duration, FixedOffset, Local, NaiveDate, NaiveDateTime, NaiveTime, Utc};
33
use postgres_protocol::types;
4-
use std::convert::TryInto;
54
use std::error::Error;
65

76
use crate::{FromSql, IsNull, ToSql, Type};
@@ -23,13 +22,9 @@ impl<'a> FromSql<'a> for NaiveDateTime {
2322

2423
impl ToSql for NaiveDateTime {
2524
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()),
3328
};
3429
types::timestamp_to_sql(time, w);
3530
Ok(IsNull::No)
@@ -122,7 +117,7 @@ impl<'a> FromSql<'a> for NaiveDate {
122117

123118
impl ToSql for NaiveDate {
124119
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();
126121
if jd > i64::from(i32::max_value()) || jd < i64::from(i32::min_value()) {
127122
return Err("value too large to transmit".into());
128123
}
@@ -147,9 +142,9 @@ impl<'a> FromSql<'a> for NaiveTime {
147142
impl ToSql for NaiveTime {
148143
fn to_sql(&self, _: &Type, w: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
149144
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()),
153148
};
154149
types::time_to_sql(time, w);
155150
Ok(IsNull::No)

0 commit comments

Comments
 (0)