Rails' utc_to_local and daylight saving time

> e = Event.first
> e.registration_start_utc  #registration_start_utc is a datetime column
 => Sat, 23 Oct 2010 06:38:00 UTC +00:00 
> e.registration_start_utc.utc?
 => true 
> ActiveSupport::TimeZone.find_tzinfo("America/New_York").utc_to_local(e.registration_start_utc)
 => Sat, 23 Oct 2010 02:38:00 UTC +00:00

2 questions:

1) Why is this last output showing "UTC" - hour converted (6 => 2), but it still says UTC. Why not EST / EDT?

2) What happens after daylight saving, and the shift for New York is from -4 to -5? The value in the database does not change, so my only conclusion is that my application will start showing "1:38" everywhere instead of the correct 2:38?

I mainly deal with # 2. # 1 - it's rather a curiosity.

Thank!

+3
source share
1 answer

2) utc_to_localuses a date to determine which offset is correct, so the output will always be the same for a given date.

:

t = Time.utc(2011,3, 14, 12)
# => 2011-03-14 12:00:00 UTC
t2 = Time.utc(2011,3, 11, 12)
# => 2011-03-11 12:00:00 UTC
ActiveSupport::TimeZone.find_tzinfo("America/New_York").utc_to_local(t)
# => 2011-03-14 08:00:00 UTC
ActiveSupport::TimeZone.find_tzinfo("America/New_York").utc_to_local(t2)
# => 2011-03-14 07:00:00 UTC

1) . , , .. .

:

e.registration_start_utc.in_time_zone("Eastern Time (US & Canada)")

. ...

+1

Source: https://habr.com/ru/post/1771048/


All Articles