Daylight saving not being considered #35

Closed
brauliobo opened this Issue Jan 13, 2015 · 2 comments

Comments

Projects
None yet
2 participants
@brauliobo

On the system (ubuntu 14.10) I get:

~/P/n/blogoosfero git:blogoosfero ❯❯❯ TZ='America/Bahia' date                                                                                                                          
Ter Jan 13 13:38:27 BRT 2015
~/P/n/blogoosfero git:blogoosfero ❯❯❯ TZ='America/Sao_Paulo' date                                                                                                                       
Ter Jan 13 14:38:32 BRST 2015

And on Rails console I get:

irb(main):002:0> Time.zone = 'America/Bahia'
=> "America/Bahia"
irb(main):003:0> Time.zone.formatted_offset
=> "-03:00"
irb(main):004:0> Time.zone = 'America/Sao_Paulo'
=> "America/Sao_Paulo"
irb(main):005:0> Time.zone.formatted_offset
=> "-03:00"

I'm using rails 3.2.21 and tzinfo 0.3.42 (as required by activerecord 3.2.21)

@philr

This comment has been minimized.

Show comment
Hide comment
@philr

philr Jan 13, 2015

Member

According to the Rails source code, the ActiveSupport::TimeZone#formatted_offset method returns the difference between UTC and the standard time for the zone. It will not take daylight savings time into account.

If you want to find the current offset, you can use the ActiveSupport::TimeWithZone#formatted_offset method instead:

  > Time.zone = 'America/Bahia'
 => "America/Bahia" 
  > Time.zone.now.formatted_offset
 => "-03:00" 
  > Time.zone = 'America/Sao_Paulo'
 => "America/Sao_Paulo" 
  > Time.zone.now.formatted_offset
 => "-02:00" 
Member

philr commented Jan 13, 2015

According to the Rails source code, the ActiveSupport::TimeZone#formatted_offset method returns the difference between UTC and the standard time for the zone. It will not take daylight savings time into account.

If you want to find the current offset, you can use the ActiveSupport::TimeWithZone#formatted_offset method instead:

  > Time.zone = 'America/Bahia'
 => "America/Bahia" 
  > Time.zone.now.formatted_offset
 => "-03:00" 
  > Time.zone = 'America/Sao_Paulo'
 => "America/Sao_Paulo" 
  > Time.zone.now.formatted_offset
 => "-02:00" 

@philr philr added the invalid label Jan 13, 2015

@philr philr closed this Jan 13, 2015

@brauliobo

This comment has been minimized.

Show comment
Hide comment

thanks @philr !

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