Skip to content

replace deprecated chrono::DateTime::from_utc #1077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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