0.7.0 • Published 5 years ago

@rocketseat/adonis-timezone v0.7.0

Weekly downloads
183
License
MIT
Repository
github
Last release
5 years ago

Adonis Timezone Provider

This library provides an easy way to start using timezones with AdonisJS.

Coverage Status

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();
  }
}
0.7.0

5 years ago

0.6.0

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago