Skip to content

Commit 459c032

Browse files
authored
fix(oauth): parse ISO timestamps with negative UTC offsets
Signed-off-by: Sebastian Turner <sebastiant3484@gmail.com>
1 parent ab4e498 commit 459c032

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

‎slack_sdk/oauth/installation_store/internals.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44

55
def _from_iso_format_to_datetime(iso_datetime_str: str) -> datetime:
6-
if "+" not in iso_datetime_str:
7-
iso_datetime_str += "+00:00"
8-
return datetime.fromisoformat(iso_datetime_str)
6+
dt = datetime.fromisoformat(iso_datetime_str)
7+
if dt.tzinfo is None:
8+
dt = dt.replace(tzinfo=timezone.utc)
9+
return dt
910

1011

1112
def _from_iso_format_to_unix_timestamp(iso_datetime_str: str) -> float:

‎tests/slack_sdk/oauth/installation_store/test_internals.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ def test_iso_format(self):
2222
dt = _from_iso_format_to_datetime("2021-07-14 08:00:17")
2323
self.assertEqual(dt.timestamp(), 1626249617.0)
2424

25+
def test_iso_format_with_utc_offset(self):
26+
dt = _from_iso_format_to_datetime("2021-07-14 17:00:17+09:00")
27+
self.assertEqual(dt.timestamp(), 1626249617.0)
28+
dt = _from_iso_format_to_datetime("2021-07-14 03:00:17-05:00")
29+
self.assertEqual(dt.timestamp(), 1626249617.0)
30+
2531

2632
@pytest.mark.parametrize(
2733
"ts,target_type,expected_result",
@@ -30,6 +36,7 @@ def test_iso_format(self):
3036
(datetime(2023, 11, 28, 22, 9, 7, tzinfo=timezone.utc), int, 1701209347),
3137
("1701209605", int, 1701209605),
3238
("2023-11-28 22:11:19", int, 1701209479),
39+
("2023-11-28 17:11:19-05:00", int, 1701209479),
3340
(1701209998.3429494, float, 1701209998.3429494),
3441
(datetime(2023, 11, 28, 22, 20, 25, 262571, tzinfo=timezone.utc), float, 1701210025.262571),
3542
("1701210054.4672053", float, 1701210054.4672053),

0 commit comments

Comments
 (0)