Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/divineomega/dates-timezone-conversion-trait

⏳🗺 Automatically convert an Eloquent model's dates to and from the current user's timezone
https://github.com/divineomega/dates-timezone-conversion-trait

eloquent laravel timezone timezone-conversion trait

Last synced: 3 months ago
JSON representation

⏳🗺 Automatically convert an Eloquent model's dates to and from the current user's timezone

Awesome Lists containing this project

README

        

# ⏳🗺 Dates Timezone Conversion Trait

This package provides a trait that automatically converts an Eloquent
model's dates to and from the current user's timezone.

## Installation

Dates Timezone Conversion Trait can be easily installed using Composer.
Just run the following command from the root of your project.

```
composer require divineomega/dates-timezone-conversion-trait
```

If you have never used the Composer dependency manager before, head
to the [Composer website](https://getcomposer.org/) for more
information on how to get started.

## Usage

First, you must add a `timezone` field to your application's main `User`
model and populate it with an appropriate timezone. Please see this [list
of supported timezones](https://secure.php.net/manual/en/timezones.php).

Then, to benefit from this trait, simply `use` it within any Eloquent Model.
An example of a `User` model with the trait being used is shown below.

```php
last_logged_in_at`), the datetime
object will automatically be converted to the user's timezone.

* When writing to an attribute (e.g. `$user->last_logged_in_at`), the datetime
will automatically be converted to the Laravel application's timezone (as
defined in the `config/app.php` file).