Skip to content

Commit

Permalink
Try to test both time 0.2 and time 0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
paolobarbolini committed Dec 2, 2021
1 parent d7aa838 commit b4eef14
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Expand Up @@ -141,7 +141,8 @@ sqlx-macros = { version = "0.5.9", path = "sqlx-macros", default-features = fals

[dev-dependencies]
anyhow = "1.0.31"
time_ = { version = "0.3.2", package = "time" }
time02_ = { version = "0.2.27", package = "time" }
time03_ = { version = "0.3.2", package = "time" }
futures = "0.3.5"
env_logger = "0.8.3"
async-std = { version = "1.8.0", features = ["attributes"] }
Expand Down
56 changes: 50 additions & 6 deletions tests/postgres/types.rs
@@ -1,5 +1,3 @@
extern crate time_ as time;

use std::ops::Bound;
#[cfg(feature = "decimal")]
use std::str::FromStr;
Expand Down Expand Up @@ -276,11 +274,57 @@ mod chrono {
));
}

#[cfg(feature = "time")]
mod time_tests {
#[cfg(feature = "time-02")]
mod time02_tests {
extern crate time02_ as time;

use super::*;
use time::{date, time, Date, OffsetDateTime, PrimitiveDateTime, Time, UtcOffset};

type PgTimeTz = sqlx::postgres::types::PgTimeTz<Time, UtcOffset>;

test_type!(time_date<Date>(
Postgres,
"DATE '2001-01-05'" == date!(2001 - 1 - 5),
"DATE '2050-11-23'" == date!(2050 - 11 - 23)
));

test_type!(time_time<Time>(
Postgres,
"TIME '05:10:20.115100'" == time!(5:10:20.115100)
));

test_type!(time_date_time<PrimitiveDateTime>(
Postgres,
"TIMESTAMP '2019-01-02 05:10:20'" == date!(2019 - 1 - 2).with_time(time!(5:10:20)),
"TIMESTAMP '2019-01-02 05:10:20.115100'" == date!(2019 - 1 - 2).with_time(time!(5:10:20.115100))
));

test_type!(time_timestamp<OffsetDateTime>(
Postgres,
"TIMESTAMPTZ '2019-01-02 05:10:20.115100'"
== date!(2019 - 1 - 2)
.with_time(time!(5:10:20.115100))
.assume_utc()
));

test_prepared_type!(time_time_tz<PgTimeTz>(Postgres,
"TIMETZ '05:10:20.115100+00'" == PgTimeTz { time: time!(5:10:20.115100), offset: UtcOffset::east_seconds(0) },
"TIMETZ '05:10:20.115100+06:30'" == PgTimeTz { time: time!(5:10:20.115100), offset: UtcOffset::east_seconds(60 * 60 * 6 + 1800) },
"TIMETZ '05:10:20.115100-05'" == PgTimeTz { time: time!(5:10:20.115100), offset: UtcOffset::west_seconds(60 * 60 * 5) },
"TIMETZ '05:10:20+02'" == PgTimeTz { time: time!(5:10:20), offset: UtcOffset::east_seconds(60 * 60 * 2 )}
));
}

#[cfg(feature = "time-03")]
mod time03_tests {
extern crate time03_ as time;

use super::*;
use sqlx::types::time::{Date, OffsetDateTime, PrimitiveDateTime, Time, UtcOffset};
use time::macros::{date, time};
use time::{
macros::{date, time},
Date, OffsetDateTime, PrimitiveDateTime, Time, UtcOffset,
};

type PgTimeTz = sqlx::postgres::types::PgTimeTz<Time, UtcOffset>;

Expand Down

0 comments on commit b4eef14

Please sign in to comment.