-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
touch
: move from time
to chrono
#4600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
touch
: move from time
to chrono
#4600
Conversation
4ff8b60
to
3081b15
Compare
Some rustfmt & clippy warnings |
Yeah I'll look into those after the PR it depends on is merged. |
3081b15
to
f98247c
Compare
f98247c
to
21b1dab
Compare
21b1dab
to
795030a
Compare
Windows is broken:
|
Yes, I'll look into that :) |
I bet Windows doesn't work because it does not parse the libc-style timezone syntax. I think it's best if I just disable the test for Windows. At least we get the correct behaviour merged then. Do you agree, @sylvestre? |
@tertsdiepraam sorry, i missed your question. I am fine with disabling the test on Windows |
ca4292a
to
1037304
Compare
I disabled the test on windows and got this all up to date with |
mod format { | ||
pub(crate) const POSIX_LOCALE: &str = "%a %b %e %H:%M:%S %Y"; | ||
pub(crate) const ISO_8601: &str = "%Y-%m-%d"; | ||
// "%Y%m%d%H%M.%S" 15 chars |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somehow I don't see what the purpose is of this and the other similar comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's used in this function:
coreutils/src/uu/touch/src/touch.rs
Lines 401 to 415 in 1037304
let (format, ts) = match s.chars().count() { | |
15 => (YYYYMMDDHHMM_DOT_SS, s.to_owned()), | |
12 => (YYYYMMDDHHMM, s.to_owned()), | |
// If we don't add "20", we have insufficient information to parse | |
13 => (YYYYMMDDHHMM_DOT_SS, format!("20{}", s)), | |
10 => (YYYYMMDDHHMM, format!("20{}", s)), | |
11 => (YYYYMMDDHHMM_DOT_SS, format!("{}{}", current_year(), s)), | |
8 => (YYYYMMDDHHMM, format!("{}{}", current_year(), s)), | |
_ => { | |
return Err(USimpleError::new( | |
1, | |
format!("invalid date format {}", s.quote()), | |
)) | |
} | |
}; |
It's mostly just a leftover from before, when it was harder to determine the length of the format due to the format strings from the time
crate. I can remove it if you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove them.
src/uu/touch/src/touch.rs
Outdated
/// | ||
/// The DateTime is converted into a unix timestamp from which the FileTime is | ||
/// constructed. | ||
fn dt_to_filetime<T: TimeZone>(dt: &DateTime<T>) -> FileTime { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use datetime
instead of dt
because chrono also uses datetime
in its function names.
fn dt_to_filetime<T: TimeZone>(dt: &DateTime<T>) -> FileTime { | |
fn datetime_to_filetime<T: TimeZone>(dt: &DateTime<T>) -> FileTime { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that name was leftover from local_dt_to_filetime
. I'll fix it
src/uu/touch/src/touch.rs
Outdated
|
||
Ok(ft) | ||
|
||
// We have to check that ft is valid time. Due to daylight saving |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess ft
is a left over from the previous code. Not sure whether this first sentence is even needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I removed the sentence
src/uu/touch/src/touch.rs
Outdated
// We have to check that ft is valid time. Due to daylight saving | ||
// time switch, local time can jump from 1:59 AM to 3:00 AM, | ||
// in which case any time between 2:00 AM and 2:59 AM is not valid. | ||
// If we are within this jump, chrono assumes takes the offset from before |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure whether there is something missing between "assumes" and "takes" or one of those words can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, I removed "assumes"
This allows us to work with daylight savings time which is necessary to enable one of the tests. The leap second calculation and parsing are also ported over. A bump in the chrono version is necessary to use NaiveTime::MIN.
1037304
to
c299771
Compare
chrono
has better support for daylight savings time, so I was able to support that and enable the test for it. It's also just easier to work with, so we can remove a lot of verbosity with this too.For reviewing, the DST and leap second handling is probably most important. The formats should also be checked, even though they are (hopefully) well-tested.