cms icon indicating copy to clipboard operation
cms copied to clipboard

Date field doesn't use APP_TIMEZONE

Open stephenmeehanuk opened this issue 1 year ago • 3 comments

Bug description

In my .env I've set APP_TIMEZONE=America/New_York

When I enable the timepicker, entries show my local time UK, not America/New_York

These two variables use the timezone from the .env

  • {{ now | format:"H:i:s" }}
  • {{ updated_at | format:"Y-m-d H:i:s"}}

But this variable uses my local (Valet) timezone

  • {{ date | format:"Y-m-d H:i:s"}}

Is this a bug? Or is there something else I need to configure to get {{ date | format:"Y-m-d H:i:s"}} to use APP_TIMEZONE ?

How to reproduce

  • Run the site locally
  • Add a timepicker to an entry blueprint
  • Set APP_TIMEZONE to a different timezone than the one you're in
  • Compare these variables
  • {{ now | format:"H:i:s" }}
  • {{ updated_at | format:"Y-m-d H:i:s"}}
  • {{ date | format:"Y-m-d H:i:s"}}
  • I would expect them to pull the date from APP_TIMEZONE but {{ date | format:"Y-m-d H:i:s"}} doesn't

Logs

No response

Environment

Environment
Application Name: Statamic
Laravel Version: 11.22.0
PHP Version: 8.3.8
Composer Version: 2.6.5
Environment: local
Debug Mode: OFF
URL: demo.test
Maintenance Mode: OFF
Timezone: America/New_York
Locale: en

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: redis
Database: sqlite
Logs: stack / single
Mail: log
Queue: redis
Session: file

Livewire
Livewire: v3.5.6

Statamic
Addons: 5
Sites: 1
Stache Watcher: Enabled
Static Caching: Disabled
Version: 5.24.0 PRO

Statamic Addons
jonassiewertsen/statamic-jobs: 1.5.0
jonassiewertsen/statamic-live-search: 2.1.1
jonassiewertsen/statamic-livewire: 3.6.0
statamic/collaboration: 1.0.0
visuellverstehen/statamic-anchor-navigation: 1.0.0

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

stephenmeehanuk avatar Oct 03 '24 09:10 stephenmeehanuk

In app.php it says date and date-time functions will use APP_TIMEZONE. But that's not what's happening.

/*
    |--------------------------------------------------------------------------
    | Application Timezone
    |--------------------------------------------------------------------------
    |
    | Here you may specify the default timezone for your application, which
    | will be used by the PHP date and date-time functions. The timezone
    | is set to "UTC" by default as it is suitable for most use cases.
    |
    */

    'timezone' => env('APP_TIMEZONE', 'UTC'),

stephenmeehanuk avatar Oct 04 '24 08:10 stephenmeehanuk

Hi, is this something that's likely to be fixed in the near future?

stephenmeehanuk avatar Oct 10 '24 15:10 stephenmeehanuk

Unfortunatley, I don't think it'll be addressed in the near future.

We have quite a few timezone-related issues open, but they aren't easy to fix because they would require changes to existing data.

But this variable uses my local (Valet) timezone {{ date | format:"Y-m-d H:i:s"}}

When you push the site to a server, if you configure the server's timezone to also be American/New York, it should output correctly.

duncanmcclean avatar Oct 10 '24 16:10 duncanmcclean

Going to close this as we've just merged https://github.com/statamic/cms/pull/11409, which makes a bunch of timezone-related improvements. It'll be released as part of Statamic 6.

duncanmcclean avatar Mar 11 '25 15:03 duncanmcclean