1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Fix bug when setting time w/o year.

This commit is contained in:
Joseph Crail 2015-08-11 20:50:32 -04:00
parent e455ba5de1
commit eff8851cf9

View file

@ -191,18 +191,19 @@ fn parse_date(str: &str) -> FileTime {
} }
} }
fn parse_timestamp(str: &str) -> FileTime { fn parse_timestamp(s: &str) -> FileTime {
let format = match str.chars().count() { let now = time::now();
15 => "%Y%m%d%H%M.%S", let (format, ts) = match s.chars().count() {
12 => "%Y%m%d%H%M", 15 => ("%Y%m%d%H%M.%S", s.to_string()),
13 => "%y%m%d%H%M.%S", 12 => ("%Y%m%d%H%M", s.to_string()),
10 => "%y%m%d%H%M", 13 => ("%y%m%d%H%M.%S", s.to_string()),
11 => "%m%d%H%M.%S", 10 => ("%y%m%d%H%M", s.to_string()),
8 => "%m%d%H%M", 11 => ("%Y%m%d%H%M.%S", format!("{}{}", now.tm_year + 1900, s)),
8 => ("%Y%m%d%H%M", format!("{}{}", now.tm_year + 1900, s)),
_ => panic!("Unknown timestamp format") _ => panic!("Unknown timestamp format")
}; };
match time::strptime(str, format) { match time::strptime(&ts, format) {
Ok(tm) => local_tm_to_filetime!(to_local!(tm)), Ok(tm) => local_tm_to_filetime!(to_local!(tm)),
Err(e) => panic!("Unable to parse timestamp\n{}", e) Err(e) => panic!("Unable to parse timestamp\n{}", e)
} }