mirror of
https://github.com/uutils/coreutils
synced 2024-11-16 01:38:04 +00:00
also support for tests/touch/relative.sh
This commit is contained in:
parent
d5569847bd
commit
f65d72e334
2 changed files with 27 additions and 0 deletions
|
@ -312,6 +312,13 @@ const YYMMDDHHMM_FORMAT: &[time::format_description::FormatItem] = format_descri
|
|||
[hour repr:24 padding:zero][minute padding:zero]"
|
||||
);
|
||||
|
||||
// "%Y-%m-%d %H:%M +offset"
|
||||
// Used for example in tests/touch/relative.sh
|
||||
const YYYYMMDDHHMM_OFFSET_FORMAT: &[time::format_description::FormatItem] = format_description!(
|
||||
"[year]-[month]-[day] [hour repr:24]:[minute] \
|
||||
[offset_hour sign:mandatory][offset_minute]"
|
||||
);
|
||||
|
||||
fn parse_date(s: &str) -> UResult<FileTime> {
|
||||
// This isn't actually compatible with GNU touch, but there doesn't seem to
|
||||
// be any simple specification for what format this parameter allows and I'm
|
||||
|
@ -338,6 +345,7 @@ fn parse_date(s: &str) -> UResult<FileTime> {
|
|||
YYYYMMDDHHMMS_FORMAT,
|
||||
YYYYMMDDHHMMSS_FORMAT,
|
||||
YYYY_MM_DD_HH_MM_FORMAT,
|
||||
YYYYMMDDHHMM_OFFSET_FORMAT,
|
||||
] {
|
||||
if let Ok(parsed) = time::PrimitiveDateTime::parse(s, &fmt) {
|
||||
return Ok(dt_to_filename(parsed));
|
||||
|
|
|
@ -488,6 +488,25 @@ fn test_touch_set_date6() {
|
|||
assert_eq!(mtime, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_touch_set_date7() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let file = "test_touch_set_date";
|
||||
|
||||
ucmd.args(&["-d", "2004-01-16 12:00 +0000", file])
|
||||
.succeeds()
|
||||
.no_stderr();
|
||||
|
||||
assert!(at.file_exists(file));
|
||||
|
||||
let expected = FileTime::from_unix_time(1074254400, 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