New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

laralabs/timezone

Laravel package for easy bi-directional conversion of DateTime into a variety of formats and locales
2,335
Install
composer require laralabs/timezone
Latest Version:2.0.0
PHP:^7.3
Laravel:5 – 8
License:MIT
Last Updated:Oct 13, 2020
Links: GitHub  ·  Packagist
Maintainer: Laralabs

Stable Build Build Status StyleCI

The timezone package for Laravel provides an easy bi-directional conversion of DateTime into a variety of formats and locales.

:rocket: Quick Start

Installation

Require the package in the composer.json of your project.

composer require laralabs/timezone

Publish the configuration file.

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

Edit the configuration file and set your desired default display timezone and format.

Usage

A helper function and facade is available, choose your preferred method. For the following examples the default timezone will be Europe/London and d/m/Y H:i:s as the default format.

Converting from storage

$date = '2018-09-11 11:00:00';
$result = timezone()->fromStorage($date);
$result->formatToDefault();

Output: 11/09/2018 12:00:00

Converting to storage

$date = '11/09/2018 12:00:00';
$result = timezone()->toStorage($date);

Output: 2018-09-11 11:00:00

The package will check for a timezone key in the session before defaulting to the configuration value, alternatively it is possible to override the timezone with a second argument.

Overriding timezone

$toTimezone = 'Europe/London';
timezone()->fromStorage($date, $toTimezone);

$fromTimezone = 'Europe/London';
timezone()->toStorage($date, $fromTimezone);

Model Presenter

The package also comes with a presenter that can be added to models as a trait, for more information on this see the full documentation available below.

:orange_book: Documentation

Full documentation can be found on the docs website.

:speech_balloon: Support

Please raise an issue on GitHub if there is a problem.

:key: License

This is open-sourced software licensed under the MIT License.

Related Packages

camroncade/timezone

Helps manage timezones in Laravel. Includes <select> form builder for timezones.

1,103,308 159
jamesmills/laravel-timezone

Timezone storage and retrieval for Laravel

856,379 694
glhd/laravel-timezone-mapper

Timezone mapper for Laravel

474,200 47
nirajp/timezone

Helps manage timezones in Laravel. Includes <select> form builder for timezones....

22,311 0
thinktomorrow/locale

A Laravel package for route and domain based localization

8,405 2

Version History

Version Released PHP Laravel License
2.0.0 ^7.3 ^5.5|^6.0|^7.0|^8.0 MIT
1.0.4 >=7.1 ^5.5|^6.0|^7.0 MIT
1.0.2 >=7.1 ^5.5|^6.0 MIT
1.0.1 >=7.1 ^5.5 MIT
1.0.0 >=7.1 ^5.5 MIT