Skip to content
Merged
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
3 changes: 3 additions & 0 deletions src/hdx/utilities/dateparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,9 @@ def parse_date_range(
if timezone_handling == 0:
startdate = startdate.replace(tzinfo=UTC)
enddate = enddate.replace(tzinfo=UTC)
elif timezone_handling == 1:
startdate = startdate.replace(tzinfo=None)
enddate = enddate.replace(tzinfo=None)
elif timezone_handling == 3:
if startdate.tzinfo is None:
startdate = startdate.replace(tzinfo=UTC)
Expand Down
19 changes: 19 additions & 0 deletions tests/hdx/utilities/test_dateparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,25 @@ def test_parse_date(self):
with pytest.raises(ParserError):
parse_date("02/2013", "%m/%Y")

@pytest.mark.parametrize("date_format", [None, "%Y-%m-%d %H:%M:%S %z"])
def test_parse_date_ignore_numeric_timezone(self, date_format: str | None) -> None:
assert parse_date(
"2013-02-20 01:30:20 +0530",
date_format=date_format,
timezone_handling=1,
) == datetime(2013, 2, 20, 1, 30, 20)

@pytest.mark.parametrize("date_format", [None, "%Y-%m-%d %H:%M:%S %z"])
def test_parse_date_range_ignore_numeric_timezone(
self, date_format: str | None
) -> None:
expected = datetime(2013, 2, 20, 1, 30, 20)
assert parse_date_range(
"2013-02-20 01:30:20 +0530",
date_format=date_format,
timezone_handling=1,
) == (expected, expected)

def test_get_datetime_from_timestamp(self):
expected_timestamp = 1596180834.0
expected_date = datetime(2020, 7, 31, 7, 33, 54, tzinfo=UTC)
Expand Down