Skip to content

Commit f9743af

Browse files
committed
Refactored "%Y-%m-%d" into its own YYYY_MM_DD const definition.
1 parent 20641b5 commit f9743af

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/main.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,12 @@ enum Bound {
178178
#[fail(display = "will never happen")]
179179
struct BoundParseError {}
180180

181+
const YYYY_MM_DD: &'static str = "%Y-%m-%d";
182+
181183
impl FromStr for Bound {
182184
type Err = BoundParseError;
183185
fn from_str(s: &str) -> Result<Bound, BoundParseError> {
184-
match chrono::NaiveDate::parse_from_str(s, "%Y-%m-%d") {
186+
match chrono::NaiveDate::parse_from_str(s, YYYY_MM_DD) {
185187
Ok(date) => Ok(Bound::Date(Date::from_utc(date, Utc))),
186188
Err(_) => Ok(Bound::Commit(s.to_string())),
187189
}
@@ -193,7 +195,7 @@ impl Bound {
193195
match self {
194196
Bound::Commit(commit) => Ok(Bound::Commit(commit)),
195197
Bound::Date(date) => {
196-
let date_str = date.format("%Y-%m-%d");
198+
let date_str = date.format(YYYY_MM_DD);
197199
let url = format!("{}/{}/channel-rust-nightly-git-commit-hash.txt", NIGHTLY_SERVER, date_str);
198200

199201
eprintln!("fetching {}", url);
@@ -262,7 +264,7 @@ impl Toolchain {
262264
// N.B. We need to call this with a nonstandard name so that rustup utilizes the
263265
// fallback cargo logic.
264266
ToolchainSpec::Nightly { ref date } => {
265-
format!("bisector-nightly-{}-{}", date.format("%Y-%m-%d"), self.host)
267+
format!("bisector-nightly-{}-{}", date.format(YYYY_MM_DD), self.host)
266268
}
267269
}
268270
}
@@ -275,7 +277,7 @@ impl fmt::Display for Toolchain {
275277
let alt_s = if alt { format!("-alt") } else { String::new() };
276278
write!(f, "{}{}", commit, alt_s)
277279
}
278-
ToolchainSpec::Nightly { ref date } => write!(f, "nightly-{}", date.format("%Y-%m-%d")),
280+
ToolchainSpec::Nightly { ref date } => write!(f, "nightly-{}", date.format(YYYY_MM_DD)),
279281
}
280282
}
281283
}
@@ -753,7 +755,7 @@ impl Toolchain {
753755

754756
let location = match self.spec {
755757
ToolchainSpec::Ci { ref commit, .. } => commit.to_string(),
756-
ToolchainSpec::Nightly { ref date } => date.format("%Y-%m-%d").to_string(),
758+
ToolchainSpec::Nightly { ref date } => date.format(YYYY_MM_DD).to_string(),
757759
};
758760

759761
// download rustc.
@@ -1030,8 +1032,8 @@ fn bisect(cfg: &Config, client: &Client) -> Result<(), Error> {
10301032
if let Bound::Commit(working_commit) = Bound::Date(previous_date).as_commit()? {
10311033
eprintln!(
10321034
"looking for regression commit between {} and {}",
1033-
date.format("%Y-%m-%d"),
1034-
previous_date.format("%Y-%m-%d"),
1035+
date.format(YYYY_MM_DD),
1036+
previous_date.format(YYYY_MM_DD),
10351037
);
10361038

10371039
let ci_bisection_result = bisect_ci_between(cfg, client, &working_commit, &bad_commit)?;

0 commit comments

Comments
 (0)