1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-09-16 03:36:18 +00:00

time: Various fixes

This commit is contained in:
Sylvestre Ledru 2022-04-23 21:32:35 +02:00
parent f810b55d86
commit 3a576f2441
8 changed files with 69 additions and 19 deletions

View file

@ -1032,8 +1032,8 @@ fn test_cp_no_deref_folder_to_folder() {
#[cfg(target_os = "linux")]
fn test_cp_archive() {
let (at, mut ucmd) = at_and_ucmd!();
let ts = time::now().to_timespec();
let previous = FileTime::from_unix_time(ts.sec as i64 - 3600, ts.nsec as u32);
let ts = time::OffsetDateTime::now_local().unwrap();
let previous = FileTime::from_unix_time(ts.unix_timestamp() - 3600, ts.nanosecond() as u32);
// set the file creation/modification an hour ago
filetime::set_file_times(
at.plus_as_string(TEST_HELLO_WORLD_SOURCE),
@ -1135,8 +1135,8 @@ fn test_cp_archive_recursive() {
#[cfg(any(target_os = "linux", target_os = "android"))]
fn test_cp_preserve_timestamps() {
let (at, mut ucmd) = at_and_ucmd!();
let ts = time::now().to_timespec();
let previous = FileTime::from_unix_time(ts.sec as i64 - 3600, ts.nsec as u32);
let ts = time::OffsetDateTime::now_local().unwrap();
let previous = FileTime::from_unix_time(ts.unix_timestamp() - 3600, ts.nanosecond());
// set the file creation/modification an hour ago
filetime::set_file_times(
at.plus_as_string(TEST_HELLO_WORLD_SOURCE),
@ -1168,8 +1168,8 @@ fn test_cp_preserve_timestamps() {
#[cfg(any(target_os = "linux", target_os = "android"))]
fn test_cp_no_preserve_timestamps() {
let (at, mut ucmd) = at_and_ucmd!();
let ts = time::now().to_timespec();
let previous = FileTime::from_unix_time(ts.sec as i64 - 3600, ts.nsec as u32);
let ts = time::OffsetDateTime::now_local().unwrap();
let previous = FileTime::from_unix_time(ts.unix_timestamp() - 3600, ts.nanosecond());
// set the file creation/modification an hour ago
filetime::set_file_times(
at.plus_as_string(TEST_HELLO_WORLD_SOURCE),

View file

@ -1,4 +1,10 @@
// spell-checker:ignore (formats) cymdhm cymdhms mdhm mdhms ymdhm ymdhms
// spell-checker:ignore (formats) cymdhm cymdhms mdhm mdhms ymdhm ymdhms datetime mktime
// This test relies on
// --cfg unsound_local_offset
// https://github.com/time-rs/time/blob/deb8161b84f355b31e39ce09e40c4d6ce3fea837/src/sys/local_offset_at/unix.rs#L112-L120=
// See https://github.com/time-rs/time/issues/293#issuecomment-946382614=
// Defined in .cargo/config
extern crate touch;
use self::touch::filetime::{self, FileTime};
@ -42,8 +48,14 @@ fn str_to_filetime(format: &str, s: &str) -> FileTime {
"%Y%m%d%H%M.%S" => format_description!("[year][month][day][hour][minute].[second]"),
_ => panic!("unexpected dt format"),
};
let tm = time::PrimitiveDateTime::parse(&s, &format_description).unwrap();
let offset_dt = tm.assume_offset(time::OffsetDateTime::now_local().unwrap().offset());
let tm = time::PrimitiveDateTime::parse(s, &format_description).unwrap();
let d = match time::OffsetDateTime::now_local() {
Ok(now) => now,
Err(e) => {
panic!("Error {} retrieving the OffsetDateTime::now_local", e);
}
};
let offset_dt = tm.assume_offset(d.offset());
FileTime::from_unix_time(offset_dt.unix_timestamp(), tm.nanosecond())
}
@ -461,7 +473,13 @@ fn test_touch_mtime_dst_succeeds() {
// In other locales it will be a different date/time, and in some locales
// it doesn't exist at all, in which case this function will return None.
fn get_dst_switch_hour() -> Option<String> {
let now = time::OffsetDateTime::now_local().unwrap();
//let now = time::OffsetDateTime::now_local().unwrap();
let now = match time::OffsetDateTime::now_local() {
Ok(now) => now,
Err(e) => {
panic!("Error {} retrieving the OffsetDateTime::now_local", e);
}
};
// Start from January 1, 2020, 00:00.
let tm = datetime!(2020-01-01 00:00 UTC);