Skip to content

Commit 0f9c69b

Browse files
authored
Merge pull request #10093 from aaron-ang/touch-test-offset
fix: use jiff time for touch tests
2 parents 130f780 + e580609 commit 0f9c69b

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ chrono.workspace = true
539539
ctor.workspace = true
540540
filetime.workspace = true
541541
glob.workspace = true
542+
jiff.workspace = true
542543
libc.workspace = true
543544
num-prime.workspace = true
544545
pretty_assertions = "1.4.0"

tests/by-util/test_touch.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
//
33
// For the full copyright and license information, please view the LICENSE
44
// file that was distributed with this source code.
5-
// spell-checker:ignore (formats) cymdhm cymdhms mdhm mdhms ymdhm ymdhms datetime mktime
5+
// spell-checker:ignore (formats) cymdhm cymdhms datetime mdhm mdhms mktime strtime ymdhm ymdhms
66

77
use filetime::FileTime;
88
#[cfg(not(target_os = "freebsd"))]
99
use filetime::set_symlink_file_times;
10+
use jiff::{fmt::strtime, tz::TimeZone};
1011
use std::fs::remove_file;
1112
use std::path::PathBuf;
1213
use uutests::at_and_ucmd;
@@ -36,11 +37,10 @@ fn set_file_times(at: &AtPath, path: &str, atime: FileTime, mtime: FileTime) {
3637
}
3738

3839
fn str_to_filetime(format: &str, s: &str) -> FileTime {
39-
let tm = chrono::NaiveDateTime::parse_from_str(s, format).unwrap();
40-
FileTime::from_unix_time(
41-
tm.and_utc().timestamp(),
42-
tm.and_utc().timestamp_subsec_nanos(),
43-
)
40+
let tm = strtime::parse(format, s).unwrap();
41+
let dt = tm.to_datetime().unwrap();
42+
let ts = dt.to_zoned(TimeZone::UTC).unwrap().timestamp();
43+
FileTime::from_unix_time(ts.as_second(), ts.subsec_nanosecond() as u32)
4444
}
4545

4646
#[test]

0 commit comments

Comments
 (0)