Skip to content
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

Fix chrono::DateTime<Utc> tests #1170

Merged
merged 1 commit into from
Aug 16, 2024
Merged
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
30 changes: 17 additions & 13 deletions tokio-postgres/tests/test/types/chrono_04.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use chrono_04::{DateTime, NaiveDate, NaiveDateTime, NaiveTime, TimeZone, Utc};
use chrono_04::{DateTime, NaiveDate, NaiveDateTime, NaiveTime, Utc};
use std::fmt;
use tokio_postgres::types::{Date, FromSqlOwned, Timestamp};
use tokio_postgres::Client;
Expand Down Expand Up @@ -53,18 +53,20 @@ 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.from_utc_datetime(
&NaiveDateTime::parse_from_str(time, "'%Y-%m-%d %H:%M:%S.%f'").unwrap(),
)),
Some(
DateTime::parse_from_str(time, "'%Y-%m-%d %H:%M:%S.%f%#z'")
.unwrap()
.to_utc(),
),
time,
)
}
test_type(
"TIMESTAMP WITH TIME ZONE",
&[
make_check("'1970-01-01 00:00:00.010000000'"),
make_check("'1965-09-25 11:19:33.100314000'"),
make_check("'2010-02-09 23:11:45.120200000'"),
make_check("'1970-01-01 00:00:00.010000000Z'"),
make_check("'1965-09-25 11:19:33.100314000Z'"),
make_check("'2010-02-09 23:11:45.120200000Z'"),
(None, "NULL"),
],
)
Expand All @@ -75,18 +77,20 @@ 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.from_utc_datetime(
&NaiveDateTime::parse_from_str(time, "'%Y-%m-%d %H:%M:%S.%f'").unwrap(),
)),
Timestamp::Value(
DateTime::parse_from_str(time, "'%Y-%m-%d %H:%M:%S.%f%#z'")
.unwrap()
.to_utc(),
),
time,
)
}
test_type(
"TIMESTAMP WITH TIME ZONE",
&[
make_check("'1970-01-01 00:00:00.010000000'"),
make_check("'1965-09-25 11:19:33.100314000'"),
make_check("'2010-02-09 23:11:45.120200000'"),
make_check("'1970-01-01 00:00:00.010000000Z'"),
make_check("'1965-09-25 11:19:33.100314000Z'"),
make_check("'2010-02-09 23:11:45.120200000Z'"),
(Timestamp::PosInfinity, "'infinity'"),
(Timestamp::NegInfinity, "'-infinity'"),
],
Expand Down
Loading