Code Monkey home page Code Monkey logo

adonis-timezone's Introduction

Adonis Timezone Provider

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

Coverage Status

Install

adonis install @rocketseat/adonis-timezone

Include adonis-timezone provider into providers list

Insert provider reference: @rocketseat/adonis-timezone/providers/TimezoneProvider into providers list.

file path: start/app.js

const providers = [   
  ...    
  '@rocketseat/adonis-timezone/providers/TimezoneProvider',  
  
];

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

adonis-timezone's People

Contributors

higoribeiro avatar jpdemagalhaes avatar marcuspianco avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

adonis-timezone's Issues

Implementation

Do I need to call middleware somewhere? The implementation here does not work.

Error with nested relationships

Hi, this library don't work with nested relationships like:

const user = await User.query() .where('id', params.id) .with('image') .fetch()

Any suggest?

Error: Cannot find module 'Timezone/Trait' && Cannot read property 'activate' of undefined

Issue description:
After install adonis-timezone using the process describe in readme.md the lib does not find the module Timezone/Trait in the first request, after of try again(another request) the error is: Cannot read property 'activate' of undefined. The problem is that the provider is not listed in start/app.js -> providers[]. I did a investigation and see that in documentation don't appear the inclusion of these provider, and these erros occurred.

Fix proposal:

Add the inclusion of provider in providers list in start/app.js file, I fixed the erros with this process.

Cannot save timezone created_at and updated_at

Eg.
created_at and updated_at from this package is "2020-01-07 17:09:07"
Timezone set to Asia/Jakarta

My vps machine use America/New_York timezone, and of course MySql will use this as the timezone

so whenever I save my record to database, it will automatically change to America/New_York not my current settings with this package Asia/Jakarta

so the example given in above, database will save it to
created_at = "2020-01-07 05:09:07"
updated_at = "2020-01-07 05:09:07"

any step that i'm missing ? please some advice

thanks in advance

ps : I know I can change my vps timezone, but I avoid this way since in my database already has too much record

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.