1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 20:17:45 +00:00

touch: replace use of deprecated chrono functions

This commit is contained in:
Daniel Hofstetter 2024-03-06 18:16:49 +01:00
parent c45c00eed4
commit aad8f7d8b5
2 changed files with 3 additions and 3 deletions

View file

@ -433,7 +433,7 @@ fn parse_timestamp(s: &str) -> UResult<FileTime> {
// only care about the timestamp anyway. // only care about the timestamp anyway.
// Tested in gnu/tests/touch/60-seconds // Tested in gnu/tests/touch/60-seconds
if local.second() == 59 && ts.ends_with(".60") { if local.second() == 59 && ts.ends_with(".60") {
local += Duration::seconds(1); local += Duration::try_seconds(1).unwrap();
} }
// Due to daylight saving time switch, local time can jump from 1:59 AM to // Due to daylight saving time switch, local time can jump from 1:59 AM to
@ -441,7 +441,7 @@ fn parse_timestamp(s: &str) -> UResult<FileTime> {
// valid. If we are within this jump, chrono takes the offset from before // valid. If we are within this jump, chrono takes the offset from before
// the jump. If we then jump forward an hour, we get the new corrected // the jump. If we then jump forward an hour, we get the new corrected
// offset. Jumping back will then now correctly take the jump into account. // offset. Jumping back will then now correctly take the jump into account.
let local2 = local + Duration::hours(1) - Duration::hours(1); let local2 = local + Duration::try_hours(1).unwrap() - Duration::try_hours(1).unwrap();
if local.hour() != local2.hour() { if local.hour() != local2.hour() {
return Err(USimpleError::new( return Err(USimpleError::new(
1, 1,

View file

@ -32,7 +32,7 @@ fn set_file_times(at: &AtPath, path: &str, atime: FileTime, mtime: FileTime) {
fn str_to_filetime(format: &str, s: &str) -> FileTime { fn str_to_filetime(format: &str, s: &str) -> FileTime {
let tm = chrono::NaiveDateTime::parse_from_str(s, format).unwrap(); let tm = chrono::NaiveDateTime::parse_from_str(s, format).unwrap();
FileTime::from_unix_time(tm.timestamp(), tm.timestamp_subsec_nanos()) FileTime::from_unix_time(tm.and_utc().timestamp(), tm.timestamp_subsec_nanos())
} }
#[test] #[test]