laralabs/timezone

Laravel package for easy bi-directional conversion of DateTime into a variety of formats and locales

2.0.0 2020-10-13 22:26 UTC

This package is auto-updated.

Last update: 2024-04-14 06:52:40 UTC


README

68747470733a2f2f6173736574732e6c6172616c6162732e756b2f7061636b616765732f74696d657a6f6e652f74696d657a6f6e655f6c6f676f2e706e67

Stable Build Build Status StyleCI 68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f38313132633564313032366366346130313537302f6d61696e7461696e6162696c697479 68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f38313132633564313032366366346130313537302f746573745f636f766572616765

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

🚀 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.

📙 Documentation

Full documentation can be found on the docs website.

💬 Support

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

🔑 License

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