Skip to content

Instantly share code, notes, and snippets.

@jamesmartin
Last active November 6, 2020 06:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesmartin/a648b6ca27017c7d888b to your computer and use it in GitHub Desktop.
Save jamesmartin/a648b6ca27017c7d888b to your computer and use it in GitHub Desktop.
Timezone Problems with Timecop and Circle CI
# System time zone is set to 'Australia/Sydney'
#
Time.zone = "Europe/Madrid"
=> "Europe/Madrid"
Timecop.freeze(Time.zone.now)
=> 2015-02-06 23:36:46 +1100 # The "frozen" time. +1100 is Australia/Sydney. Oh dear.
Time.zone.now
=> Fri, 06 Feb 2015 13:36:46 CET +01:00 # The time here is for the configured Time.zone; Europe/Madrid +01:00
@jamesmartin
Copy link
Author

jamesmartin commented Feb 6, 2015

The problem:
Tests that freeze time with Timecop pass locally, but fail on Circle CI.
When Timecop freezes time, it uses the system timezone, rather than the ActiveSupport::TimeZone configuration (in Rails).

The solution:
Configure Circle CI test machines and Rails to use the same Timezone:

# config/application.rb
config.time_zone = 'Australia/Sydney'
# circle.yml
machine:
  timezone:
    Australia/Sydney

@kirillplatonov
Copy link

Typo in circle.yml. Should be:

# circle.yml
machine:
  timezone:
    Europe/Moscow

@prakashmurthy
Copy link

👍 Just ran into the same issue!

@hmaack
Copy link

hmaack commented Dec 11, 2015

👍

@Epigene
Copy link

Epigene commented May 9, 2016

A cleaner version:

machine:
  timezone: 'Australia/Sydney'

@temirov
Copy link

temirov commented Mar 27, 2018

And if anyone needs it for CircleCI v 2:

  environment:
      TZ: /usr/share/zoneinfo/America/Los_Angeles

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment