# @rocketseat/adonis-timezone

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

Latest version **0.7.0** (published 2019-10-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install @rocketseat/adonis-timezone
pnpm add @rocketseat/adonis-timezone
yarn add @rocketseat/adonis-timezone
bun add @rocketseat/adonis-timezone
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.7.0 |
| Published | 2019-10-17 |
| First published | 2019-09-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 10.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 54 |
| Maintainers | aldroyd, csorlandi, dieegosf, higoribeiro, jpdemagalhaes, jpedroschmitz, thepellizzetti |
| Keywords | timezone, adonis, adonisjs, adonis-js, adonis-timezone |

## Links

- npm: https://www.npmjs.com/package/@rocketseat/adonis-timezone
- Repository: https://github.com/Rocketseat/adonis-timezone
- Homepage: https://github.com/Rocketseat/adonis-timezone#readme
- Issues: https://github.com/Rocketseat/adonis-timezone/issues
- npm.io page: https://npm.io/package/@rocketseat/adonis-timezone

## Dependencies (1)

- [moment-timezone](https://npm.io/package/moment-timezone.md) ^0.5.26

## Alternatives

- [@js-joda/timezone](https://npm.io/package/@js-joda/timezone.md) — 383.4K weekly downloads
- [chartjs-adapter-moment](https://npm.io/package/chartjs-adapter-moment.md) — 210.8K weekly downloads
- [strftime](https://npm.io/package/strftime.md) — 171.2K weekly downloads
- [vue-flatpickr-component](https://npm.io/package/vue-flatpickr-component.md) — 115.8K weekly downloads
- [timepicker](https://npm.io/package/timepicker.md) — 51.0K weekly downloads

## Recent versions

- 0.7.0 (latest) — 2019-10-17
- 0.6.0 — 2019-09-11
- 0.5.0 — 2019-09-11
- 0.4.0 — 2019-09-11
- 0.3.0 — 2019-09-11
- 0.2.0 — 2019-09-11
- 0.1.0 — 2019-09-10

## README

# Adonis Timezone Provider

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

[![Coverage Status](https://coveralls.io/repos/github/Rocketseat/adonis-timezone/badge.svg?branch=master)](https://coveralls.io/github/Rocketseat/adonis-timezone?branch=master)

## Install

`adonis install @rocketseat/adonis-timezone`

## Use

To use this provider you need to add a `trait` inside your `Model`, like this:

```js
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.

```js
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.

```js
class Timezone {
  async handle({ timezone, auth }, next) {
    timezone.activate(auth.user.timezone);
    await next();
  }
}
```

---
_Source: https://npm.io/package/@rocketseat/adonis-timezone · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
