mirror of
https://github.com/uutils/coreutils
synced 2024-11-16 17:58:06 +00:00
Merge pull request #2415 from miDeb/touch/date-epoch
touch: support @<timestamp> date format
This commit is contained in:
commit
439b7e0ca5
2 changed files with 22 additions and 0 deletions
|
@ -268,6 +268,10 @@ fn parse_date(str: &str) -> FileTime {
|
|||
return local_tm_to_filetime(to_local(tm));
|
||||
}
|
||||
}
|
||||
if let Ok(tm) = time::strptime(str, "@%s") {
|
||||
// Don't convert to local time in this case - seconds since epoch are not time-zone dependent
|
||||
return local_tm_to_filetime(tm);
|
||||
}
|
||||
show_error!("Unable to parse date: {}\n", str);
|
||||
process::exit(1);
|
||||
}
|
||||
|
|
|
@ -375,6 +375,24 @@ fn test_touch_set_date2() {
|
|||
assert_eq!(mtime, start_of_year);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_touch_set_date3() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let file = "test_touch_set_date";
|
||||
|
||||
ucmd.args(&["-d", "@1623786360", file])
|
||||
.succeeds()
|
||||
.no_stderr();
|
||||
|
||||
assert!(at.file_exists(file));
|
||||
|
||||
let expected = FileTime::from_unix_time(1623786360, 0);
|
||||
let (atime, mtime) = get_file_times(&at, file);
|
||||
assert_eq!(atime, mtime);
|
||||
assert_eq!(atime, expected);
|
||||
assert_eq!(mtime, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_touch_set_date_wrong_format() {
|
||||
let (_at, mut ucmd) = at_and_ucmd!();
|
||||
|
|
Loading…
Reference in a new issue