Time.zone.now.all_* returns range in UTC #8807

Closed
agrobbin opened this Issue Jan 8, 2013 · 4 comments

Projects

None yet

2 participants

@agrobbin
agrobbin commented Jan 8, 2013

Time.zone.now (and Time.current) seem to be changing the time zone to UTC when running Time.zone.now.all_week or any of the other all_* methods. However, Time.now keeps it in the server's time zone (which in my case happens to be EST).

Time.now:

1.9.3p327 :001 > Time.now
 => 2013-01-07 22:19:18 -0500 
1.9.3p327 :002 > Time.now.all_week
 => 2013-01-07 00:00:00 -0500..2013-01-13 23:59:59 -0500 
1.9.3p327 :003 > Time.now.beginning_of_week
 => 2013-01-07 00:00:00 -0500 
1.9.3p327 :004 > Time.now.end_of_week
 => 2013-01-13 23:59:59 -0500 

Time.zone.now:

1.9.3p327 :005 > Time.zone.now
 => Mon, 07 Jan 2013 22:19:52 EST -05:00 
1.9.3p327 :006 > Time.zone.now.all_week
 => 2013-01-07 00:00:00 UTC..2013-01-13 23:59:59 UTC 
1.9.3p327 :007 > Time.zone.now.beginning_of_week
 => Mon, 07 Jan 2013 00:00:00 EST -05:00 
1.9.3p327 :008 > Time.zone.now.end_of_week
 => Sun, 13 Jan 2013 23:59:59 EST -05:00 

Time zone configuration:

1.9.3p327 :009 > Rails.configuration.time_zone
 => "Eastern Time (US & Canada)" 

Notice Line 6's output. It's range is in UTC, while the Time.zone.now output of Line 5 is in EST.

I'm on Rails 3.2.10 and Ruby 1.9.3 p327.

@pixeltrix
Member

This is a duplicate of #6179 and has already been fixed in master by e2e5136 but it should be okay to backport (I'm sure I'l regret saying that 😄).

@pixeltrix
Member

Fixed in d39d878

@pixeltrix pixeltrix closed this Jan 8, 2013
@carlosantoniodasilva carlosantoniodasilva pushed a commit to carlosantoniodasilva/rails that referenced this issue Jan 8, 2013
@nashby nashby Wrap time ranges with timezones, closes #8807
(cherry picked from commit e2e5136)
(cherry picked from commit dcdde7d)

Backport of #6183, original issue was #6179

Conflicts:
	activesupport/lib/active_support/core_ext/time/calculations.rb
	activesupport/test/core_ext/time_ext_test

Signed-off-by: Andrew White <andyw@pixeltrix.co.uk>
d39d878
@agrobbin
agrobbin commented Jan 8, 2013

Man I thought I had searched for the right keyword before posting this issue. Sorry about the duplication and thanks for backporting it!

@pixeltrix
Member

As always it turned out to be tricker than at first glance due to the lack of nsec in Ruby 1.8.7

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