Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Timezone Laravel Package

adlawson/timezone

Sets PHP’s default timezone to UTC when date.timezone isn’t configured, preventing DateTime “not safe to rely on system timezone” warnings. Auto-runs on include (side effect), intended for end-user apps/frameworks, not libraries.

View on GitHub
Deep Wiki
Context7

Timezone

Version: 1.0.0

Timezone fixes issues you may run into with PHP and it's date.timezone ini setting. This library should only be a dependency on end user applications and frameworks. It should not be a dependency on smaller libraries or plugins. It can be installed in whichever way you prefer, but I recommend Composer.

{
    "require": {
        "adlawson/timezone": "1.0.0"
    }
}

When should I consider using this library?

It is useful if you ever see this warning

Exception: DateTime::__construct(): It is not safe to rely on the system's timezone settings. You are *required* to use
the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are
still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now,
but please set date.timezone to select your timezone.

This library works by setting the default timezone to UTC if it isn't already set in php.ini. Unfortunately, it does so by ignoring PSR-1#2.3 and executes itself when the file is included.

Usage

If you installed this library with composer, all you need to do is include composer's autoloader.

<?php
require 'vendor/autoload.php';

Otherwise, you'll need to include the file in this library directly.

<?php
require '/path/to/adlawson/timezone/lib/timezone.php';

Notes

This is a fairly horrible but convenient way to cover up the timezone issue in PHP. It's by no means a silver bullet and should only be used if you're confident you know what it actually does.

When I wrote this, I had seen a very similar fix somewhere on github but I couldn't for the life of me find it again. If anybody knows which library I'm referring to, please send me a link. Thanks.

License

The content of this library is released under the MIT License by Andrew Lawson. You can find a copy of this license at http://www.opensource.org/licenses/mit or in LICENSE

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
adachsoft/changelog-linter
adachsoft/collection
payerurl/telegrambot-crypto-payment-instant-payout
dskripchenko/laravel-hybrid-search
riorizkyrainey/lara-ced
mehedimi/static-vel
zharp/zharp
nonsapiens/bigquery-model-sync
lgu-bayambang-ict-office/lgu-laravel-development-standards
andydefer/laravel-support
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel
draftsmaninc/draftsman
square-bit/laravel-volition
himito/laravel-mailman
htinlynn/genius-helper
maco-studios/hephaestus
adachsoft/php-code-style