Access the user’s local time and time zone in your functions
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:
The Modus Local Time APIs allow you to access the user’s local time and time zone from your functions.
To begin, import the localtime
package from the SDK:
The APIs in the localtime
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:
X-Time-Zone
header is present in the request, the time zone is set to
the value of the header.TZ
environment variable is set on the host, the time zone is set to
the value of the variable.When working locally with modus dev
, Modus uses the host’s local time zone by
default. You can override this by setting the TZ
environment variable in your
.env.local
file.
In a browser-based web app, you can get the user’s time zone with the following JavaScript code:
Assign that value to a "X-Time-Zone"
request header when calling Modus, to use
it for all local time calculations.
In many cases, you can use Go’s built-in time support:
Due to Go’s WASM implementation, the standard time.Now()
function always
returns the UTC time, not the user’s local time like it usually does in Go. If
you need the user’s local time, use localtime.Now()
instead.
We’re constantly introducing new APIs through ongoing development with early users. Please open an issue if you have ideas on what would make Modus even more powerful for your next app!
Returns a pointer to a Go time.Location
object for a specific time zone.
Errors if the time zone provided is invalid.
Returns the user’s time zone in IANA format.
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"
.
Returns the current time as a time.Time
object, with the location set to the
user’s local time zone. Errors if the time zone passed to the host is invalid.
Returns the current time as a time.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"
.
Access the user’s local time and time zone in your functions
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:
The Modus Local Time APIs allow you to access the user’s local time and time zone from your functions.
To begin, import the localtime
package from the SDK:
The APIs in the localtime
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:
X-Time-Zone
header is present in the request, the time zone is set to
the value of the header.TZ
environment variable is set on the host, the time zone is set to
the value of the variable.When working locally with modus dev
, Modus uses the host’s local time zone by
default. You can override this by setting the TZ
environment variable in your
.env.local
file.
In a browser-based web app, you can get the user’s time zone with the following JavaScript code:
Assign that value to a "X-Time-Zone"
request header when calling Modus, to use
it for all local time calculations.
In many cases, you can use Go’s built-in time support:
Due to Go’s WASM implementation, the standard time.Now()
function always
returns the UTC time, not the user’s local time like it usually does in Go. If
you need the user’s local time, use localtime.Now()
instead.
We’re constantly introducing new APIs through ongoing development with early users. Please open an issue if you have ideas on what would make Modus even more powerful for your next app!
Returns a pointer to a Go time.Location
object for a specific time zone.
Errors if the time zone provided is invalid.
Returns the user’s time zone in IANA format.
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"
.
Returns the current time as a time.Time
object, with the location set to the
user’s local time zone. Errors if the time zone passed to the host is invalid.
Returns the current time as a time.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"
.