Debian Codegraph @

third_party/rust/time/src/sys/local_offset_at/wasm_js.rs

raw
1 use num_conv::prelude::*;
2
3 use crate::convert::*;
4 use crate::{OffsetDateTime, UtcOffset};
5
6 /// Obtain the system's UTC offset.
7 pub(super) fn local_offset_at(datetime: OffsetDateTime) -> Option<UtcOffset> {
8 let js_date: js_sys::Date = datetime.into();
9 // The number of minutes returned by getTimezoneOffset() is positive if the local time zone
10 // is behind UTC, and negative if the local time zone is ahead of UTC. For example,
11 // for UTC+10, -600 will be returned.
12 let timezone_offset =
13 (js_date.get_timezone_offset() as i32) * -Minute::per(Hour).cast_signed().extend::<i32>();
14
15 UtcOffset::from_whole_seconds(timezone_offset).ok()
16 }