summaryrefslogtreecommitdiffstats
path: root/vendor/time/src/sys/local_offset_at/wasm_js.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/time/src/sys/local_offset_at/wasm_js.rs')
-rw-r--r--vendor/time/src/sys/local_offset_at/wasm_js.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/vendor/time/src/sys/local_offset_at/wasm_js.rs b/vendor/time/src/sys/local_offset_at/wasm_js.rs
new file mode 100644
index 000000000..fcea4b0f5
--- /dev/null
+++ b/vendor/time/src/sys/local_offset_at/wasm_js.rs
@@ -0,0 +1,12 @@
+use crate::{OffsetDateTime, UtcOffset};
+
+/// Obtain the system's UTC offset.
+pub(super) fn local_offset_at(datetime: OffsetDateTime) -> Option<UtcOffset> {
+ let js_date: js_sys::Date = datetime.into();
+ // The number of minutes returned by getTimezoneOffset() is positive if the local time zone
+ // is behind UTC, and negative if the local time zone is ahead of UTC. For example,
+ // for UTC+10, -600 will be returned.
+ let timezone_offset = (js_date.get_timezone_offset() as i32) * -60;
+
+ UtcOffset::from_whole_seconds(timezone_offset).ok()
+}