Skip to content

Commit

Permalink
Merge pull request #1077 from ds-cbo/fix-deprecated-chrono-func
Browse files Browse the repository at this point in the history
replace deprecated chrono::DateTime::from_utc
  • Loading branch information
sfackler authored Oct 31, 2023
2 parents c5ff8cf + 19a6ef7 commit ab23ca8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
6 changes: 4 additions & 2 deletions postgres-types/src/chrono_04.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use bytes::BytesMut;
use chrono_04::{DateTime, Duration, FixedOffset, Local, NaiveDate, NaiveDateTime, NaiveTime, Utc};
use chrono_04::{
DateTime, Duration, FixedOffset, Local, NaiveDate, NaiveDateTime, NaiveTime, TimeZone, Utc,
};
use postgres_protocol::types;
use std::error::Error;

Expand Down Expand Up @@ -40,7 +42,7 @@ impl ToSql for NaiveDateTime {
impl<'a> FromSql<'a> for DateTime<Utc> {
fn from_sql(type_: &Type, raw: &[u8]) -> Result<DateTime<Utc>, Box<dyn Error + Sync + Send>> {
let naive = NaiveDateTime::from_sql(type_, raw)?;
Ok(DateTime::from_utc(naive, Utc))
Ok(Utc.from_utc_datetime(&naive))
}

accepts!(TIMESTAMPTZ);
Expand Down
14 changes: 6 additions & 8 deletions tokio-postgres/tests/test/types/chrono_04.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ async fn test_with_special_naive_date_time_params() {
async fn test_date_time_params() {
fn make_check(time: &str) -> (Option<DateTime<Utc>>, &str) {
(
Some(
Utc.datetime_from_str(time, "'%Y-%m-%d %H:%M:%S.%f'")
.unwrap(),
),
Some(Utc.from_utc_datetime(
&NaiveDateTime::parse_from_str(time, "'%Y-%m-%d %H:%M:%S.%f'").unwrap(),
)),
time,
)
}
Expand All @@ -76,10 +75,9 @@ async fn test_date_time_params() {
async fn test_with_special_date_time_params() {
fn make_check(time: &str) -> (Timestamp<DateTime<Utc>>, &str) {
(
Timestamp::Value(
Utc.datetime_from_str(time, "'%Y-%m-%d %H:%M:%S.%f'")
.unwrap(),
),
Timestamp::Value(Utc.from_utc_datetime(
&NaiveDateTime::parse_from_str(time, "'%Y-%m-%d %H:%M:%S.%f'").unwrap(),
)),
time,
)
}
Expand Down

0 comments on commit ab23ca8

Please sign in to comment.