-
Notifications
You must be signed in to change notification settings - Fork 553
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
default to UTC when /etc/localtime is missing #756
Conversation
Ideally in IMO the risk with a silent fallback is there could be subtle bugs caused by expecting to get the local time but actually getting UTC rather than signalling that there is no currently defined local time. |
Nice, thanks for working on this! My inclination is to keep this scoped to Unix for now, which is where we broke compatibility with 0.4.20. I think for now we should stick to only defaulting to UTC if we get a NotFound error, and keep panicking for other types of errors. I'd like to hear about other types of failures before we tackle them. Maybe we can also improve on the error message people see in this case, to make it explicit that it's about |
Oh, and we could add a |
I guess putting the logic in timezones.rs might work? I'm not sure, did you have a chance to look at how/when libc falls back? |
I tested this locally against date command which also seems to default to UTC in the case of no With regards to putting the logic in However this may actually not be the right path - these cases where we are falling back to UTC due to a missing I'm also somewhat tempted by the suggestion of using Alternatively to make this work in
|
I think we should go the other way and rely on the system timezone database, I was thinking this morning about exposing other timezones in some way through the type system (where available). You aren't quite explicit about why this solution doesn't work on Android, is that because we need to check this extra property? How would that work? |
Okay, after reviewing the code in iana-time-zone I can see that it would make sense to pull that in as a dependency. But not sure why that should be used with chrono-tz? |
This is an excellent idea IMO! As its better to have the automatically updated system tzdb (plus, a "static" feature could be possible for deployments to an environment lacking tzdb).
We have to use the android SDK or equivalent to find the name of the currently chosen timezone
It only returns the name of the timezone, like "Asia/Kuala_Lumpur" or "America/Los_Angeles". This works if the system has the tzdb somewhere (eg Android has it, but in a different location), but |
Ideally the fallback here would only be applied if all the following conditions are met:
|
Yes, that sounds good. I think we should prioritize shipping 0.4.21 that fixes this for systems that have a tzdb on the file system (ideally today?), we can take some more time to deal with iOS, I suppose (what did your "potentially" refer to?). |
One thing to note is that there are two main classes of failures we've seen currently:
Fixing these two gets us to a much better state than now, and then further work can be done for iOS etc (I'll raise separate issues for these) |
For iOS I guess we could pull in the |
|
I guess we can see about getting support for |
81ad471
to
058241c
Compare
I've kept the MSRV change as a separate commit so it is clear when it happened |
2b7851a
to
40cec2d
Compare
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.
Looking good!
40cec2d
to
abe831b
Compare
…ng, support android fix function name
abe831b
to
669d555
Compare
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.
Great!
would be great to add android and iOS to the CI, will investigate in a seperate PR |
- Updated from version 0.4.19 to 0.4.22 - Update of rootfile - Update of metadata patch as more windows related entries in Cargo.toml to be excluded - Changelog ## 0.4.22 * Allow wasmbindgen to be optional on `wasm32-unknown-unknown` target [(#771)](chronotope/chrono#771) * Fix compile error for `x86_64-fortanix-unknown-sgx` [(#767)](chronotope/chrono#767) * Update `iana-time-zone` version to 1.44 [(#773)](chronotope/chrono#773) ## 0.4.21 * Fall back to UTC timezone in cases where no timezone is found [(#756)](chronotope/chrono#756) * Correctly detect timezone on Android [(#756)](chronotope/chrono#756) * Improve documentation for strftime `%Y` specifier [(#760)](chronotope/chrono#760) ## 0.4.20 * Add more formatting documentation and examples. * Add support for microseconds timestamps serde serialization/deserialization (#304) * Fix `DurationRound` is not TZ aware (#495) * Implement `DurationRound` for `NaiveDateTime` * Implement `std::iter::Sum` for `Duration` * Add `DateTime::from_local()` to construct from given local date and time (#572) * Add a function that calculates the number of years elapsed between now and a given `Date` or `DateTime` (#557) * Correct build for wasm32-unknown-emscripten target (#568) * Change `Local::now()` and `Utc::now()` documentation from "current date" to "current date and time" (#647) * Fix `duration_round` panic on rounding by `Duration::zero()` (#658) * Add optional rkyv support. * Add support for microseconds timestamps serde serialization for `NaiveDateTime`. * Add support for optional timestamps serde serialization for `NaiveDateTime`. * Fix build for wasm32-unknown-emscripten (@yu-re-ka #593) * Make `ParseErrorKind` public and available through `ParseError::kind()` (#588) * Implement `DoubleEndedIterator` for `NaiveDateDaysIterator` and `NaiveDateWeeksIterator` * Fix panicking when parsing a `DateTime` (@botahamec) * Add support for getting week bounds based on a specific `NaiveDate` and a `Weekday` (#666) * Remove libc dependency from Cargo.toml. * Add the `and_local_timezone` method to `NaiveDateTime` * Fix the behavior of `Duration::abs()` for negative durations with non-zero nanos * Add compatibility with rfc2822 comments (#733) * Make `js-sys` and `wasm-bindgen` enabled by default when target is `wasm32-unknown-unknown` for ease of API discovery * Add the `Months` struct and associated `Add` and `Sub` impls Tested-by: Adolf Belka <[email protected]> Signed-off-by: Adolf Belka <[email protected]>
This is one potential solution to #755.
I've temporarily commented out some tests in src/offset/local/tz_info/timezone.rs, awaiting some discussion on where our "default to UTC" behavior should be (in unix.rs or in timezone.rs):
unix.rs
then the assumption of the test is invalidated as they will all panictimezone.rs
then the question is which errors should we recover from and which should we propogate (eg should filesystem errors cause a default to UTC as well?)expect
- should this default to UTC instead of panicing: