1
Fork 0
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:
Sylvestre Ledru 2023-09-13 09:46:41 +02:00 committed by GitHub
commit c07bed11d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 13 deletions

4
Cargo.lock generated
View file

@ -239,9 +239,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chrono"
version = "0.4.28"
version = "0.4.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95ed24df0632f708f5f6d8082675bef2596f7084dee3dd55f632290bf35bfe0f"
checksum = "defd4e7873dbddba6c7c91e199c7fcb946abc4a6a4ac3195400bcfb01b5de877"
dependencies = [
"android-tzdata",
"iana-time-zone",

View file

@ -263,7 +263,7 @@ binary-heap-plus = "0.5.0"
bstr = "1.6"
bytecount = "0.6.3"
byteorder = "1.4.3"
chrono = { version = "^0.4.28", default-features = false, features = [
chrono = { version = "^0.4.30", default-features = false, features = [
"std",
"alloc",
"clock",

View file

@ -3,10 +3,13 @@
// For the full copyright and license information, please view the LICENSE
// 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
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::{crate_version, Arg, ArgAction, ArgGroup, Command};
use filetime::{set_file_times, set_symlink_file_times, FileTime};
@ -348,8 +351,8 @@ fn parse_date(s: &str) -> UResult<FileTime> {
// Tue Dec 3 ...
// ("%c", POSIX_LOCALE_FORMAT),
//
if let Ok(parsed) = Local.datetime_from_str(s, format::POSIX_LOCALE) {
return Ok(datetime_to_filetime(&parsed));
if let Ok(parsed) = NaiveDateTime::parse_from_str(s, format::POSIX_LOCALE) {
return Ok(datetime_to_filetime(&parsed.and_utc()));
}
// 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::YYYYMMDDHHMM_OFFSET,
] {
if let Ok(parsed) = Utc.datetime_from_str(s, fmt) {
return Ok(datetime_to_filetime(&parsed));
if let Ok(parsed) = NaiveDateTime::parse_from_str(s, fmt) {
return Ok(datetime_to_filetime(&parsed.and_utc()));
}
}
@ -411,9 +414,17 @@ fn parse_timestamp(s: &str) -> UResult<FileTime> {
}
};
let mut local = chrono::Local
.datetime_from_str(&ts, format)
let local = NaiveDateTime::parse_from_str(&ts, format)
.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
// or wrap to the next minute. But that doesn't really matter, because we

View file

@ -5,7 +5,6 @@
// spell-checker:ignore (formats) cymdhm cymdhms mdhm mdhms ymdhm ymdhms datetime mktime
use crate::common::util::{AtPath, TestScenario};
use chrono::TimeZone;
use filetime::{self, FileTime};
use std::fs::remove_file;
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 {
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())
}