While each Modus SDK offers similar capabilities, the APIs and usage may vary between languages.Modus Local Time APIs documentation is available on the following pages:
- AssemblyScript Local Time APIs
- Go Local Time APIs(this page)
Import
To begin, import thelocaltime package from the SDK:
Local Time APIs
The APIs in thelocaltime package are below.
All time zones use the IANA time zone database format. For example,
"America/New_York". You can find a list of valid time zones
here.
For APIs that work with the user’s local time, the time zone is determined in
the following order of precedence:
- If the
X-Time-Zoneheader is present in the request, the time zone is set to the value of the header. - If the
TZenvironment variable is set on the host, the time zone is set to the value of the variable. - Otherwise, the time zone is set to the host’s local time zone.
Functions
GetLocation
Returns a pointer to a Gotime.Location object for a specific time zone.
Errors if the time zone provided is invalid.
GetTimeZone
Returns the user’s time zone in IANA format.IsValidTimeZone
Determines whether the specified time zone is a valid IANA time zone and recognized by the system as such.An IANA time zone identifier, such as
"America/New_York".Now
Returns the current time as atime.Time object, with the location set to the
user’s local time zone. Errors if the time zone passed to the host is invalid.
NowInZone
Returns the current time as atime.Time object, with the location set to a
specific time zone. Errors if the time zone provided is invalid.
An IANA time zone identifier, such as
"America/New_York".