From eff8851cf9d91fa88147c89e1da8224efcdb2bb4 Mon Sep 17 00:00:00 2001 From: Joseph Crail Date: Tue, 11 Aug 2015 20:50:32 -0400 Subject: [PATCH] Fix bug when setting time w/o year. --- src/touch/touch.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/touch/touch.rs b/src/touch/touch.rs index 02b690cf3..9f51f9837 100644 --- a/src/touch/touch.rs +++ b/src/touch/touch.rs @@ -191,18 +191,19 @@ fn parse_date(str: &str) -> FileTime { } } -fn parse_timestamp(str: &str) -> FileTime { - let format = match str.chars().count() { - 15 => "%Y%m%d%H%M.%S", - 12 => "%Y%m%d%H%M", - 13 => "%y%m%d%H%M.%S", - 10 => "%y%m%d%H%M", - 11 => "%m%d%H%M.%S", - 8 => "%m%d%H%M", +fn parse_timestamp(s: &str) -> FileTime { + let now = time::now(); + let (format, ts) = match s.chars().count() { + 15 => ("%Y%m%d%H%M.%S", s.to_string()), + 12 => ("%Y%m%d%H%M", s.to_string()), + 13 => ("%y%m%d%H%M.%S", s.to_string()), + 10 => ("%y%m%d%H%M", s.to_string()), + 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") }; - match time::strptime(str, format) { + match time::strptime(&ts, format) { Ok(tm) => local_tm_to_filetime!(to_local!(tm)), Err(e) => panic!("Unable to parse timestamp\n{}", e) }