This module provides a set of functions for working with TimeZone values.
Import from the base library to use this module.
import TimeZone "mo:datetime/TimeZone";
import Components "mo:datetime/Components";
type TimeZone = Types.TimeZone
type FixedTimeZone = Types.FixedTimeZone
type Offset = Types.FixedTimeZone
type TimeZoneDescriptor = Types.TimeZoneDescriptor
func utc() : TimeZone
Helper function to create a UTC timezone (fixed at UTC+0)
let timeZone : TimeZone.TimeZone = TimeZone.utc();
func withFixedOffset(offset : Offset) : TimeZone
Helper function to create a timezone with a fixed offset like UTC+3
let timeZone : TimeZone.TimeZone = TimeZone.withFixedOffset(#hours(3)); // UTC+3
func toOffsetSeconds(timeZone : TimeZone, components : Components) : Int
Gets the UTC offset in seconds for the specified components and time zone. The components are used if the timezone is dynamic. This is due to the timezone offset being dependent on the date (daylight savings, changes to timezone offset, etc...).
let timeZone : TimeZone.TimeZone = ...;
let c : Components.Components = {year = 2020; month = 1; day = 1; hour = 0; minute = 0; nanosecond = 0};
let offsetSeconds : Int = TimeZone.getOffsetSeconds(timeZone, c);
func toFixedOffsetSeconds(fixedTimeZone : FixedTimeZone) : Int
Gets the UTC offset in seconds for the specified fixed time zone.
let timeZone : TimeZone.TimeZone = #fixed(#hours(1));
let offsetSeconds : Int = TimeZone.getFixedOffsetSeconds(timeZone);