-
Notifications
You must be signed in to change notification settings - Fork 542
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
Parse time zone info in Rust on Unix systems #677
Conversation
43a4ff9
to
c0e806e
Compare
78b2835
to
69169ec
Compare
For information, since the last release of
I also added some documentation mentioning what a value of |
I wasn't aware of that! I found the interface substantially more painful but for this purpose it makes sense, so this PR now no longer pulls in once_cell. Thanks for the pointer!
Thanks, I will definitely be watching your follow-up commits after this is merged. |
Hi @djc - I've had an attempt to fix my above comments here and also added some more tests: https://github.com/esheppa/chrono/tree/tz-info-extra (Please note that I've not yet fixed at least two areas with the *_from_local functions: |
@esheppa I'm not seeing your "above comments" -- did you forget to submit them? If you have a chance, could you submit any fixes as a PR that targets this PR's branch? |
src/offset/local/unix.rs
Outdated
|
||
pub(super) fn naive_to_local(d: &NaiveDateTime, local: bool) -> DateTime<Local> { | ||
let offset = match local { | ||
true => offset(d.timestamp()), |
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.
the d.timestamp()
in this case is in local timezone, not in UTC, so it needs to be adjusted back (or forward) to UTC before it can be passed to the offset
function. Alternatively, a custom version of find_local_time_type
could be implemented which takes a local timestamp instead of a UTC timestamp.
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 just published the version 0.6.8
of tz-rs
where I have added a method DateTime::find()
which covers this use case.
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.
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 see that you used unwrap()
, which will panic if the datetime is after the last transition and there is no extra rule.
src/offset/local/unix.rs
Outdated
false => FixedOffset::east(0), | ||
}; | ||
|
||
DateTime::from_utc(*d - offset, offset) |
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.
where d
is a UTC timestamp we still need to provide the local offset, for example:
DateTime::from_utc(*d - offset, offset(d.timestamp()))
I forgot to submit before, I've now submitted the comments and created PR #678 |
Based on tz-rs commit b8675e2b5794d923f80970daf9ea548cfb998db2, with substantial modifications from me.
See #674 for next release planning. |
See the release announcement: - https://github.com/chronotope/chrono/releases/tag/v0.4.20 It looks like the fix for RUSTSEC-2020-0159 vendors much of the relevant code from `tz-rs` (which Artichoke already uses): - chronotope/chrono#677 Previous `cargo deny` error (I think this started triggering today now that there is a fixed version out): ```console $ cargo deny check error[A001]: Potential segfault in `localtime_r` invocations ┌─ /Users/lopopolo/dev/artichoke/artichoke/Cargo.lock:15:1 │ 15 │ chrono 0.4.19 registry+https://github.com/rust-lang/crates.io-index │ ------------------------------------------------------------------- security vulnerability detected │ = ID: RUSTSEC-2020-0159 = Advisory: https://rustsec.org/advisories/RUSTSEC-2020-0159 = ### Impact Unix-like operating systems may segfault due to dereferencing a dangling pointer in specific circumstances. This requires an environment variable to be set in a different thread than the affected functions. This may occur without the user's knowledge, notably in a third-party library. ### Workarounds No workarounds are known. ### References - [time-rs/time#293](time-rs/time#293) = Announcement: chronotope/chrono#499 = Solution: Upgrade to >=0.4.20 = chrono v0.4.19 ├── chrono-tz v0.6.1 │ └── spinoso-time v0.5.0 │ └── artichoke-backend v0.13.0 │ └── artichoke v0.1.0-pre.0 └── spinoso-time v0.5.0 (*) advisories FAILED, bans ok, licenses ok, sources ok ```
There is a long-standing problem (time-rs/time#293) that has not yet been solved by time-rs Switch to chrono as it seemed to solve the problem (chronotope/chrono#677)
There is a long-standing problem (time-rs/time#293) that has not yet been solved by time-rs Switch to chrono as it seemed to solve the problem (chronotope/chrono#677)
…ystem There is a long-standing problem (time-rs/time#293) that has not yet been solved by time-rs Switch to chrono as it seemed to solve the problem (chronotope/chrono#677)
There is a long-standing problem (time-rs/time#293) that has not yet been solved by time-rs Switch to chrono as it seemed to solve the problem (chronotope/chrono#677)
Fixes #499 by vendoring a heavily modified copy of tz-rs.
Why we don't use tz-rs directly:
Alternative solutions: like time, we could check for concurrently running threads before running
localtime_r()
, leaving tzinfo handling to libc. Using well-tested Rust code to parse the timezone info files seems preferable to me over platform-specific hacks to find out if other threads are running.@x-hgg-x thanks for your work on tz-rs!