Use macOS API to retrieve the local timezone

The `time` crate currently doesn't have a reliable way to get that.
In the future, `NSSystemTimeZoneDidChangeNotification` could be
used to keep the cached timezone up-to-date.

Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
Antonio Scandurra
2021-09-02 19:15:05 +02:00
co-authored by Max Brunsfeld
parent 3d4ff43f9e
commit f59e02cf25
7 changed files with 30 additions and 6 deletions
+9
View File
@@ -42,6 +42,7 @@ use std::{
slice, str,
sync::Arc,
};
use time::UtcOffset;
const MAC_PLATFORM_IVAR: &'static str = "platform";
static mut APP_CLASS: *const Class = ptr::null();
@@ -558,6 +559,14 @@ impl platform::Platform for MacPlatform {
let _: () = msg_send![cursor, set];
}
}
fn local_timezone(&self) -> UtcOffset {
unsafe {
let local_timezone: id = msg_send![class!(NSTimeZone), localTimeZone];
let seconds_from_gmt: NSInteger = msg_send![local_timezone, secondsFromGMT];
UtcOffset::from_whole_seconds(seconds_from_gmt.try_into().unwrap()).unwrap()
}
}
}
unsafe fn get_foreground_platform(object: &mut Object) -> &MacForegroundPlatform {
+5
View File
@@ -9,6 +9,7 @@ use std::{
rc::Rc,
sync::Arc,
};
use time::UtcOffset;
pub struct Platform {
dispatcher: Arc<dyn super::Dispatcher>,
@@ -136,6 +137,10 @@ impl super::Platform for Platform {
fn set_cursor_style(&self, style: CursorStyle) {
*self.cursor.lock() = style;
}
fn local_timezone(&self) -> UtcOffset {
UtcOffset::UTC
}
}
impl Window {