Skip to content
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

update time crate to 0.3 #3319

Merged
merged 22 commits into from
May 8, 2022
Merged

update time crate to 0.3 #3319

merged 22 commits into from
May 8, 2022

Conversation

g-k
Copy link
Contributor

@g-k g-k commented Mar 27, 2022

This is a draft PR to fix #2884 it still needs some clean up work, but I'd like to get feedback on this approach and the scope of the issue.

Changes:

  • update the time crate to 0.3

Caveats / Questions:

  • How does this project want to handle datetimes and TZ data? This PR disables touch filetime printing daylight savings time tests. time 0.3 removes timezone support and the Timespec DST flag (upstream issue Timezones a-la chrono-tz time-rs/time#351). Unicode icu4x might provide longer term stability and allow us to localize dates and times for strftime %b and %c currently we assume LC_ALL=C e.g. from Create an Ideal Components Bag / Skeleton for DateTimeFormat  unicode-org/icu4x#1317
  • Is Update the time crate to 0.3 #2884 for upgrading direct usage of time 0.1 or removing it from the dep tree entirely? This PR still uses time 0.1 indirectly via chrono.
  • How much do we care about RUSTSEC-2020-0071? To fix this we'd need chrono to update to time 0.3 and bump time chronotope/chrono#639 (comment) suggests they aren't planning to. I can see spinning this off into a separate issue.
  • Related to ^ this PR uses the time 0.3 uses unsound_local_offset config. My read is that racing multithreaded reads of env vars are unlikely to be an issue for single threaded, short lived CLI utils, but I can do more in this PR to isolate and limit the number of fallible calls e.g. read offset once at load.

Tests:

  • RUSTFLAGS="--cfg unsound_local_offset" cargo test --features=feat_require_unix_utmpx,feat_common_core passes locally with version:
rustc --version --verbose
rustc 1.58.1 (db9d1b20b 2022-01-20)
binary: rustc
commit-hash: db9d1b20bba1968c1ec1fc49616d4742c1725b4b
commit-date: 2022-01-20
host: aarch64-apple-darwin
release: 1.58.1
LLVM version: 13.0.0

@sylvestre
Copy link
Contributor

cool stuff, bravo :)

Answer:

about sec

I don't care about that RUSTSEC-2020-0071, afaik, nobody is using this crate in production and rust sec is less worrying that C's

How does this project want to handle datetimes and TZ data?

Just like GNU :)

about time 0.1

I would like to see that update to 0.3 everywhere (or switch to chrono)

@jfinkels
Copy link
Collaborator

See also #3300

@g-k g-k force-pushed the 2884-time-0.3 branch 3 times, most recently from a36fbbf to 4d95f89 Compare April 3, 2022 20:38
@sylvestre sylvestre force-pushed the 2884-time-0.3 branch 2 times, most recently from a44f081 to 3fc5b37 Compare April 12, 2022 07:54
@sylvestre
Copy link
Contributor

@g-k sorry for the ping :) do you have an update on this? This is the main blocker to have it in Debian :)
thanks

@g-k
Copy link
Contributor Author

g-k commented Apr 19, 2022

Oh getting it in Debian is exciting!

I'm not sure how to fix the remaining errors and I don't think I'll have time to finish it in a reasonable amount of time.

Happy to hand it off if someone else wants to pick it up.

@sylvestre
Copy link
Contributor

I think I fixed all the issues but one:

$ stat -c %z /bin/sh   
2021-11-26 17:20:49.310012278 +0100
$ ./target/debug/coreutils stat -c %z /bin/sh
2021-11-26 18:20:49.310012278 +0200

(note the +01 vs +02 for the TZ)

while the following work:

$ stat -c %z Cargo.toml
2022-04-23 21:46:14.564134437 +0200
$ ./target/debug/coreutils stat -c %z Cargo.toml
2022-04-23 21:46:14.564134437 +0200

Not sure what is going on?
Maybe a DST issue when the file was created?!

@tertsdiepraam
Copy link
Member

tertsdiepraam commented Apr 26, 2022

Something related to DST seems likely. The dates seem to match with when the timezone changes. If I touch 2 files and give them the dates before and after DST starts I get the same behaviour (all using GNU):

❯ touch -t 03260500 test1 # March 26 5:00
❯ touch -t 03280500 test2 # March 28 5:00, DST starts March 27
❯ stat -c %x test1
2022-03-26 05:00:00.000000000 +0100
❯ stat -c %x test2
2022-03-28 05:00:00.000000000 +0200

(I use %x because the creation time is not affected by touch).

Using uutils (from this PR):

❯ uu_stat -c %x test1
2022-03-26 05:00:00.0 +0200
❯ uu_stat -c %x test2
2022-03-28 05:00:00.0 +0200

Note also the difference in rounding.

@sylvestre sylvestre requested a review from tertsdiepraam April 26, 2022 21:25
@sylvestre
Copy link
Contributor

Warning: Congrats! The gnu test tests/touch/relative is no longer failing!
Error: GNU test failed: tests/touch/60-seconds. tests/touch/60-seconds is passing on 'main'. Maybe you have to rebase?

@sylvestre sylvestre marked this pull request as ready for review April 27, 2022 06:38
@sylvestre
Copy link
Contributor

The GNU failure is

$ ./target/debug/coreutils touch -t 197001010000.60 f      
touch: invalid date ts format '197001010000.60'

Copy link
Member

@tertsdiepraam tertsdiepraam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, they made a lot of breaking changes in the time crate! Really nice to see this completed :)

Comment on lines +352 to +404
// // 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.
// // Convert back to local time and see if we got the same value back.
// let ts = time::Timespec {
// sec: ft.unix_seconds(),
// nsec: 0,
// };
// let tm2 = time::at(ts);
// if tm.tm_hour != tm2.tm_hour {
// return Err(USimpleError::new(
// 1,
// format!("invalid date format {}", s.quote()),
// ));
// }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this commented out? Is it no longer necessary or is it a remaining thing to port?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed that, @g-k do you remember ? :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it isn't breaking any test on our side or GNU's
So, I am in favor of remove this piece of code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh yeah. This is a remaining thing to port, but also an edge case and probably hard to run into in practice.

IIRC time 0.3 dropped TZ support and removed the Tm struct and tm_isdst flag, so I wasn't sure how to proceed since it didn't look like there were good alternatives.

Dropping the code and waiting for support in icu4x seems like a reasonable path to me (icu would also potentially let coreutils handle localized strftime args).

Mentioned it a bit in this part of #3319 (comment) but I had the wrong struct and flag name:

How does this project want to handle datetimes and TZ data? This PR disables touch filetime printing daylight savings time tests. time 0.3 removes timezone support and the Timespec DST flag (upstream issue time-rs/time#351). Unicode icu4x might provide longer term stability and allow us to localize dates and times for strftime %b and %c currently we assume LC_ALL=C e.g. from unicode-org/icu4x#1317

src/uucore/Cargo.toml Outdated Show resolved Hide resolved
src/uucore/src/lib/features/fsext.rs Outdated Show resolved Hide resolved
@sylvestre
Copy link
Contributor

sylvestre commented Apr 29, 2022

Actually, I am wrong:
Warning: Changes from 'main': PASS -2 / FAIL -1 / ERROR +3 / SKIP +0

I will have a look to the errors

@sylvestre sylvestre force-pushed the 2884-time-0.3 branch 2 times, most recently from a201b23 to f5d1021 Compare May 6, 2022 06:41
@sylvestre
Copy link
Contributor

Finally! :)
Warning: Changes from 'main': PASS +0 / FAIL +0 / ERROR +0 / SKIP +0

Not perfect. I am not happy with the long list of format_description in touch.rs
https://github.com/uutils/coreutils/pull/3319/files#diff-9565d8fad7b29837b3b468a61a809dc187fb351a72421ffe4b7c4879a8445b27R264=

I will land it to iterate from it

reported:
#3505

@sylvestre sylvestre merged commit 779eca4 into uutils:main May 8, 2022
@tertsdiepraam
Copy link
Member

Finally! This is amazing!

@g-k g-k deleted the 2884-time-0.3 branch May 8, 2022 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update the time crate to 0.3
4 participants