1

I'm using Lumen 5.6 and on my local server (I don't have a production server yet) and all my timestamps (created_at, updated_at) are being stored natively in my local timezone (Amsterdam, +02:00). I would like this to be in UTC. I have done a standard lumen install I thought UTC was the default?

I have tried the following .env settings

APP_TIMEZONE='+00:00' #This does nothing no matter what I set it to
DB_TIMEZONE='+02:00' #This gets me UTC by offsetting the offset

These two configurations fail with or without quotes

APP_TIMEZONE='UTC'
DB_TIMEZONE='UTC'

# OR

APP_TIMEZONE='Africa/Timbuktu'
DB_TIMEZONE='Africa/Timbuktu'

I have also tried to explicitly set the timestamp column like so

$password_reset = PasswordReset::create([
    'token' => Str::random(60),
    'email' => $request->input('email'),
    'created_at' => Carbon::now('UTC')->toDateTimeString()
  ]);

and the timestamps in my database are STILL offset by two hours. Highly frustrating. I am aware of all the Laravel fixes, none work. And it appears lumen 5.6 does not use an config/app.php like laravel, its all down to the .env file but nothing is working unless i "hack" the DB_TIMEZONE by "+02:00"

MrRed
  • 677
  • 1
  • 6
  • 21
  • didn't you try to change `'timezone' => 'Africa/Timbuktu'` in `config/app.php`? – Malkhazi Dartsmelidze May 25 '18 at 08:42
  • yeah i did but apparently lumen doesnt use that since 5.6 it just uses the .env file. But i yeah i tried that :/ – MrRed May 25 '18 at 08:43
  • 1
    This is weird, since the default lumen database drivers make a point of NOT adding timezones: https://github.com/laravel/lumen-framework/blob/5.6/config/database.php Maybe you could create your own `config/app.php` (since there is one: https://github.com/laravel/lumen-framework/blob/5.6/config/app.php ) and declare your timezone there as you would with laravel? Or maybe PHP is messing up, have you checked the default timezone in your php.ini? – Loek May 25 '18 at 08:43
  • unbelievably it doesnt work, even when adding $app->configure('app'); to the bootstrap/app.php as reccomended to get a custom config/app.php to work in lumen – MrRed May 25 '18 at 08:49
  • And what is the default timezone in your php.ini? Maybe that is messing up. https://stackoverflow.com/questions/16765158/date-it-is-not-safe-to-rely-on-the-systems-timezone-settings (Second answer can also be useful!) – Loek May 25 '18 at 08:52
  • php.ini is set to date.timezone = "UTC" – MrRed May 25 '18 at 08:59
  • 1
    Mind = blown. Very interested to see what the problem/answer is. – Loek May 25 '18 at 09:05
  • Did you install ntp on your server and set server timezone to utc? – train_fox May 25 '18 at 09:08
  • Hey train_fox, i haven't installed ntp. im using xampp on my local windows machine. looks like ntp is linux right? – MrRed May 25 '18 at 09:25
  • since lumen priorities the .env why not set it in the .env file? and then use the global env() function? –  May 25 '18 at 13:28
  • I have it set in the env file, its the two options i showed in my original post that doesnt work. ive created a brand new project with composer and lumen and the same problem . i just dont get it. Anyone here using lumen 5.6? – MrRed May 25 '18 at 18:09

0 Answers0