mirror of
https://github.com/gorules/zen.git
synced 2026-10-04 08:02:28 +00:00
fix: timezone caching (#371)
This commit is contained in:
@@ -185,12 +185,17 @@ mod helper {
|
||||
use rust_decimal::prelude::ToPrimitive;
|
||||
use std::ops::{Add, Deref};
|
||||
use std::str::FromStr;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
fn tz() -> Tz {
|
||||
iana_time_zone::get_timezone()
|
||||
.ok()
|
||||
.and_then(|tz| Tz::from_str(&tz).ok())
|
||||
.unwrap_or_else(|| Tz::UTC)
|
||||
static CACHED_TZ: OnceLock<Tz> = OnceLock::new();
|
||||
|
||||
*CACHED_TZ.get_or_init(|| {
|
||||
iana_time_zone::get_timezone()
|
||||
.ok()
|
||||
.and_then(|tz| Tz::from_str(&tz).ok())
|
||||
.unwrap_or_else(|| Tz::UTC)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn now() -> DateTime<Tz> {
|
||||
|
||||
Reference in New Issue
Block a user