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.
Somehow I don't see what the purpose is of this and the other similar comments.
There was a problem hiding this comment.
It's used in this function:
coreutils/src/uu/touch/src/touch.rs
Lines 401 to 415 in 1037304
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.
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.
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.
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.
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.
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.
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.
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
chronohas 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.