-
-
Notifications
You must be signed in to change notification settings - Fork 281
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
thread 'main' panicked at 'called time::OffsetDateTime::now_local().unwrap()
on an Err
value: IndeterminateOffset'
#427
Comments
The method is fallible for a reason. Don't call |
But can't get local time on MacOS? |
With the version published on crates.io, no. It will be supported in the next release, but only when the program does not have multiple threads running. You should explicitly handle the error case in any situation. |
Ok, now I use the let mut now = time: : OffsetDateTime: : now_utc ();
let off = UtcOffset::from_whole_seconds(chrono::offset::Local::now().offset().local_minus_utc()).unwrap();
now = now.to_offset(off); Instead of this. |
What chrono does is unsound and can crash your program completely and without warning. It is a security concern. Time does not have this problem. That is why it will be restricted to single-threaded programs in the next release. |
So I call this method only if I have a mutex, right? To ensure that it cannot be accessed by multiple threads at the same time |
That is not correct. If you have multiple threads running, the method will fail on MacOS. |
oh, maybe i should save in to Lazy Global data
So time zone data is only fetched once。 thanks |
If you call Chrono is unsound. If you use the time crate, you will not encounter unsoundness. That is a guarantee I provide. |
Ok, this is a temporary solution, pending a new version of Time。 should be this。 (The test will only initialize once) pub static GLOBAL_OFFSET: Lazy<UtcOffset> = Lazy::new(|| {
println!("init time");
UtcOffset::from_whole_seconds(chrono::offset::Local::now().offset().local_minus_utc()).unwrap()
}); |
thread 'main' panicked at 'called
Result::unwrap()
on anErr
value: IndeterminateOffset'os: MacOS Big Sur
The text was updated successfully, but these errors were encountered: