'Set timezone AdonisJs V5

I'm getting a hard time on change a timezone on AdonisJs 5.

PORT=8080
HOST=0.0.0.0
NODE_ENV=development
APP_KEY=blablablabla
DRIVE_DISK=local
TZ=America/New_York

I have tried the code above, but nothing changes.

Anyone have an idea on how to set the timezone ?



Solution 1:[1]

You need to change env.ts like this:

import Env from '@ioc:Adonis/Core/Env'

export default Env.rules({
  HOST: Env.schema.string({ format: 'host' }),
  PORT: Env.schema.number(),
  APP_KEY: Env.schema.string(),
  APP_NAME: Env.schema.string(),
  CACHE_VIEWS: Env.schema.boolean(),
  SESSION_DRIVER: Env.schema.string(),
  DRIVE_DISK: Env.schema.enum(['local'] as const),
  NODE_ENV: Env.schema.enum(['development', 'production', 'testing'] as const),
  TZ: Env.schema.string()
})

Add TZ Attribute.

Solution 2:[2]

In database.js

mysql: {
client: 'mysql',
connection: {
  host: Env.get('DB_HOST', ''),
  port: Env.get('DB_PORT', ''),
  user: Env.get('DB_USER', ''),
  password: Env.get('DB_PASSWORD', ''),
  database: Env.get('DB_DATABASE', ''),
  timezone: 'America/New_York'
},
debug: Env.get('DB_DEBUG', false)}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yi-Ju Wu
Solution 2 FK Rima