Skip to content

Commit 70d65c5

Browse files
CommanderStormjrasanen
authored andcommitted
fixed deprecation warnings (launchbadge#3384)
1 parent 125ff62 commit 70d65c5

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

tests/postgres/types.rs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -260,51 +260,49 @@ mod chrono {
260260
type PgTimeTz = sqlx::postgres::types::PgTimeTz<NaiveTime, FixedOffset>;
261261

262262
test_type!(chrono_date<NaiveDate>(Postgres,
263-
"DATE '2001-01-05'" == NaiveDate::from_ymd(2001, 1, 5),
264-
"DATE '2050-11-23'" == NaiveDate::from_ymd(2050, 11, 23)
263+
"DATE '2001-01-05'" == NaiveDate::from_ymd_opt(2001, 1, 5).unwrap(),
264+
"DATE '2050-11-23'" == NaiveDate::from_ymd_opt(2050, 11, 23).unwrap()
265265
));
266266

267267
test_type!(chrono_time<NaiveTime>(Postgres,
268-
"TIME '05:10:20.115100'" == NaiveTime::from_hms_micro(5, 10, 20, 115100)
268+
"TIME '05:10:20.115100'" == NaiveTime::from_hms_micro_opt(5, 10, 20, 115100).unwrap()
269269
));
270270

271271
test_type!(chrono_date_time<NaiveDateTime>(Postgres,
272-
"'2019-01-02 05:10:20'::timestamp" == NaiveDate::from_ymd(2019, 1, 2).and_hms(5, 10, 20)
272+
"'2019-01-02 05:10:20'::timestamp" == NaiveDate::from_ymd_opt(2019, 1, 2).unwrap().and_hms_opt(5, 10, 20).unwrap()
273273
));
274274

275275
test_type!(chrono_date_time_vec<Vec<NaiveDateTime>>(Postgres,
276276
"array['2019-01-02 05:10:20']::timestamp[]"
277-
== vec![NaiveDate::from_ymd(2019, 1, 2).and_hms(5, 10, 20)]
277+
== vec![NaiveDate::from_ymd_opt(2019, 1, 2).unwrap().and_hms_opt(5, 10, 20).unwrap()]
278278
));
279279

280280
test_type!(chrono_date_time_tz_utc<DateTime::<Utc>>(Postgres,
281281
"TIMESTAMPTZ '2019-01-02 05:10:20.115100'"
282-
== DateTime::<Utc>::from_utc(
283-
NaiveDate::from_ymd(2019, 1, 2).and_hms_micro(5, 10, 20, 115100),
284-
Utc,
282+
== Utc.from_utc_datetime(
283+
&NaiveDate::from_ymd_opt(2019, 1, 2).unwrap().and_hms_micro_opt(5, 10, 20, 115100).unwrap(),
285284
)
286285
));
287286

288287
test_type!(chrono_date_time_tz<DateTime::<FixedOffset>>(Postgres,
289288
"TIMESTAMPTZ '2019-01-02 05:10:20.115100+06:30'"
290-
== FixedOffset::east(60 * 60 * 6 + 1800).ymd(2019, 1, 2).and_hms_micro(5, 10, 20, 115100)
289+
== FixedOffset::east_opt(60 * 60 * 6 + 1800).unwrap().ymd(2019, 1, 2).and_hms_micro_opt(5, 10, 20, 115100).unwrap()
291290
));
292291

293292
test_type!(chrono_date_time_tz_vec<Vec<DateTime::<Utc>>>(Postgres,
294293
"array['2019-01-02 05:10:20.115100']::timestamptz[]"
295294
== vec![
296-
DateTime::<Utc>::from_utc(
297-
NaiveDate::from_ymd(2019, 1, 2).and_hms_micro(5, 10, 20, 115100),
298-
Utc,
295+
Utc.from_utc_datetime(
296+
&NaiveDate::from_ymd_opt(2019, 1, 2).unwrap().and_hms_micro_opt(5, 10, 20, 115100).unwrap(),
299297
)
300298
]
301299
));
302300

303301
test_type!(chrono_time_tz<PgTimeTz>(Postgres,
304-
"TIMETZ '05:10:20.115100+00'" == PgTimeTz { time: NaiveTime::from_hms_micro(5, 10, 20, 115100), offset: FixedOffset::east(0) },
305-
"TIMETZ '05:10:20.115100+06:30'" == PgTimeTz { time: NaiveTime::from_hms_micro(5, 10, 20, 115100), offset: FixedOffset::east(60 * 60 * 6 + 1800) },
306-
"TIMETZ '05:10:20.115100-05'" == PgTimeTz { time: NaiveTime::from_hms_micro(5, 10, 20, 115100), offset: FixedOffset::west(60 * 60 * 5) },
307-
"TIMETZ '05:10:20+02'" == PgTimeTz { time: NaiveTime::from_hms(5, 10, 20), offset: FixedOffset::east(60 * 60 * 2 )}
302+
"TIMETZ '05:10:20.115100+00'" == PgTimeTz { time: NaiveTime::from_hms_micro_opt(5, 10, 20, 115100).unwrap(), offset: FixedOffset::east_opt(0).unwrap() },
303+
"TIMETZ '05:10:20.115100+06:30'" == PgTimeTz { time: NaiveTime::from_hms_micro_opt(5, 10, 20, 115100).unwrap(), offset: FixedOffset::east_opt(60 * 60 * 6 + 1800).unwrap() },
304+
"TIMETZ '05:10:20.115100-05'" == PgTimeTz { time: NaiveTime::from_hms_micro_opt(5, 10, 20, 115100).unwrap(), offset: FixedOffset::west_opt(60 * 60 * 5).unwrap() },
305+
"TIMETZ '05:10:20+02'" == PgTimeTz { time: NaiveTime::from_hms_opt(5, 10, 20).unwrap(), offset: FixedOffset::east_opt(60 * 60 * 2 ).unwrap() }
308306
));
309307
}
310308

@@ -586,7 +584,7 @@ test_prepared_type!(citext_array<Vec<PgCiText>>(Postgres,
586584
#[cfg(any(postgres_14, postgres_15))]
587585
test_type!(ltree<sqlx::postgres::types::PgLTree>(Postgres,
588586
"'Foo.Bar.Baz.Quux'::ltree" == sqlx::postgres::types::PgLTree::from_str("Foo.Bar.Baz.Quux").unwrap(),
589-
"'Alpha.Beta.Delta.Gamma'::ltree" == sqlx::postgres::types::PgLTree::from_iter(["Alpha", "Beta", "Delta", "Gamma"]).unwrap(),
587+
"'Alpha.Beta.Delta.Gamma'::ltree" == sqlx::postgres::types::PgLTree::try_from_iter(["Alpha", "Beta", "Delta", "Gamma"]).unwrap(),
590588
));
591589

592590
// FIXME: needed to disable `ltree` tests in version that don't have a binary format for it
@@ -596,7 +594,7 @@ test_type!(ltree_vec<Vec<sqlx::postgres::types::PgLTree>>(Postgres,
596594
"array['Foo.Bar.Baz.Quux', 'Alpha.Beta.Delta.Gamma']::ltree[]" ==
597595
vec![
598596
sqlx::postgres::types::PgLTree::from_str("Foo.Bar.Baz.Quux").unwrap(),
599-
sqlx::postgres::types::PgLTree::from_iter(["Alpha", "Beta", "Delta", "Gamma"]).unwrap()
597+
sqlx::postgres::types::PgLTree::try_from_iter(["Alpha", "Beta", "Delta", "Gamma"]).unwrap()
600598
]
601599
));
602600

tests/sqlite/types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,15 @@ mod chrono {
100100
use sqlx::types::chrono::{DateTime, FixedOffset, NaiveDate, NaiveDateTime, TimeZone, Utc};
101101

102102
test_type!(chrono_naive_date_time<NaiveDateTime>(Sqlite, "SELECT datetime({0}) is datetime(?), {0}, ?",
103-
"'2019-01-02 05:10:20'" == NaiveDate::from_ymd(2019, 1, 2).and_hms(5, 10, 20)
103+
"'2019-01-02 05:10:20'" == NaiveDate::from_ymd_opt(2019, 1, 2).unwrap().and_hms_opt(5, 10, 20).unwrap()
104104
));
105105

106106
test_type!(chrono_date_time_utc<DateTime::<Utc>>(Sqlite, "SELECT datetime({0}) is datetime(?), {0}, ?",
107-
"'1996-12-20T00:39:57+00:00'" == Utc.ymd(1996, 12, 20).and_hms(0, 39, 57)
107+
"'1996-12-20T00:39:57+00:00'" == Utc.with_ymd_and_hms(1996, 12, 20, 0, 39, 57).unwrap()
108108
));
109109

110110
test_type!(chrono_date_time_fixed_offset<DateTime::<FixedOffset>>(Sqlite, "SELECT datetime({0}) is datetime(?), {0}, ?",
111-
"'2016-11-08T03:50:23-05:00'" == DateTime::<Utc>::from(FixedOffset::west(5 * 3600).ymd(2016, 11, 08).and_hms(3, 50, 23))
111+
"'2016-11-08T03:50:23-05:00'" == DateTime::<Utc>::from(FixedOffset::west_opt(5 * 3600).unwrap().with_ymd_and_hms(2016, 11, 08, 3, 50, 23).unwrap())
112112
));
113113
}
114114

0 commit comments

Comments
 (0)