@@ -14,7 +14,7 @@ use std::process;
1414use std:: str:: FromStr ;
1515
1616use anyhow:: { bail, Context } ;
17- use chrono:: { Date , Duration , NaiveDate , Utc } ;
17+ use chrono:: { Duration , NaiveDate , Utc } ;
1818use clap:: { ArgAction , Parser , ValueEnum } ;
1919use colored:: Colorize ;
2020use github:: get_pr_comments;
@@ -31,7 +31,7 @@ use crate::github::get_commit;
3131use crate :: least_satisfying:: { least_satisfying, Satisfies } ;
3232use crate :: repo_access:: { AccessViaGithub , AccessViaLocalGit , RustRepositoryAccessor } ;
3333use 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
186190fn validate_dir ( s : & str ) -> anyhow:: Result < PathBuf > {
187191 let path: PathBuf = s. parse ( ) ?;
@@ -204,7 +208,7 @@ enum Bound {
204208impl 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
474478fn 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
900904impl 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
0 commit comments