@rocketseat/adonis-timezone
v0.7.0
Published
This library provides an easy way to start using timezones with AdonisJS.
Downloads
831
Readme
Adonis Timezone Provider
This library provides an easy way to start using timezones with AdonisJS.
Install
adonis install @rocketseat/adonis-timezone
Use
To use this provider you need to add a trait
inside your Model
, like this:
class User extends Model {
static boot() {
super.boot();
this.addTrait("@provider:Timezone/Trait");
}
}
OBS: Unfortunately cannot overwrite castDates
And you need to create a middleware and inside it, use the timezone
context variable.
On the timezone variable, you can choose the timezone, that your model will provide the timestamps and custom time & date.
class Timezone {
async handle({ timezone }, next) {
timezone.activate("America/Sao_Paulo");
await next();
}
}
If you'd like to add user's timezone, then you should add a named middleware to the timezone
and the user must have a timezone field in their Model.
class Timezone {
async handle({ timezone, auth }, next) {
timezone.activate(auth.user.timezone);
await next();
}
}