tighten/lambo

When upgrading the Lambo config, the comment setting the time in the old config doesn't respect my time zone

mattstauffer opened this issue ยท 5 comments

Instead it uses UTC.

image

@mattstauffer This seems to be a PHP and/or Laravel Zero issue.

In vendor/laravel-zero/foundation/src/Illuminate/Foundation/Bootstrap/LoadConfiguration.php It does the following:

date_default_timezone_set($config->get('app.timezone', 'UTC'));

If I set date.timezone = 'America/New_York in php.ini it is ignored as the above implies.

If I make the following changes to vendor/laravel-zero/foundation/src/Illuminate/Foundation/Bootstrap/LoadConfiguration.php then the php.ini value is honored.

date_default_timezone_set($config->get('app.timezone', date_default_timezone_get()));

If I set timezone in config/app.php to America/New_York it is honored.

TL;DR
I don't think this is solvable in a nice way. In my case, I don't really notice it as I live in UTC/GMT which PHP and Laravel Zero default to.

It seems weird to advise users to set timezone in config/app.php. I'm not sure it's correct for Laravel Zero to set the default timezone to something other than UTC.

Hm, I sort of think it might be ideal to set it to the current user's computer's time zone instead of UTC?

PHP doesn't let you do that. You have to manually set it in php.ini or at runtime. That's the issue.

Womp. OK.

I got annoyed by the Lambo time zone thing ๐Ÿคท๐Ÿป

After many hours of googling, and trying various fixes, apparently, PHP does have a solution. The following addition to config/app.php should sort it:

<?php
return [
    โ
    'timezone' => IntlTimeZone::createDefault()->getID(),
    โ
];

the only caveat is that ext-intl extension must be installed but I feel like most people have that?

The above solution works on all operating systems but if ext-intl is not installed then the following works on Mac OS:

<?php
return [
    โ
    'timezone' => exec('/bin/ls -l /etc/localtime|/usr/bin/cut -d"/" -f8-'),
    โ
];

and the following for Debian/Ubuntu distros:

<?php
return [
    โ
    'timezone' => exec('cat /etc/timezone'),
    โ
];