|
| 1 | +from datetime import datetime, timedelta |
| 2 | + |
1 | 3 | import pytest |
2 | 4 |
|
3 | 5 | from . import _defs, tz_rendering, tz_utils, zones |
@@ -74,3 +76,80 @@ def test_aliases(tzname): |
74 | 76 | _, name, formatted = tz_utils.format_tz_by_name(tzname) |
75 | 77 | assert name == tzname |
76 | 78 | assert tzname in formatted |
| 79 | + |
| 80 | + |
| 81 | +def test_get_timezones_lists_vancouver(): |
| 82 | + # Given British Columbia has its own timezone from November 2026 |
| 83 | + vancouver_labels = [] |
| 84 | + |
| 85 | + # When the supported timezones are listed |
| 86 | + all_timezones = zones.get_timezones() |
| 87 | + |
| 88 | + # Then America/Vancouver is offered under its own name |
| 89 | + for offset_str, tzname, verbose_name in all_timezones: |
| 90 | + if tzname == "America/Vancouver": |
| 91 | + vancouver_labels.append(verbose_name) |
| 92 | + assert len(vancouver_labels) == 1 |
| 93 | + assert vancouver_labels[0].endswith(") Vancouver") |
| 94 | + |
| 95 | + |
| 96 | +def test_get_timezones_lists_edmonton(): |
| 97 | + # Given Alberta has its own timezone from November 2026 |
| 98 | + edmonton_labels = [] |
| 99 | + |
| 100 | + # When the supported timezones are listed |
| 101 | + all_timezones = zones.get_timezones() |
| 102 | + |
| 103 | + # Then America/Edmonton is offered under its own name |
| 104 | + for offset_str, tzname, verbose_name in all_timezones: |
| 105 | + if tzname == "America/Edmonton": |
| 106 | + edmonton_labels.append(verbose_name) |
| 107 | + assert len(edmonton_labels) == 1 |
| 108 | + assert edmonton_labels[0].endswith(") Edmonton") |
| 109 | + |
| 110 | + |
| 111 | +def test_get_timezones_lists_winnipeg(): |
| 112 | + # Given Manitoba has its own timezone from November 2026 |
| 113 | + winnipeg_labels = [] |
| 114 | + |
| 115 | + # When the supported timezones are listed |
| 116 | + all_timezones = zones.get_timezones() |
| 117 | + |
| 118 | + # Then America/Winnipeg is offered under its own name |
| 119 | + for offset_str, tzname, verbose_name in all_timezones: |
| 120 | + if tzname == "America/Winnipeg": |
| 121 | + winnipeg_labels.append(verbose_name) |
| 122 | + assert len(winnipeg_labels) == 1 |
| 123 | + assert winnipeg_labels[0].endswith(") Winnipeg") |
| 124 | + |
| 125 | + |
| 126 | +def test_get_timezones_offers_us_central_time_only_for_us_central(): |
| 127 | + # Given Manitoba no longer follows US Central time from November 2026 |
| 128 | + central_time_zone_names = [] |
| 129 | + |
| 130 | + # When the supported timezones are listed |
| 131 | + all_timezones = zones.get_timezones() |
| 132 | + |
| 133 | + # Then "Central Time (US & Canada)" is offered only for US/Central |
| 134 | + for offset_str, tzname, verbose_name in all_timezones: |
| 135 | + if verbose_name.endswith(") Central Time (US & Canada)"): |
| 136 | + central_time_zone_names.append(tzname) |
| 137 | + assert central_time_zone_names == ["US/Central"] |
| 138 | + |
| 139 | + |
| 140 | +def test_get_timezones_keeps_central_america_on_utc_minus_6(): |
| 141 | + # Given a date in December 2026, after Manitoba stops changing its clocks |
| 142 | + december_2026 = datetime(2026, 12, 1, 12, 0) |
| 143 | + central_america_zone_names = [] |
| 144 | + |
| 145 | + # When the supported timezones are listed |
| 146 | + all_timezones = zones.get_timezones() |
| 147 | + |
| 148 | + # Then "Central America" is offered once, on a zone that is at UTC-6 then |
| 149 | + for offset_str, tzname, verbose_name in all_timezones: |
| 150 | + if verbose_name.endswith(") Central America"): |
| 151 | + central_america_zone_names.append(tzname) |
| 152 | + assert len(central_america_zone_names) == 1 |
| 153 | + central_america_zone = tz_utils.get_timezone(central_america_zone_names[0]) |
| 154 | + assert central_america_zone is not None |
| 155 | + assert central_america_zone.utcoffset(december_2026) == timedelta(hours=-6) |
0 commit comments