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

fix/touch ~ time crate usage errors

This commit is contained in:
Roy Ivy III 2023-06-11 19:45:06 -05:00 committed by Daniel Hofstetter
parent 9aef5ac35b
commit af64bde92b

View file

@ -85,12 +85,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
(Some(reference), Some(date)) => {
let (atime, mtime) = stat(Path::new(reference), !matches.get_flag(options::NO_DEREF))?;
if let Ok(offset) = parse_datetime::from_str(date) {
let mut seconds = offset.whole_seconds();
let mut nanos = offset.subsec_nanoseconds();
if nanos < 0 {
nanos += 1_000_000_000;
seconds -= 1;
}
let seconds = offset.num_seconds();
let nanos = offset.num_nanoseconds().unwrap_or(0) % 1_000_000_000;
let ref_atime_secs = atime.unix_seconds();
let ref_atime_nanos = atime.nanoseconds();
@ -447,7 +443,11 @@ fn parse_date(s: &str) -> UResult<FileTime> {
if let Ok(duration) = parse_datetime::from_str(s) {
let now_local = time::OffsetDateTime::now_local().unwrap();
let diff = now_local.checked_add(duration).unwrap();
let diff = now_local
.checked_add(time::Duration::nanoseconds(
duration.num_nanoseconds().unwrap(),
))
.unwrap();
return Ok(local_dt_to_filetime(diff));
}