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.
date.timezone unset) that can disrupt production environments, especially in shared hosting or CI/CD pipelines.date.timezone behavior changes, strict typing).config/app.php already sets timezone by default, and the framework enforces it via DateTime facade. This package may be redundant unless legacy code or shared hosting constraints exist.AppServiceProvider::boot()) or Framework Kernel already handle timezone initialization. This package could clash with Laravel’s built-in logic.index.php or a custom bootstrap/app.php wrapper), risking order-of-initialization issues.php.ini cannot be modified (e.g., Heroku, shared hosting).if (!defined('LARAVEL_STARTED') && !ini_get('date.timezone')) {
require __DIR__.'/vendor/adlawson/timezone/lib/timezone.php';
}
date.timezone behavior.config(['app.timezone' => 'UTC']) or a custom solution.php.ini cannot be modified?timezone config not suffice (e.g., APP_TIMEZONE=UTC in .env)?DateTime facade or Carbon library (which may override timezone settings)?// app/Providers/AppServiceProvider.php
public function boot(): void {
if (!ini_get('date.timezone')) {
date_default_timezone_set(config('app.timezone', 'UTC'));
}
}
.env (APP_TIMEZONE=UTC)config/app.php ('timezone' => 'UTC')DateTime facade (extends Carbon, which respects Laravel’s config).date.timezone deprecation warnings and strict typing.DateTime/Carbon usages in the codebase to confirm no timezone assumptions exist.ini_get('date.timezone') is already handled elsewhere (e.g., Laravel’s bootstrap).// bootstrap/app.php (before Laravel loads)
if (!ini_get('date.timezone')) {
date_default_timezone_set(config('app.timezone', 'UTC'));
}
composer.json:
"require": {
"adlawson/timezone": "^1.0.0"
}
public/index.php):
require __DIR__.'/../vendor/autoload.php';
require __DIR__.'/../vendor/adlawson/timezone/lib/timezone.php';
// app/Helpers/TimezoneHelper.php
if (!ini_get('date.timezone') && !app()->runningInConsole()) {
date_default_timezone_set('UTC');
}
now(), Carbon::now(), and DateTime objects behave consistently.date_default_timezone_get() or similar, which could trigger warnings in PHP 8.1+.DateTime instantiation or Laravel’s bootstrap.public/index.php or a custom bootstrap/app.php wrapper.1. Load package (sets UTC if missing).
2. Laravel bootstrap (respects existing timezone).
3. Application logic (uses consistent timezone).
date.timezone unset in php.ini.APP_TIMEZONE set in .env.now() methods.php.ini).APP_TIMEZONE already handles this.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| PHP 8.1+ deprecation warnings | Runtime errors or E_DEPRECATED | Replace with Laravel-native logic |
| Conflict with Laravel’s timezone | Inconsistent DateTime behavior |
Load package before Laravel bootstrap |
| Package stops working silently | Undetected timezone issues | Add health checks (e.g., log ` |
How can I help you explore Laravel packages today?