Reputation: 6367
I am using Rails 5 and my app's timezone is set to Brasilia.
Right now it's winter (no daylight saving) in Brazil so
Time.current.dst?
returns false
But in Brazil daylight savings starts at 21/10/2018, so when I do
(Time.current + 10.days).dst?
I expect it ti return true
, but it returns false
.
Is there a table where I can check what dates Rails considers for start end and of daylight savings in each timezone?
Or as another example. I understand that UTC does not have daylight savings. So
Time.current.strftime(%Z)
return -3
which is the correct diference between UTC and current Brazil time.
But when I do
(Time.current+10.days).strftime(%Z)
is still returns -3
but that date is after Brazil has changed time, so it should be -2
. Something seems to be wrong.
Upvotes: 4
Views: 458
Reputation: 241693
The TimeZone class serves as a wrapper around
TZInfo::Timezone
instances.
TZInfo::Timezone
instances are provided via the Ruby TZInfo gem. The data for TZInfo is provided in a separate TZInfo-Data package. Staying current with that will keep your time zone data accurate. This data is sourced from the IANA time zone database (TZDB), as it is with most other programming languages.
Note that it is generally preferable to use the IANA time zone identifiers with tzinfo gem directly, as Rails time zones are limited to "a meaningful subset of 134 zones" (per the same docs), but contain many duplications and omissions, and provide no criteria as to what "meaningful" means. More on this in the timezone tag wiki (near the end).
Also, Brazil starts DST on November 4th in 2018, not on October 21st. See here and here. This change was reflected in IANA TZDB 2018a, which was reflected in TZInfo-Data v1.2018.1. If you have that version or newer, then you have the newer, correct Brazil DST date, and thus explains your results.
There was recently a plan to push Brazil's DST date out even further to November 18th, but the government retracted that plan before it ever became official, and thus was never represented in the time zone data.
Upvotes: 6