mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #5270 from cakebaker/bump_chrono_and_adapt_touch
Bump chrono and fix deprecation warnings in touch
This commit is contained in:
commit
c07bed11d7
4 changed files with 23 additions and 13 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -239,9 +239,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chrono"
|
name = "chrono"
|
||||||
version = "0.4.28"
|
version = "0.4.30"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "95ed24df0632f708f5f6d8082675bef2596f7084dee3dd55f632290bf35bfe0f"
|
checksum = "defd4e7873dbddba6c7c91e199c7fcb946abc4a6a4ac3195400bcfb01b5de877"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"android-tzdata",
|
"android-tzdata",
|
||||||
"iana-time-zone",
|
"iana-time-zone",
|
||||||
|
|
|
@ -263,7 +263,7 @@ binary-heap-plus = "0.5.0"
|
||||||
bstr = "1.6"
|
bstr = "1.6"
|
||||||
bytecount = "0.6.3"
|
bytecount = "0.6.3"
|
||||||
byteorder = "1.4.3"
|
byteorder = "1.4.3"
|
||||||
chrono = { version = "^0.4.28", default-features = false, features = [
|
chrono = { version = "^0.4.30", default-features = false, features = [
|
||||||
"std",
|
"std",
|
||||||
"alloc",
|
"alloc",
|
||||||
"clock",
|
"clock",
|
||||||
|
|
|
@ -3,10 +3,13 @@
|
||||||
// For the full copyright and license information, please view the LICENSE
|
// For the full copyright and license information, please view the LICENSE
|
||||||
// file that was distributed with this source code.
|
// file that was distributed with this source code.
|
||||||
|
|
||||||
// spell-checker:ignore (ToDO) filetime datetime lpszfilepath mktime DATETIME subsecond datelike timelike
|
// spell-checker:ignore (ToDO) filetime datetime lpszfilepath mktime DATETIME datelike timelike
|
||||||
// spell-checker:ignore (FORMATS) MMDDhhmm YYYYMMDDHHMM YYMMDDHHMM YYYYMMDDHHMMS
|
// spell-checker:ignore (FORMATS) MMDDhhmm YYYYMMDDHHMM YYMMDDHHMM YYYYMMDDHHMMS
|
||||||
|
|
||||||
use chrono::{DateTime, Datelike, Duration, Local, NaiveDate, NaiveTime, TimeZone, Timelike, Utc};
|
use chrono::{
|
||||||
|
DateTime, Datelike, Duration, Local, LocalResult, NaiveDate, NaiveDateTime, NaiveTime,
|
||||||
|
TimeZone, Timelike,
|
||||||
|
};
|
||||||
use clap::builder::ValueParser;
|
use clap::builder::ValueParser;
|
||||||
use clap::{crate_version, Arg, ArgAction, ArgGroup, Command};
|
use clap::{crate_version, Arg, ArgAction, ArgGroup, Command};
|
||||||
use filetime::{set_file_times, set_symlink_file_times, FileTime};
|
use filetime::{set_file_times, set_symlink_file_times, FileTime};
|
||||||
|
@ -348,8 +351,8 @@ fn parse_date(s: &str) -> UResult<FileTime> {
|
||||||
// Tue Dec 3 ...
|
// Tue Dec 3 ...
|
||||||
// ("%c", POSIX_LOCALE_FORMAT),
|
// ("%c", POSIX_LOCALE_FORMAT),
|
||||||
//
|
//
|
||||||
if let Ok(parsed) = Local.datetime_from_str(s, format::POSIX_LOCALE) {
|
if let Ok(parsed) = NaiveDateTime::parse_from_str(s, format::POSIX_LOCALE) {
|
||||||
return Ok(datetime_to_filetime(&parsed));
|
return Ok(datetime_to_filetime(&parsed.and_utc()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Also support other formats found in the GNU tests like
|
// Also support other formats found in the GNU tests like
|
||||||
|
@ -361,8 +364,8 @@ fn parse_date(s: &str) -> UResult<FileTime> {
|
||||||
format::YYYY_MM_DD_HH_MM,
|
format::YYYY_MM_DD_HH_MM,
|
||||||
format::YYYYMMDDHHMM_OFFSET,
|
format::YYYYMMDDHHMM_OFFSET,
|
||||||
] {
|
] {
|
||||||
if let Ok(parsed) = Utc.datetime_from_str(s, fmt) {
|
if let Ok(parsed) = NaiveDateTime::parse_from_str(s, fmt) {
|
||||||
return Ok(datetime_to_filetime(&parsed));
|
return Ok(datetime_to_filetime(&parsed.and_utc()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -411,9 +414,17 @@ fn parse_timestamp(s: &str) -> UResult<FileTime> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut local = chrono::Local
|
let local = NaiveDateTime::parse_from_str(&ts, format)
|
||||||
.datetime_from_str(&ts, format)
|
|
||||||
.map_err(|_| USimpleError::new(1, format!("invalid date ts format {}", ts.quote())))?;
|
.map_err(|_| USimpleError::new(1, format!("invalid date ts format {}", ts.quote())))?;
|
||||||
|
let mut local = match chrono::Local.from_local_datetime(&local) {
|
||||||
|
LocalResult::Single(dt) => dt,
|
||||||
|
_ => {
|
||||||
|
return Err(USimpleError::new(
|
||||||
|
1,
|
||||||
|
format!("invalid date ts format {}", ts.quote()),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Chrono caps seconds at 59, but 60 is valid. It might be a leap second
|
// Chrono caps seconds at 59, but 60 is valid. It might be a leap second
|
||||||
// or wrap to the next minute. But that doesn't really matter, because we
|
// or wrap to the next minute. But that doesn't really matter, because we
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
// spell-checker:ignore (formats) cymdhm cymdhms mdhm mdhms ymdhm ymdhms datetime mktime
|
// spell-checker:ignore (formats) cymdhm cymdhms mdhm mdhms ymdhm ymdhms datetime mktime
|
||||||
|
|
||||||
use crate::common::util::{AtPath, TestScenario};
|
use crate::common::util::{AtPath, TestScenario};
|
||||||
use chrono::TimeZone;
|
|
||||||
use filetime::{self, FileTime};
|
use filetime::{self, FileTime};
|
||||||
use std::fs::remove_file;
|
use std::fs::remove_file;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
@ -32,7 +31,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::Utc.datetime_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.timestamp(), tm.timestamp_subsec_nanos())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue