Skip to content
Closed
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
1 change: 1 addition & 0 deletions requirements_test.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
mock==4.0.3
pytest==6.2.5
pytest-sugar==0.9.5
3 changes: 3 additions & 0 deletions tests/test_tztrout.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class TestTZIdsForPhone:
[
('+1 (650) 333 4444', ['America/Los_Angeles']),
('+48 601 941 311', ['Europe/Warsaw']),
('+888569', []),
('+889989', [])
],
)
def test_ids_for_phone(self, phone, tz_ids):
Expand Down Expand Up @@ -231,6 +233,7 @@ class TestTZIdsForAddress:
@pytest.mark.parametrize(
'country, state, city, zipcode, expected_tz_ids, is_exact_match',
[
('XX', '', None, None, [], True),
('US', 'California', None, None, ['America/Los_Angeles'], True),
('US', 'CA', None, None, ['America/Los_Angeles'], True),
('US', 'CA', '', None, ['America/Los_Angeles'], True),
Expand Down
12 changes: 6 additions & 6 deletions tztrout/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,20 @@ def tz_ids_for_phone(phone, country='US'):
elif country_iso == 'CA':
area_code = str(phone.national_number)[:3]
state = td.ca_area_code_to_state.get(area_code)
return td.ca_state_to_tz_ids.get(state)
return td.ca_state_to_tz_ids.get(state, [])

elif country_iso == 'AU':
area_code = str(phone.national_number)[:2]
state = td.au_area_code_to_state.get(area_code)
state = td.au_area_code_to_state.get(area_code, [])

# Some Australian number prefixes (e.g. 04) are country-wide - fall
# back to all the AU tz ids
if state:
return td.au_state_to_tz_ids.get(state)
return pytz.country_timezones.get(country_iso)
return pytz.country_timezones.get(country_iso, [])

elif country_iso:
return pytz.country_timezones.get(country_iso)
return pytz.country_timezones.get(country_iso, [])

return []

Expand Down Expand Up @@ -160,9 +160,9 @@ def tz_ids_for_address(country, state=None, city=None, zipcode=None, **kwargs):
elif country == 'AU' and state:
if len(state) != 2:
state = td.normalized_states['AU'].get(state.lower(), state)
return td.au_state_to_tz_ids.get(state)
return td.au_state_to_tz_ids.get(state, [])

return pytz.country_timezones.get(country)
return pytz.country_timezones.get(country, [])


def tz_ids_for_offset(offset_in_minutes):
Expand Down