Search code examples
ruby-on-railsubuntutimezonedstdokku

Rails isn't applying daylight saving time


My server's clock is set to London time (I'm currently living in the GMT+0 zone). The output of timedatectl status gives me this:

  Local time: Mon 2016-05-23 08:13:06 BST   Universal time: Mon 2016-05-23 07:13:06 UTC
    RTC time: Mon 2016-05-23 07:13:06
    Timezone: Europe/London (BST, +0100)
 NTP enabled: yes NTP synchronized: no  RTC in local TZ: no
  DST active: yes  Last DST change: DST began at
              Sun 2016-03-27 00:59:59 GMT
              Sun 2016-03-27 02:00:00 BST  Next DST change: DST ends (the clock jumps one hour backwards) at
              Sun 2016-10-30 01:59:59 BST
              Sun 2016-10-30 01:00:00 GMT

And in my application.rb file I set the timezone:

config.time_zone = 'London'

Locally, it works right:

Time.now.dst?
# true
Time.now.hour
# 8

But in production it doesn't seem that DST is on.

Time.now.dst?
# false
Time.now.hour
# 7

I am not sure if it's a Rails thing or a server misconfiguration, but for me it seems right.


Solution

  • If this application is running within a docker container, the timezone of the host server may not be applied to the containers. You can probably set the TZ environment variable to whatever timezone you'd like and ruby will pick it up.

    I highly recommend not using non-UTC timezone for your application/database, as it will almost certainly cause problems down the line.

    Full disclosure: I am one of the dokku maintainers.