unlock unlimited code runs for $79, limited time →
NOSSLETTER.techLIVE
back to OSSpedia
rails/rails
junior6/10
backwards-compatibilityconfiguration-managementapi-design

Add Pacific Time (Canada) and Alberta Time zone mappings

Project: rails/rails | Language: Ruby | Concepts: backwards-compatibility, configuration-management, api-design | Difficulty: junior
Link: https://github.com/rails/rails/pull/58321

The problem

British Columbia and Alberta in Canada have adopted new timekeeping rules and no longer share winter clocks with US Pacific and Mountain time. The existing Rails time zone mappings (Pacific Time (US & Canada) and Mountain Time (US & Canada)) still point to US-based IANA zones, which causes apps to show the wrong time (off by one hour in winter) for users in BC and Alberta.

Why it's non-trivial

A naive fix would be to change the existing mappings to point to the new Canadian zones. However, this would break backwards compatibility for any applications or users relying on the old US-based mappings. The fix needs to add new, more accurate mappings without disrupting existing behavior, and also ensure the new zones are discoverable and tested.

The approach

1. Add new mappings to the time zone map:

       "Pacific Time (US & Canada)"   => "America/Los_Angeles",
+      "Pacific Time (Canada)"        => "America/Vancouver",
  • Adds a new mapping for "Pacific Time (Canada)" to the IANA zone "America/Vancouver" (British Columbia).
       "Mountain Time (US & Canada)"  => "America/Denver",
+      "Alberta"                      => "America/Edmonton",
  • Adds a new mapping for "Alberta" to the IANA zone "America/Edmonton".

2. Update documentation and changelog:

+*   Add `Pacific Time (Canada)` and `Alberta` to `ActiveSupport::TimeZone::MAPPING`.
+    ...
+    *Said Kaldybaev*
  • Documents the addition and clarifies that existing mappings remain for compatibility.

3. Add/Update tests to ensure correct behavior:

  def test_pacific_time_canada_and_alberta_mappings
    pacific_canada = ActiveSupport::TimeZone["Pacific Time (Canada)"]
    alberta = ActiveSupport::TimeZone["Alberta"]
    pacific_us = ActiveSupport::TimeZone["Pacific Time (US & Canada)"]
    mountain_us = ActiveSupport::TimeZone["Mountain Time (US & Canada)"]

    assert_equal "America/Vancouver", pacific_canada.standard_name
    assert_equal "America/Edmonton", alberta.standard_name
    assert_equal "America/Los_Angeles", pacific_us.standard_name
    assert_equal "America/Denver", mountain_us.standard_name

    assert_equal "America/Vancouver", pacific_canada.tzinfo.name
    assert_equal "America/Edmonton", alberta.tzinfo.name
  end
  • Confirms the new mappings resolve to the correct IANA zones, and that the old ones are unchanged.
  def test_country_zones_include_pacific_time_canada_and_alberta
    ca_zones = ActiveSupport::TimeZone.country_zones(:ca)

    assert_includes ca_zones, ActiveSupport::TimeZone["Pacific Time (Canada)"]
    assert_includes ca_zones, ActiveSupport::TimeZone["Alberta"]
    assert_not_includes ca_zones.map(&:name), "America/Vancouver"
    assert_not_includes ca_zones.map(&:name), "America/Edmonton"
  end
  • Ensures the new friendly names are included in the list of Canadian zones, and the raw IANA names are not directly exposed.

From the review thread

adamhollett: Thanks for taking this on. This may have been missing from my reporting of the issue but I don't think mapping Mountain Time to Edmonton is correct. Alberta's new time zone is being referred to as "Alberta Time" (which covers Edmonton). I don't believe this name has been recognized or added in to TZInfo yet. It might be more correct to map Mountain Time to America/Yellowknife.

Saidbek: @adamhollett Thanks for the note, and for the map.

Agreed Alberta is no longer ordinary Mountain Time - year-round UTC-6, branded Alberta Time (green band on that map, with Sask).

The IANA target was fine though: tzdb 2026c put permanent -06 under America/Edmonton, and there’s no separate Alberta Time id. America/Yellowknife is just a Link to America/Edmonton in tzdb’s backward file, so it wouldn’t behave differently.

I’ve renamed Mountain Time (Canada) to Alberta Time.

jstanley0: It's odd to see "Alberta Time" surrounded by "Hawaii", "Mazatlan", etc. Should it just be "Alberta"?

guilleiguaran: @Saidbek, Agree with @jstanley0; other places covered have longer names ("Alaska Standard Time", "Hawaii Standard Time") but are abbreviated; let's do the same for Alberta.

Takeaways

  • When updating configuration mappings, preserve existing keys for backwards compatibility and add new ones for new requirements.
  • Use regionally accurate, user-friendly names for time zones or similar settings, but always map them to canonical identifiers (like IANA tzdb names) to ensure correct behavior.
  • Add or update tests to cover both the new mappings and the continued correctness of old ones, especially when dealing with user-facing configuration changes.