timezone: Correct common_timezones dictionary.
The changes are as follows:
• Fix one day offset in all western zones.
• Correct CST from -64800 to -21600 and CDT from -68400 to -18000.
• Disambiguate PST in favor of -28000 over +28000.
• Add GMT, UTC, WET, previously excluded for being at offset 0.
• Add ACDT, AEDT, AKST, MET, MSK, NST, NZDT, PKT, which the previous
code did not find.
• Remove numbered abbreviations -12, …, +14, which are unnecessary.
• Remove MSD and PKST, which are no longer used.
Hardcode the dict and verify it with a test, so that future
discrepancies won’t go silently unnoticed.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-01-27 22:12:36 +01:00
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
import pytz
|
|
|
|
from django.utils.timezone import now as timezone_now
|
|
|
|
|
2020-10-27 01:41:00 +01:00
|
|
|
from zerver.lib.test_classes import ZulipTestCase
|
timezone: Correct common_timezones dictionary.
The changes are as follows:
• Fix one day offset in all western zones.
• Correct CST from -64800 to -21600 and CDT from -68400 to -18000.
• Disambiguate PST in favor of -28000 over +28000.
• Add GMT, UTC, WET, previously excluded for being at offset 0.
• Add ACDT, AEDT, AKST, MET, MSK, NST, NZDT, PKT, which the previous
code did not find.
• Remove numbered abbreviations -12, …, +14, which are unnecessary.
• Remove MSD and PKST, which are no longer used.
Hardcode the dict and verify it with a test, so that future
discrepancies won’t go silently unnoticed.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-01-27 22:12:36 +01:00
|
|
|
from zerver.lib.timezone import canonicalize_timezone, common_timezones
|
2020-10-27 01:41:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TimeZoneTest(ZulipTestCase):
|
|
|
|
def test_canonicalize_timezone(self) -> None:
|
|
|
|
self.assertEqual(canonicalize_timezone("America/Los_Angeles"), "America/Los_Angeles")
|
|
|
|
self.assertEqual(canonicalize_timezone("US/Pacific"), "America/Los_Angeles")
|
|
|
|
self.assertEqual(canonicalize_timezone("Gondor/Minas_Tirith"), "Gondor/Minas_Tirith")
|
timezone: Correct common_timezones dictionary.
The changes are as follows:
• Fix one day offset in all western zones.
• Correct CST from -64800 to -21600 and CDT from -68400 to -18000.
• Disambiguate PST in favor of -28000 over +28000.
• Add GMT, UTC, WET, previously excluded for being at offset 0.
• Add ACDT, AEDT, AKST, MET, MSK, NST, NZDT, PKT, which the previous
code did not find.
• Remove numbered abbreviations -12, …, +14, which are unnecessary.
• Remove MSD and PKST, which are no longer used.
Hardcode the dict and verify it with a test, so that future
discrepancies won’t go silently unnoticed.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-01-27 22:12:36 +01:00
|
|
|
|
|
|
|
def test_common_timezones(self) -> None:
|
|
|
|
ambiguous_abbrevs = [
|
2021-12-23 07:00:12 +01:00
|
|
|
("CDT", -18000.0), # Central Daylight Time
|
|
|
|
("CDT", -14400.0), # Cuba Daylight Time
|
|
|
|
("CST", -21600.0), # Central Standard Time
|
|
|
|
("CST", +28800.0), # China Standard Time
|
|
|
|
("CST", -18000.0), # Cuba Standard Time
|
|
|
|
("PST", -28800.0), # Pacific Standard Time
|
2022-02-08 00:13:33 +01:00
|
|
|
("PST", +28800.0), # Philippine Standard Time
|
2021-12-23 07:00:12 +01:00
|
|
|
("IST", +19800.0), # India Standard Time
|
|
|
|
("IST", +7200.0), # Israel Standard Time
|
|
|
|
("IST", +3600.0), # Ireland Standard Time
|
timezone: Correct common_timezones dictionary.
The changes are as follows:
• Fix one day offset in all western zones.
• Correct CST from -64800 to -21600 and CDT from -68400 to -18000.
• Disambiguate PST in favor of -28000 over +28000.
• Add GMT, UTC, WET, previously excluded for being at offset 0.
• Add ACDT, AEDT, AKST, MET, MSK, NST, NZDT, PKT, which the previous
code did not find.
• Remove numbered abbreviations -12, …, +14, which are unnecessary.
• Remove MSD and PKST, which are no longer used.
Hardcode the dict and verify it with a test, so that future
discrepancies won’t go silently unnoticed.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-01-27 22:12:36 +01:00
|
|
|
]
|
2021-02-12 08:19:30 +01:00
|
|
|
missing = set(dict(reversed(ambiguous_abbrevs)).items()) - set(common_timezones.items())
|
timezone: Correct common_timezones dictionary.
The changes are as follows:
• Fix one day offset in all western zones.
• Correct CST from -64800 to -21600 and CDT from -68400 to -18000.
• Disambiguate PST in favor of -28000 over +28000.
• Add GMT, UTC, WET, previously excluded for being at offset 0.
• Add ACDT, AEDT, AKST, MET, MSK, NST, NZDT, PKT, which the previous
code did not find.
• Remove numbered abbreviations -12, …, +14, which are unnecessary.
• Remove MSD and PKST, which are no longer used.
Hardcode the dict and verify it with a test, so that future
discrepancies won’t go silently unnoticed.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-01-27 22:12:36 +01:00
|
|
|
assert not missing, missing
|
|
|
|
|
|
|
|
now = timezone_now()
|
|
|
|
dates = [datetime(now.year, 6, 21), datetime(now.year, 12, 21)]
|
|
|
|
extra = {*common_timezones.items(), *ambiguous_abbrevs}
|
|
|
|
for name in pytz.all_timezones:
|
|
|
|
tz = pytz.timezone(name)
|
|
|
|
for date in dates:
|
|
|
|
abbrev = tz.tzname(date)
|
|
|
|
if abbrev.startswith(("-", "+")):
|
|
|
|
continue
|
|
|
|
delta = tz.utcoffset(date)
|
|
|
|
assert delta is not None
|
|
|
|
offset = delta.total_seconds()
|
|
|
|
assert (
|
2021-02-12 08:19:30 +01:00
|
|
|
common_timezones[abbrev] == offset or (abbrev, offset) in ambiguous_abbrevs
|
timezone: Correct common_timezones dictionary.
The changes are as follows:
• Fix one day offset in all western zones.
• Correct CST from -64800 to -21600 and CDT from -68400 to -18000.
• Disambiguate PST in favor of -28000 over +28000.
• Add GMT, UTC, WET, previously excluded for being at offset 0.
• Add ACDT, AEDT, AKST, MET, MSK, NST, NZDT, PKT, which the previous
code did not find.
• Remove numbered abbreviations -12, …, +14, which are unnecessary.
• Remove MSD and PKST, which are no longer used.
Hardcode the dict and verify it with a test, so that future
discrepancies won’t go silently unnoticed.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-01-27 22:12:36 +01:00
|
|
|
), (name, abbrev, offset)
|
|
|
|
extra.discard((abbrev, offset))
|
|
|
|
assert not extra, extra
|