PHPackages                             gnireeg/laravel-timezoned - 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. gnireeg/laravel-timezoned

ActiveLibrary[Database &amp; ORM](/categories/database)

gnireeg/laravel-timezoned
=========================

A lightweight Laravel package that provides a trait to automatically convert all date attributes of an Eloquent model from the database timezone to the user's timezone - and convert incoming user-provided dates back to the database timezone as well.

1.0.0(7mo ago)04MITPHPPHP &gt;=8.1CI passing

Since Nov 23Pushed 7mo agoCompare

[ Source](https://github.com/gnireeG/laravel-timezoned)[ Packagist](https://packagist.org/packages/gnireeg/laravel-timezoned)[ RSS](/packages/gnireeg-laravel-timezoned/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (5)Versions (2)Used By (0)

Laravel Timezoned
=================

[](#laravel-timezoned)

A lightweight Laravel package that automatically converts Eloquent model date attributes between the database timezone and the user's timezone.

- **DB → User timezone** when reading attributes
- **User → DB timezone** when writing attributes

This ensures consistent and intuitive date handling across different user timezones.

---

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

[](#installation)

```
composer require gnireeg/laravel-timezoned
```

Optionally publish the config:

```
php artisan vendor:publish --tag=config
```

---

Usage
-----

[](#usage)

```
use Gnireeg\LaravelTimezoned\HasTimezoneConversion;

class Event extends Model
{
    use HasTimezoneConversion;

    protected array $timezonedAttributes = ['starts_at', 'ends_at'];
}
```

### Reading Attributes

[](#reading-attributes)

```
// Automatically converted to user's timezone
$event->starts_at; // Returns Carbon in user's timezone
```

### Writing Attributes

[](#writing-attributes)

```
// Automatically converted to database timezone
$event->starts_at = '2025-03-10 15:00';
$event->save();
```

### Raw Attribute Access

[](#raw-attribute-access)

```
// Get the value in database timezone (bypass conversion)
$event->getRawAttribute('starts_at');
```

---

Configuration
-------------

[](#configuration)

The package config (`config/timezoned.php`) has two options:

### Timezone Resolver

[](#timezone-resolver)

Determines the user's timezone. Receives the model instance as a parameter.

```
// Default: uses authenticated user's timezone
'timezone_resolver' => function ($model) {
    return auth()->user()?->timezone ?? 'UTC';
},

// Or use session
'timezone_resolver' => fn() => session('timezone', 'UTC'),

// Or request header
'timezone_resolver' => fn() => request()->header('X-Timezone', 'UTC'),
```

### Database Timezone

[](#database-timezone)

The timezone your database stores dates in. Set to `null` to use `config('app.timezone')`.

```
'database_timezone' => null, // Uses app.timezone
'database_timezone' => 'UTC', // Explicit UTC
```

---

How It Works
------------

[](#how-it-works)

The trait overrides two Eloquent methods:

- `getAttribute()` - converts dates from database timezone to user's timezone
- `setAttribute()` - converts dates from user's timezone to database timezone

Both `Carbon` and `CarbonImmutable` instances are supported.

---

Requirements
------------

[](#requirements)

- PHP &gt;= 8.1
- Laravel 10, 11, or 12
- Carbon &gt;= 2

---

Testing
-------

[](#testing)

```
composer test
```

---

License
-------

[](#license)

MIT

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance63

Regular maintenance activity

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

224d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/48487313?v=4)[gnireeG](/maintainers/gnireeG)[@gnireeG](https://github.com/gnireeG)

---

Top Contributors

[![gnireeG](https://avatars.githubusercontent.com/u/48487313?v=4)](https://github.com/gnireeG "gnireeG (5 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/gnireeg-laravel-timezoned/health.svg)

```
[![Health](https://phpackages.com/badges/gnireeg-laravel-timezoned/health.svg)](https://phpackages.com/packages/gnireeg-laravel-timezoned)
```

###  Alternatives

[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.6k29.9M147](/packages/laravel-cashier)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M25](/packages/yajra-laravel-oci8)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.5M2](/packages/glushkovds-phpclickhouse-laravel)[api-platform/laravel

API Platform support for Laravel

58171.6k14](/packages/api-platform-laravel)[alajusticia/laravel-expirable

Make Eloquent models expirable

21106.3k6](/packages/alajusticia-laravel-expirable)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
