Skip to content

Commit 9168a22

Browse files
committed
Update chrono
1 parent ccc80ad commit 9168a22

File tree

7 files changed

+51
-41
lines changed

7 files changed

+51
-41
lines changed

Diff for: Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/git.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ impl Commit {
2020
fn from_git2_commit(commit: &mut Git2Commit<'_>) -> Self {
2121
Commit {
2222
sha: commit.id().to_string(),
23-
date: Utc.timestamp(commit.time().seconds(), 0).date(),
23+
date: Utc
24+
.timestamp_opt(commit.time().seconds(), 0)
25+
.unwrap()
26+
.date_naive(),
2427
summary: String::from_utf8_lossy(commit.summary_bytes().unwrap()).to_string(),
2528
}
2629
}

Diff for: src/github.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use reqwest::header::{HeaderMap, HeaderValue, InvalidHeaderValue, AUTHORIZATION,
33
use reqwest::{self, blocking::Client, blocking::Response};
44
use serde::{Deserialize, Serialize};
55

6-
use crate::{parse_to_utc_date, Commit, GitDate};
6+
use crate::{parse_to_naive_date, Commit, GitDate};
77

88
#[derive(Serialize, Deserialize, Debug)]
99
struct GithubCommitComparison {
@@ -42,7 +42,7 @@ impl GithubCommitElem {
4242
self.commit.committer.date.split_once('T').context(
4343
"commit date should folllow the ISO 8061 format, eg: 2022-05-04T09:55:51Z",
4444
)?;
45-
Ok(parse_to_utc_date(date_str)?)
45+
Ok(parse_to_naive_date(date_str)?)
4646
}
4747

4848
fn git_commit(self) -> anyhow::Result<Commit> {
@@ -255,7 +255,7 @@ mod tests {
255255
fn test_github() {
256256
let c = get_commit("25674202bb7415e0c0ecd07856749cfb7f591be6").unwrap();
257257
let expected_c = Commit { sha: "25674202bb7415e0c0ecd07856749cfb7f591be6".to_string(),
258-
date: parse_to_utc_date("2022-05-04").unwrap(),
258+
date: parse_to_naive_date("2022-05-04").unwrap(),
259259
summary: "Auto merge of #96695 - JohnTitor:rollup-oo4fc1h, r=JohnTitor\n\nRollup of 6 pull requests\n\nSuccessful merges:\n\n - #96597 (openbsd: unbreak build on native platform)\n - #96662 (Fix typo in lint levels doc)\n - #96668 (Fix flaky rustdoc-ui test because it did not replace time result)\n - #96679 (Quick fix for #96223.)\n - #96684 (Update `ProjectionElem::Downcast` documentation)\n - #96686 (Add some TAIT-related tests)\n\nFailed merges:\n\nr? `@ghost`\n`@rustbot` modify labels: rollup".to_string()
260260
};
261261
assert_eq!(c, expected_c)

Diff for: src/main.rs

+30-26
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::process;
1414
use std::str::FromStr;
1515

1616
use anyhow::{bail, Context};
17-
use chrono::{Date, Duration, NaiveDate, Utc};
17+
use chrono::{Duration, NaiveDate, Utc};
1818
use clap::{ArgAction, Parser, ValueEnum};
1919
use colored::Colorize;
2020
use github::get_pr_comments;
@@ -31,7 +31,7 @@ use crate::github::get_commit;
3131
use crate::least_satisfying::{least_satisfying, Satisfies};
3232
use crate::repo_access::{AccessViaGithub, AccessViaLocalGit, RustRepositoryAccessor};
3333
use crate::toolchains::{
34-
download_progress, parse_to_utc_date, DownloadParams, InstallError, TestOutcome, Toolchain,
34+
download_progress, parse_to_naive_date, DownloadParams, InstallError, TestOutcome, Toolchain,
3535
ToolchainSpec, NIGHTLY_SERVER, YYYY_MM_DD,
3636
};
3737

@@ -181,7 +181,11 @@ a date (YYYY-MM-DD), git tag name (e.g. 1.58.0) or git commit SHA."
181181
without_cargo: bool,
182182
}
183183

184-
pub type GitDate = Date<Utc>;
184+
pub type GitDate = NaiveDate;
185+
186+
pub fn today() -> NaiveDate {
187+
Utc::now().date_naive()
188+
}
185189

186190
fn validate_dir(s: &str) -> anyhow::Result<PathBuf> {
187191
let path: PathBuf = s.parse()?;
@@ -204,7 +208,7 @@ enum Bound {
204208
impl FromStr for Bound {
205209
type Err = std::convert::Infallible;
206210
fn from_str(s: &str) -> Result<Self, Self::Err> {
207-
parse_to_utc_date(s)
211+
parse_to_naive_date(s)
208212
.map(Self::Date)
209213
.or_else(|_| Ok(Self::Commit(s.to_string())))
210214
}
@@ -473,7 +477,7 @@ fn fixup_bounds(
473477

474478
fn check_bounds(start: &Option<Bound>, end: &Option<Bound>) -> anyhow::Result<()> {
475479
// current UTC date
476-
let current = Utc::today();
480+
let current = today();
477481
match (start, end) {
478482
// start date is after end date
479483
(Some(Bound::Date(start)), Some(Bound::Date(end))) if end < start => {
@@ -592,7 +596,7 @@ impl Config {
592596
&nightly_bisection_result.searched[nightly_bisection_result.found];
593597

594598
if let ToolchainSpec::Nightly { date } = nightly_regression.spec {
595-
let previous_date = date.pred();
599+
let previous_date = date.pred_opt().unwrap();
596600

597601
let working_commit = Bound::Date(previous_date).sha()?;
598602
let bad_commit = Bound::Date(date).sha()?;
@@ -871,15 +875,15 @@ impl Config {
871875
}
872876
}
873877

874-
fn get_start_date(cfg: &Config) -> Date<Utc> {
878+
fn get_start_date(cfg: &Config) -> NaiveDate {
875879
if let Some(Bound::Date(date)) = cfg.args.start {
876880
date
877881
} else {
878882
get_end_date(cfg)
879883
}
880884
}
881885

882-
fn get_end_date(cfg: &Config) -> Date<Utc> {
886+
fn get_end_date(cfg: &Config) -> NaiveDate {
883887
if let Some(Bound::Date(date)) = cfg.args.end {
884888
date
885889
} else {
@@ -888,13 +892,13 @@ fn get_end_date(cfg: &Config) -> Date<Utc> {
888892
// nightly (if available).
889893
(Some(date), None) => date,
890894
// --start only, assume --end=today
891-
_ => Utc::today(),
895+
_ => today(),
892896
}
893897
}
894898
}
895899

896-
fn date_is_future(test_date: Date<Utc>) -> bool {
897-
test_date > Utc::today()
900+
fn date_is_future(test_date: NaiveDate) -> bool {
901+
test_date > today()
898902
}
899903

900904
impl Config {
@@ -907,7 +911,7 @@ impl Config {
907911
let dl_spec = DownloadParams::for_nightly(self);
908912

909913
// before this date we didn't have -std packages
910-
let end_at = Date::from_utc(NaiveDate::from_ymd(2015, 10, 20), Utc);
914+
let end_at = NaiveDate::from_ymd_opt(2015, 10, 20).unwrap();
911915
let mut first_success = None;
912916

913917
let mut nightly_date = get_start_date(self);
@@ -977,7 +981,7 @@ impl Config {
977981
}
978982
Err(InstallError::NotFound { .. }) => {
979983
// go back just one day, presumably missing a nightly
980-
nightly_date = nightly_date.pred();
984+
nightly_date = nightly_date.pred_opt().unwrap();
981985
eprintln!(
982986
"*** unable to install {}. roll back one day and try again...",
983987
t
@@ -1044,7 +1048,7 @@ fn toolchains_between(cfg: &Config, a: ToolchainSpec, b: ToolchainSpec) -> Vec<T
10441048
std_targets: std_targets.clone(),
10451049
};
10461050
toolchains.push(t);
1047-
date = date.succ();
1051+
date = date.succ_opt().unwrap();
10481052
}
10491053
toolchains
10501054
}
@@ -1110,7 +1114,7 @@ impl Config {
11101114
mut commits: Vec<Commit>,
11111115
) -> anyhow::Result<BisectionResult> {
11121116
let dl_spec = DownloadParams::for_ci(self);
1113-
commits.retain(|c| Utc::today() - c.date < Duration::days(167));
1117+
commits.retain(|c| today() - c.date < Duration::days(167));
11141118

11151119
if commits.is_empty() {
11161120
bail!(
@@ -1275,47 +1279,47 @@ mod tests {
12751279
// Start and end date validations
12761280
#[test]
12771281
fn test_check_bounds_valid_bounds() {
1278-
let date1 = chrono::Utc::today().pred();
1279-
let date2 = chrono::Utc::today().pred();
1282+
let date1 = today().pred_opt().unwrap();
1283+
let date2 = today().pred_opt().unwrap();
12801284
assert!(check_bounds(&Some(Bound::Date(date1)), &Some(Bound::Date(date2))).is_ok());
12811285
}
12821286

12831287
#[test]
12841288
fn test_check_bounds_invalid_start_after_end() {
1285-
let start = chrono::Utc::today();
1286-
let end = chrono::Utc::today().pred();
1289+
let start = today();
1290+
let end = today().pred_opt().unwrap();
12871291
assert!(check_bounds(&Some(Bound::Date(start)), &Some(Bound::Date(end))).is_err());
12881292
}
12891293

12901294
#[test]
12911295
fn test_check_bounds_invalid_start_after_current() {
1292-
let start = chrono::Utc::today().succ();
1293-
let end = chrono::Utc::today();
1296+
let start = today().succ_opt().unwrap();
1297+
let end = today();
12941298
assert!(check_bounds(&Some(Bound::Date(start)), &Some(Bound::Date(end))).is_err());
12951299
}
12961300

12971301
#[test]
12981302
fn test_check_bounds_invalid_start_after_current_without_end() {
1299-
let start = chrono::Utc::today().succ();
1303+
let start = today().succ_opt().unwrap();
13001304
assert!(check_bounds(&Some(Bound::Date(start)), &None).is_err());
13011305
}
13021306

13031307
#[test]
13041308
fn test_check_bounds_invalid_end_after_current() {
1305-
let start = chrono::Utc::today();
1306-
let end = chrono::Utc::today().succ();
1309+
let start = today();
1310+
let end = today().succ_opt().unwrap();
13071311
assert!(check_bounds(&Some(Bound::Date(start)), &Some(Bound::Date(end))).is_err());
13081312
}
13091313

13101314
#[test]
13111315
fn test_check_bounds_invalid_end_after_current_without_start() {
1312-
let end = chrono::Utc::today().succ();
1316+
let end = today().succ_opt().unwrap();
13131317
assert!(check_bounds(&None, &Some(Bound::Date(end))).is_err());
13141318
}
13151319

13161320
#[test]
13171321
fn test_nightly_finder_iterator() {
1318-
let start_date = Date::from_utc(NaiveDate::from_ymd(2019, 01, 01), Utc);
1322+
let start_date = NaiveDate::from_ymd_opt(2019, 01, 01).unwrap();
13191323

13201324
let iter = NightlyFinderIter::new(start_date);
13211325

Diff for: src/repo_access.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ impl RustRepositoryAccessor for AccessViaGithub {
5959
// this bound on the github search.
6060
let since_date = self
6161
.bound_to_date(Bound::Commit(start_sha.to_string()))?
62-
.pred();
62+
.pred_opt()
63+
.unwrap();
6364

6465
eprintln!(
6566
"fetching (via remote github) commits from max({}, {}) to {}",

Diff for: src/toolchains.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::io::{self, Read, Write};
44
use std::path::{Path, PathBuf};
55
use std::process::{self, Command, Stdio};
66

7-
use chrono::{Date, NaiveDate, Utc};
7+
use chrono::NaiveDate;
88
use colored::Colorize;
99
use dialoguer::Select;
1010
use flate2::read::GzDecoder;
@@ -17,9 +17,7 @@ use tar::Archive;
1717
use tee::TeeReader;
1818
use xz2::read::XzDecoder;
1919

20-
use crate::Config;
21-
22-
pub type GitDate = Date<Utc>;
20+
use crate::{Config, GitDate};
2321

2422
pub const YYYY_MM_DD: &str = "%Y-%m-%d";
2523

@@ -88,7 +86,11 @@ impl Toolchain {
8886
.ok()
8987
.filter(|v| v.channel == Channel::Nightly)
9088
// rustc commit date is off-by-one, see #112
91-
.and_then(|v| parse_to_utc_date(&v.commit_date?).ok().map(|d| d.succ()))
89+
.and_then(|v| {
90+
parse_to_naive_date(&v.commit_date?)
91+
.ok()
92+
.map(|d| d.succ_opt().unwrap())
93+
})
9294
}
9395

9496
pub(crate) fn is_current_nightly(&self) -> bool {
@@ -362,8 +364,8 @@ impl Toolchain {
362364
}
363365
}
364366

365-
pub fn parse_to_utc_date(s: &str) -> chrono::ParseResult<GitDate> {
366-
NaiveDate::parse_from_str(s, YYYY_MM_DD).map(|date| Date::from_utc(date, Utc))
367+
pub fn parse_to_naive_date(s: &str) -> chrono::ParseResult<GitDate> {
368+
NaiveDate::parse_from_str(s, YYYY_MM_DD)
367369
}
368370

369371
#[derive(Clone, PartialEq, Eq, Debug)]

Diff for: tests/cmd/start-in-future.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ERROR: start date should be on or before current date, got start date request: 9999-01-01UTC and current date is [..]UTC
1+
ERROR: start date should be on or before current date, got start date request: 9999-01-01 and current date is [..]

0 commit comments

Comments
 (0)