@narando/timezones
v0.36.0
Published
A custom timezone toolkit on narando architecture.
Downloads
25
Readme
@narando/timezones
A custom timezone toolkit on narando architecture.
Getting Started
You need to have nodejs
and npm
installed.
$ npm install @narando/timezones
Usage
Get a list of all timezones to fill a <optgroup>
. Or parse a UTC Time to a given timezone.
To create an instance of the timezones module you have to import timezones
import buildTimezoneList from "@narando/buildTimezoneList";
function handleRequest(req, res) {
// You can use the function to get a grouped list of all timezones.
// With the parameter set is the given timezone preselected.
// This list can be used to generate an `<optgroup>`.
res.locals.timezones = buildTimezoneList(req.user.timezone);
res.render(`page/article`, res.locals);
}
The timezones will be displayed by the following mustache logic. In this case it will display all timezones with the user timezone selected.
<select class="form-control">
{{#timezones}}
<optgroup label="{{name}}">
{{#zones}}
<option value="{{name}}" {{#expected}} selected {{/expected}}>{{description}} </option>
{{/zones}}
</optgroup>
{{/timezones}}
</select>
Formatting UTC Time
To format a UTC in a given timezone use the following example.
import formatTime from "../formatTime";
const formattedReleaseTime = formatTime(releaseTime, req.user.timezone);