Skip to content

Instantly share code, notes, and snippets.

@willglynn
Created October 4, 2012 04:12
Show Gist options
  • Save willglynn/3831426 to your computer and use it in GitHub Desktop.
Save willglynn/3831426 to your computer and use it in GitHub Desktop.
Rails time zones + Date.today + system time zone interaction
[1] pry(main)> [`date`, ENV['TZ'], Time.zone, Date.today.midnight, Date.yesterday.midnight]
=> ["Wed Oct 3 23:11:03 CDT 2012\n",
nil,
(GMT+00:00) UTC,
Wed, 03 Oct 2012 00:00:00 UTC +00:00,
Wed, 03 Oct 2012 00:00:00 UTC +00:00]
[2] pry(main)> ENV['TZ'] = 'UTC'
=> "UTC"
[3] pry(main)> [`date`, ENV['TZ'], Time.zone, Date.today.midnight, Date.yesterday.midnight]
=> ["Thu Oct 4 04:11:21 UTC 2012\n",
"UTC",
(GMT+00:00) UTC,
Thu, 04 Oct 2012 00:00:00 UTC +00:00,
Wed, 03 Oct 2012 00:00:00 UTC +00:00]
[4] pry(main)> ENV['TZ'] = Time.zone = 'US/Central'
=> "US/Central"
[5] pry(main)> [`date`, ENV['TZ'], Time.zone, Date.today.midnight, Date.yesterday.midnight]
=> ["Wed Oct 3 23:11:41 CDT 2012\n",
"US/Central",
(GMT-06:00) US/Central,
Wed, 03 Oct 2012 00:00:00 CDT -05:00,
Tue, 02 Oct 2012 00:00:00 CDT -05:00]
@willglynn
Copy link
Author

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