This project is archived and is in readonly mode.

#2112 ✓wontfix
Jordan Brough

Time.now doesn't respect config.time_zone

Reported by Jordan Brough | March 2nd, 2009 @ 09:55 PM | in 2.x

I am located in MST timezone but want my Rails app to run in UTC. I've set config.time_zone = 'UTC' which seems to work except that Time.now remains in MST, which produces unexpected results. Should Time.now be using the modified timezone?


# config/environment.rb
config.time_zone = 'UTC'

# console
$ script/runner "puts (Time.now + 1.day).hour, 1.day.from_now.hour"
14
21
$ script/runner "puts (Time.now + 1.day).zone, 1.day.from_now.zone"
MST
UTC

Comments and changes to this ticket

  • Geoff Buesing

    Geoff Buesing March 2nd, 2009 @ 10:02 PM

    • State changed from “new” to “wontfix”

    This is correct behavior: Time.now is not affected by config.time_zone/Time.zone.

    To get the current time in Time.zone, use Time.zone.now.

  • Jordan Brough

    Jordan Brough March 2nd, 2009 @ 10:12 PM

    Thanks for the quick response. Is the reasoning for this documented anywhere? (I couldn't find it) Seems a bit unintuitive and verbose (not to mention error-prone when I forget the '.zone.').

  • Jordan Brough

    Jordan Brough March 2nd, 2009 @ 10:13 PM

    The unintuitive bit being that 1.day.from_now uses config.time_zone while Time.now + 1.day doesn't.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Tags

Pages