Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improved parsing of timezone abbreviations #1103

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion arrow/arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

"""


import calendar
import re
import sys
Expand Down Expand Up @@ -1828,6 +1827,32 @@ def _get_datetime(
else:
raise ValueError(f"{expr!r} not recognized as a datetime or timestamp.")

@classmethod
def iana_timezone(cls, time_zone: str) -> str:
iana_time_zone_map = {
"ACDT": "Austrailian Central Daylight Time",
"ACST": "Australian Central Standard Time",
"ADT": "Atlantic Daylight Time",
"AEDT": "Australian Eastern Daylight Time",
"AEST": "Australian Eastern Standard Time",
"AHDT": "Alaska-Hawaii Daylight Time",
"AHST": "Alaska-Hawaii Standard Time",
"AKDT": "Alaska Daylight Time",
"AKST": "Alaska Standard Time",
"AMT": "Armenia Time",
"AST": "Atlantic Standard Time",
"AWDT": "Australian Western Daylight Time",
"AWST": "Australian Western Standard Time",
"AWT": "Australian Western Standard Time",
"BDST": "British Double Summer Time",
"BDT": "Brunei Time",
"BMT": "Biel Mean Time",
"BST": "British Summer Time",
}
if iana_time_zone_map.get(time_zone) == None:
raise ValueError(f"not a recognized iana timezone!")
return iana_time_zone_map[time_zone]

@classmethod
def _get_frames(cls, name: _T_FRAMES) -> Tuple[str, str, int]:
"""Finds relevant timeframe and steps for use in range and span methods.
Expand Down
22 changes: 22 additions & 0 deletions tests/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3080,6 +3080,28 @@ def test_value_error_exception(self):
target.span("week", week_start=55)


class TestIanaTimeZone:
def test_acdt(self):
sample_string = "Austrailian Central Daylight Time"
test_string = arrow.Arrow.iana_timezone("ACDT")
assert sample_string == test_string

def test_acst(self):
sample_string = "Australian Central Standard Time"
test_string = arrow.Arrow.iana_timezone("ACST")
assert sample_string == test_string

def test_adt(self):
sample_string = "Atlantic Daylight Time"
test_string = arrow.Arrow.iana_timezone("ADT")
assert sample_string == test_string

def test_aedt(self):
sample_string = "Australian Eastern Daylight Time"
test_string = arrow.Arrow.iana_timezone("AEDT")
assert sample_string == test_string


class TestArrowUtil:
def test_get_datetime(self):

Expand Down