Skip to content

Commit

Permalink
format dateutils tests
Browse files Browse the repository at this point in the history
  • Loading branch information
esheppa committed Feb 14, 2023
1 parent 56e250a commit e3f0ade
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions tests/dateutils.rs
Expand Up @@ -77,7 +77,8 @@ fn try_verify_against_date_command() {

#[cfg(target_os = "linux")]
fn verify_against_date_command_format_local(path: &'static str, dt: NaiveDateTime) {
let required_format = "d%d D%D F%F H%H I%I j%j k%k l%l m%m M%M S%S T%T u%u U%U w%w W%W X%X y%y Y%Y z%:z";
let required_format =
"d%d D%D F%F H%H I%I j%j k%k l%l m%m M%M S%S T%T u%u U%U w%w W%W X%X y%y Y%Y z%:z";
// a%a - depends from localization
// A%A - depends from localization
// b%b - depends from localization
Expand All @@ -89,17 +90,26 @@ fn verify_against_date_command_format_local(path: &'static str, dt: NaiveDateTim
// x%x - fails, date is dd/mm/yyyy, chrono is dd/mm/yy, same as %D
// Z%Z - too many ways to represent it, will most likely fail


let output = process::Command::new(path)
.arg("-d")
.arg(format!("{}-{:02}-{:02} {:02}:{:02}:{:02}", dt.year(), dt.month(), dt.day(), dt.hour(), dt.minute(), dt.second()))
.arg(format!(
"{}-{:02}-{:02} {:02}:{:02}:{:02}",
dt.year(),
dt.month(),
dt.day(),
dt.hour(),
dt.minute(),
dt.second()
))
.arg(format!("+{}", required_format))
.output()
.unwrap();

let date_command_str = String::from_utf8(output.stdout).unwrap();
let date = NaiveDate::from_ymd_opt(dt.year(), dt.month(), dt.day()).unwrap();
let ldt = Local.from_local_datetime(&date.and_hms_opt(dt.hour(), dt.minute(), dt.second()).unwrap()).unwrap();
let ldt = Local
.from_local_datetime(&date.and_hms_opt(dt.hour(), dt.minute(), dt.second()).unwrap())
.unwrap();
let formated_date = format!("{}\n", ldt.format(required_format));
assert_eq!(date_command_str, formated_date);
}
Expand Down

0 comments on commit e3f0ade

Please sign in to comment.