A Jovo Framework plugin for cross-platform timezone including defaults per country code.
npm install @jovo-community/plugin-timezonev4 allows you to easily add cross-platform time zone support including an overall default time zone if there is not a country-code-specific default.
typescript
this.jovo.$session.data.$timeZone
`
Don't access or change this value, instead use the method on the plugin:
`js
const tz = await this.$timeZone.getTimeZone();
`
Install
Install the plugin into your Jovo project:
`sh
npm install @jovo-community/plugin-timezone
`
Register the plugin in app.ts:
`typescript
import { TimeZonePlugin } from '@jovo-community/plugin-timezone';
const app = new App({
// ...
plugins: [
new TimeZonePlugin(),
// ...
],
}
`
Get the time zone in your handler:
`typescript
const tz = await this.$timeZone.getTimeZone();
`
Configuration
You can set an overall default time zone fallback or defaults based on the country code portion of the locale that is sent with every request.
`typescript
import { TimeZonePlugin } from '@jovo-community/plugin-timezone';
const app = new App({
// ...
plugins: [
new TimeZonePlugin({
defaultTimeZone: 'America/New_York',
defaultTimeZoneByLocaleCountryCode: {
US: 'America/New_York',
GB: 'Europe/London',
CA: 'America/Toronto',
AU: 'Australia/Sydney',
IN: 'Asia/Kolkata',
},
}),
// ...
],
}
`
Jovo Debugger
If using the Jovo Debugger, you must add $timeZone to the list of properties the debugger ignores:
`ts
// app.dev.ts
new JovoDebugger({
ignoredProperties: ['$app', '$handleRequest', '$platform', '$timeZone'],
}),
``