Skip to content

Commit e4e2df4

Browse files
committed
Fix chrono deprecation warnings
1 parent 0e2b7c0 commit e4e2df4

File tree

6 files changed

+23
-18
lines changed

6 files changed

+23
-18
lines changed

collector/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl Bound {
4040
Bound::Commit(sha) => commit.sha == **sha,
4141
Bound::Date(date) => commit.is_master() && commit.date.0.naive_utc().date() >= *date,
4242
Bound::None => {
43-
let last_month = chrono::Utc::now().date().naive_utc() - chrono::Duration::days(30);
43+
let last_month = chrono::Utc::now().date_naive() - chrono::Duration::days(30);
4444
commit.is_master() && last_month <= commit.date.0.naive_utc().date()
4545
}
4646
}
@@ -50,7 +50,7 @@ impl Bound {
5050
pub fn right_match(&self, commit: &Commit) -> bool {
5151
match self {
5252
Bound::Commit(sha) => commit.sha == **sha,
53-
Bound::Date(date) => commit.is_master() && commit.date.0.date().naive_utc() <= *date,
53+
Bound::Date(date) => commit.is_master() && commit.date.0.date_naive() <= *date,
5454
Bound::None => commit.is_master(),
5555
}
5656
}

database/src/bin/sqlite-to-postgres.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl Table for Artifact {
6767
.serialize(ArtifactRow {
6868
id: row.get(0).unwrap(),
6969
name: row.get_ref(1).unwrap().as_str().unwrap(),
70-
date: Nullable(date.map(|seconds| Utc.timestamp(seconds, 0))),
70+
date: Nullable(date.map(|seconds| Utc.timestamp_opt(seconds, 0).unwrap())),
7171
typ: row.get_ref(3).unwrap().as_str().unwrap(),
7272
})
7373
.unwrap();
@@ -102,7 +102,7 @@ impl Table for ArtifactCollectionDuration {
102102
writer
103103
.serialize(ArtifactCollectionDurationRow {
104104
aid: row.get(0).unwrap(),
105-
date_recorded: Utc.timestamp(date_recorded, 0),
105+
date_recorded: Utc.timestamp_opt(date_recorded, 0).unwrap(),
106106
duration: row.get(2).unwrap(),
107107
})
108108
.unwrap();
@@ -200,8 +200,8 @@ impl Table for CollectorProgress {
200200
fn write_postgres_csv_row<W: Write>(writer: &mut csv::Writer<W>, row: &rusqlite::Row) {
201201
let start: Option<i64> = row.get(2).unwrap();
202202
let end: Option<i64> = row.get(3).unwrap();
203-
let start_time = Nullable(start.map(|seconds| Utc.timestamp(seconds, 0)));
204-
let end_time = Nullable(end.map(|seconds| Utc.timestamp(seconds, 0)));
203+
let start_time = Nullable(start.map(|seconds| Utc.timestamp_opt(seconds, 0).unwrap()));
204+
let end_time = Nullable(end.map(|seconds| Utc.timestamp_opt(seconds, 0).unwrap()));
205205

206206
writer
207207
.serialize(CollectorProgressRow {
@@ -386,7 +386,9 @@ impl Table for PullRequestBuild {
386386
pr: row.get(1).unwrap(),
387387
parent_sha: row.get_ref(2).unwrap().try_into().unwrap(),
388388
complete: row.get(3).unwrap(),
389-
requested: Nullable(requested.map(|seconds| Utc.timestamp(seconds, 0))),
389+
requested: Nullable(
390+
requested.map(|seconds| Utc.timestamp_opt(seconds, 0).unwrap()),
391+
),
390392
include: row.get_ref(5).unwrap().try_into().unwrap(),
391393
exclude: row.get_ref(6).unwrap().try_into().unwrap(),
392394
runs: row.get(7).unwrap(),

database/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl Date {
6666
}
6767

6868
pub fn ymd_hms(year: i32, month: u32, day: u32, h: u32, m: u32, s: u32) -> Date {
69-
Date(Utc.ymd(year, month, day).and_hms(h, m, s))
69+
Date(Utc.with_ymd_and_hms(year, month, day, h, m, s).unwrap())
7070
}
7171

7272
pub fn empty() -> Date {

database/src/pool/postgres.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ where
498498
let timestamp: Option<DateTime<Utc>> = row.get(2);
499499
match timestamp {
500500
Some(t) => Date(t),
501-
None => Date(Utc.ymd(2001, 01, 01).and_hms(0, 0, 0)),
501+
None => Date(Utc.with_ymd_and_hms(2001, 01, 01, 0, 0, 0).unwrap()),
502502
}
503503
},
504504
r#type: CommitType::from_str(&row.get::<_, String>(3)).unwrap()

database/src/pool/sqlite.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,8 @@ impl Connection for SqliteConnection {
438438
date: {
439439
let timestamp: Option<i64> = row.get(2)?;
440440
match timestamp {
441-
Some(t) => Date(Utc.timestamp(t, 0)),
442-
None => Date(Utc.ymd(2001, 01, 01).and_hms(0, 0, 0)),
441+
Some(t) => Date(Utc.timestamp_opt(t, 0).unwrap()),
442+
None => Date(Utc.with_ymd_and_hms(2001, 01, 01, 0, 0, 0).unwrap()),
443443
}
444444
},
445445
r#type: CommitType::from_str(&row.get::<_, String>(3)?).unwrap(),
@@ -648,7 +648,7 @@ impl Connection for SqliteConnection {
648648
include: row.get(3).unwrap(),
649649
exclude: row.get(4).unwrap(),
650650
runs: row.get(5).unwrap(),
651-
commit_date: row.get::<_, Option<i64>>(6).unwrap().map(|timestamp| Date(DateTime::from_utc(NaiveDateTime::from_timestamp(timestamp, 0), Utc)))
651+
commit_date: row.get::<_, Option<i64>>(6).unwrap().map(|timestamp| Date(DateTime::from_utc(NaiveDateTime::from_timestamp_opt(timestamp, 0).unwrap(), Utc)))
652652
})
653653
})
654654
.collect::<Result<Vec<_>, _>>()
@@ -679,7 +679,7 @@ impl Connection for SqliteConnection {
679679
include: row.get(3).unwrap(),
680680
exclude: row.get(4).unwrap(),
681681
runs: row.get(5).unwrap(),
682-
commit_date: row.get::<_, Option<i64>>(6).unwrap().map(|timestamp| Date(DateTime::from_utc(NaiveDateTime::from_timestamp(timestamp, 0), Utc)))
682+
commit_date: row.get::<_, Option<i64>>(6).unwrap().map(|timestamp| Date(DateTime::from_utc(NaiveDateTime::from_timestamp_opt(timestamp, 0).unwrap(), Utc)))
683683
})
684684
},
685685
)
@@ -955,7 +955,7 @@ impl Connection for SqliteConnection {
955955
"try" | "master" => ArtifactId::Commit(Commit {
956956
sha: name,
957957
date: date
958-
.map(|d| Utc.timestamp(d, 0))
958+
.map(|d| Utc.timestamp_opt(d, 0).unwrap())
959959
.map(Date)
960960
.unwrap_or_else(|| Date::ymd_hms(2001, 01, 01, 0, 0, 0)),
961961
r#type: CommitType::from_str(&ty).unwrap(),
@@ -1011,7 +1011,7 @@ impl Connection for SqliteConnection {
10111011
order by date_recorded desc \
10121012
limit 1;",
10131013
params![],
1014-
|r| Ok(Utc.timestamp(r.get(0)?, 0)),
1014+
|r| Ok(Utc.timestamp_opt(r.get(0)?, 0).unwrap()),
10151015
)
10161016
.optional()
10171017
.unwrap()
@@ -1155,13 +1155,16 @@ impl Connection for SqliteConnection {
11551155
match ty.as_str() {
11561156
"master" => Some(ArtifactId::Commit(Commit {
11571157
sha: artifact.to_owned(),
1158-
date: Date(Utc.timestamp(date.expect("master has date"), 0)),
1158+
date: Date(
1159+
Utc.timestamp_opt(date.expect("master has date"), 0)
1160+
.unwrap(),
1161+
),
11591162
r#type: CommitType::Master,
11601163
})),
11611164
"try" => Some(ArtifactId::Commit(Commit {
11621165
sha: artifact.to_owned(),
11631166
date: date
1164-
.map(|d| Date(Utc.timestamp(d, 0)))
1167+
.map(|d| Date(Utc.timestamp_opt(d, 0).unwrap()))
11651168
.unwrap_or_else(|| Date::ymd_hms(2000, 1, 1, 0, 0, 0)),
11661169
r#type: CommitType::Try,
11671170
})),

site/src/comparison.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,7 @@ Revision range: [{first_commit}..{last_commit}](https://perf.rust-lang.org/?star
14241424
TODO: Nags
14251425
14261426
"#####,
1427-
date = chrono::Utc::today().format("%Y-%m-%d"),
1427+
date = chrono::Utc::now().format("%Y-%m-%d"),
14281428
first_commit = start,
14291429
last_commit = end,
14301430
num_comparisons = num_comparisons,

0 commit comments

Comments
 (0)