@@ -14,7 +14,7 @@ use std::process;
14
14
use std:: str:: FromStr ;
15
15
16
16
use anyhow:: { bail, Context } ;
17
- use chrono:: { Date , Duration , NaiveDate , Utc } ;
17
+ use chrono:: { Duration , NaiveDate , Utc } ;
18
18
use clap:: { ArgAction , Parser , ValueEnum } ;
19
19
use colored:: Colorize ;
20
20
use github:: get_pr_comments;
@@ -31,7 +31,7 @@ use crate::github::get_commit;
31
31
use crate :: least_satisfying:: { least_satisfying, Satisfies } ;
32
32
use crate :: repo_access:: { AccessViaGithub , AccessViaLocalGit , RustRepositoryAccessor } ;
33
33
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 ,
35
35
ToolchainSpec , NIGHTLY_SERVER , YYYY_MM_DD ,
36
36
} ;
37
37
@@ -181,7 +181,11 @@ a date (YYYY-MM-DD), git tag name (e.g. 1.58.0) or git commit SHA."
181
181
without_cargo : bool ,
182
182
}
183
183
184
- pub type GitDate = Date < Utc > ;
184
+ pub type GitDate = NaiveDate ;
185
+
186
+ pub fn today ( ) -> NaiveDate {
187
+ Utc :: now ( ) . date_naive ( )
188
+ }
185
189
186
190
fn validate_dir ( s : & str ) -> anyhow:: Result < PathBuf > {
187
191
let path: PathBuf = s. parse ( ) ?;
@@ -204,7 +208,7 @@ enum Bound {
204
208
impl FromStr for Bound {
205
209
type Err = std:: convert:: Infallible ;
206
210
fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
207
- parse_to_utc_date ( s)
211
+ parse_to_naive_date ( s)
208
212
. map ( Self :: Date )
209
213
. or_else ( |_| Ok ( Self :: Commit ( s. to_string ( ) ) ) )
210
214
}
@@ -473,7 +477,7 @@ fn fixup_bounds(
473
477
474
478
fn check_bounds ( start : & Option < Bound > , end : & Option < Bound > ) -> anyhow:: Result < ( ) > {
475
479
// current UTC date
476
- let current = Utc :: today ( ) ;
480
+ let current = today ( ) ;
477
481
match ( start, end) {
478
482
// start date is after end date
479
483
( Some ( Bound :: Date ( start) ) , Some ( Bound :: Date ( end) ) ) if end < start => {
@@ -592,7 +596,7 @@ impl Config {
592
596
& nightly_bisection_result. searched [ nightly_bisection_result. found ] ;
593
597
594
598
if let ToolchainSpec :: Nightly { date } = nightly_regression. spec {
595
- let previous_date = date. pred ( ) ;
599
+ let previous_date = date. pred_opt ( ) . unwrap ( ) ;
596
600
597
601
let working_commit = Bound :: Date ( previous_date) . sha ( ) ?;
598
602
let bad_commit = Bound :: Date ( date) . sha ( ) ?;
@@ -871,15 +875,15 @@ impl Config {
871
875
}
872
876
}
873
877
874
- fn get_start_date ( cfg : & Config ) -> Date < Utc > {
878
+ fn get_start_date ( cfg : & Config ) -> NaiveDate {
875
879
if let Some ( Bound :: Date ( date) ) = cfg. args . start {
876
880
date
877
881
} else {
878
882
get_end_date ( cfg)
879
883
}
880
884
}
881
885
882
- fn get_end_date ( cfg : & Config ) -> Date < Utc > {
886
+ fn get_end_date ( cfg : & Config ) -> NaiveDate {
883
887
if let Some ( Bound :: Date ( date) ) = cfg. args . end {
884
888
date
885
889
} else {
@@ -888,13 +892,13 @@ fn get_end_date(cfg: &Config) -> Date<Utc> {
888
892
// nightly (if available).
889
893
( Some ( date) , None ) => date,
890
894
// --start only, assume --end=today
891
- _ => Utc :: today ( ) ,
895
+ _ => today ( ) ,
892
896
}
893
897
}
894
898
}
895
899
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 ( )
898
902
}
899
903
900
904
impl Config {
@@ -907,7 +911,7 @@ impl Config {
907
911
let dl_spec = DownloadParams :: for_nightly ( self ) ;
908
912
909
913
// 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 ( ) ;
911
915
let mut first_success = None ;
912
916
913
917
let mut nightly_date = get_start_date ( self ) ;
@@ -977,7 +981,7 @@ impl Config {
977
981
}
978
982
Err ( InstallError :: NotFound { .. } ) => {
979
983
// go back just one day, presumably missing a nightly
980
- nightly_date = nightly_date. pred ( ) ;
984
+ nightly_date = nightly_date. pred_opt ( ) . unwrap ( ) ;
981
985
eprintln ! (
982
986
"*** unable to install {}. roll back one day and try again..." ,
983
987
t
@@ -1044,7 +1048,7 @@ fn toolchains_between(cfg: &Config, a: ToolchainSpec, b: ToolchainSpec) -> Vec<T
1044
1048
std_targets : std_targets. clone ( ) ,
1045
1049
} ;
1046
1050
toolchains. push ( t) ;
1047
- date = date. succ ( ) ;
1051
+ date = date. succ_opt ( ) . unwrap ( ) ;
1048
1052
}
1049
1053
toolchains
1050
1054
}
@@ -1110,7 +1114,7 @@ impl Config {
1110
1114
mut commits : Vec < Commit > ,
1111
1115
) -> anyhow:: Result < BisectionResult > {
1112
1116
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 ) ) ;
1114
1118
1115
1119
if commits. is_empty ( ) {
1116
1120
bail ! (
@@ -1275,47 +1279,47 @@ mod tests {
1275
1279
// Start and end date validations
1276
1280
#[ test]
1277
1281
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 ( ) ;
1280
1284
assert ! ( check_bounds( & Some ( Bound :: Date ( date1) ) , & Some ( Bound :: Date ( date2) ) ) . is_ok( ) ) ;
1281
1285
}
1282
1286
1283
1287
#[ test]
1284
1288
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 ( ) ;
1287
1291
assert ! ( check_bounds( & Some ( Bound :: Date ( start) ) , & Some ( Bound :: Date ( end) ) ) . is_err( ) ) ;
1288
1292
}
1289
1293
1290
1294
#[ test]
1291
1295
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 ( ) ;
1294
1298
assert ! ( check_bounds( & Some ( Bound :: Date ( start) ) , & Some ( Bound :: Date ( end) ) ) . is_err( ) ) ;
1295
1299
}
1296
1300
1297
1301
#[ test]
1298
1302
fn test_check_bounds_invalid_start_after_current_without_end ( ) {
1299
- let start = chrono :: Utc :: today ( ) . succ ( ) ;
1303
+ let start = today ( ) . succ_opt ( ) . unwrap ( ) ;
1300
1304
assert ! ( check_bounds( & Some ( Bound :: Date ( start) ) , & None ) . is_err( ) ) ;
1301
1305
}
1302
1306
1303
1307
#[ test]
1304
1308
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 ( ) ;
1307
1311
assert ! ( check_bounds( & Some ( Bound :: Date ( start) ) , & Some ( Bound :: Date ( end) ) ) . is_err( ) ) ;
1308
1312
}
1309
1313
1310
1314
#[ test]
1311
1315
fn test_check_bounds_invalid_end_after_current_without_start ( ) {
1312
- let end = chrono :: Utc :: today ( ) . succ ( ) ;
1316
+ let end = today ( ) . succ_opt ( ) . unwrap ( ) ;
1313
1317
assert ! ( check_bounds( & None , & Some ( Bound :: Date ( end) ) ) . is_err( ) ) ;
1314
1318
}
1315
1319
1316
1320
#[ test]
1317
1321
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 ( ) ;
1319
1323
1320
1324
let iter = NightlyFinderIter :: new ( start_date) ;
1321
1325
0 commit comments