Skip to content

Timezone

1. Get Current Timezone

typescript
const tz = this.ctx.tz;

2. Set Current Timezone

typescript
this.ctx.tz = 'America/New_York';

Rules for Getting the Current Timezone

When a user accesses the backend API, the backend will automatically obtain the current Timezone according to the rules

1. Module Configuration

I18n is the core capability provided by the module a-i18n. The module configuration can be modified in the App Config:

src/backend/config/config/config.ts

typescript
// modules
config.modules = {
  'a-i18n': {
    tz: {
      defaultTz: undefined,
      queryField: 'x-vona-tz',
      headerField: 'x-vona-tz',
      cookieField: 'tz',
    },
  },
};
NameDescription
defaultTzDefault timezone
queryFieldRetrieves the current timezone from the request query. The query key defaults to x-vona-tz
headerFieldRetrieves the current timezone from the request header. The header key defaults to x-vona-tz
cookieFieldRetrieves the current timezone from the request cookie. The cookie key defaults to tz

2. Rule Order

The system determines the current timezone in the following order:

queryField > headerField > cookieField > user tz > defaultTz > undefined(system timezone)

Released under the MIT License.