PHPackages                             divineomega/dates-timezone-conversion-trait - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. divineomega/dates-timezone-conversion-trait

Abandoned → [jord-jd/dates-timezone-conversion-trait](/?search=jord-jd%2Fdates-timezone-conversion-trait)Library[Database &amp; ORM](/categories/database)

divineomega/dates-timezone-conversion-trait
===========================================

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

v3.0.0(6mo ago)20271LGPL-3.0-onlyPHPCI passing

Since Oct 10Pushed 4w agoCompare

[ Source](https://github.com/Jord-JD/dates-timezone-conversion-trait)[ Packagist](https://packagist.org/packages/divineomega/dates-timezone-conversion-trait)[ GitHub Sponsors](https://github.com/DivineOmega)[ RSS](/packages/divineomega-dates-timezone-conversion-trait/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (7)Dependencies (2)Versions (7)Used By (0)

⏳🗺 Dates Timezone Conversion Trait
==================================

[](#-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.

Supports Laravel 5.1 through 13 without raising the original PHP 5.5.9 minimum. Nullable dates pass through unchanged, modern date/datetime casts are recognised, and returned Carbon values are copied before timezone conversion so reading an attribute does not mutate Eloquent's underlying date object.

Installation
------------

[](#installation)

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

```
composer require jord-jd/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
-----

[](#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.

```
