From c821ab999b242efbf69ee8e1bc8a20b050f9faea Mon Sep 17 00:00:00 2001 From: Sandra Snan Date: Sun, 24 Sep 2023 00:35:39 +0200 Subject: [PATCH 1/3] Fix crash on weird date time Solution found by danschwarz --- toot/entities.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toot/entities.py b/toot/entities.py index 739b9623..51250744 100644 --- a/toot/entities.py +++ b/toot/entities.py @@ -394,7 +394,7 @@ def _convert(field_type, value): return datetime.strptime(value, "%Y-%m-%dT%H:%M:%S.%f%z") if field_type == date: - return date.fromisoformat(value) + return datetime.fromisoformat(value).date() if get_origin(field_type) == list: (inner_type,) = get_args(field_type) From 6a22e2345b669ddd075c338f354a74235c8d970f Mon Sep 17 00:00:00 2001 From: Sandra Snan Date: Sun, 24 Sep 2023 00:42:46 +0200 Subject: [PATCH 2/3] Add in controversial timezone workaround --- toot/entities.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toot/entities.py b/toot/entities.py index 51250744..6ba55530 100644 --- a/toot/entities.py +++ b/toot/entities.py @@ -394,7 +394,7 @@ def _convert(field_type, value): return datetime.strptime(value, "%Y-%m-%dT%H:%M:%S.%f%z") if field_type == date: - return datetime.fromisoformat(value).date() + return datetime.fromisoformat(value.replace('Z', '+00:00')).date() if get_origin(field_type) == list: (inner_type,) = get_args(field_type) From b344bb3bdb1050a3dff953ebed48a4f0017b9711 Mon Sep 17 00:00:00 2001 From: Sandra Snan Date: Sun, 24 Sep 2023 08:09:06 +0200 Subject: [PATCH 3/3] Add tests for reading dates --- tests/test_console.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_console.py b/tests/test_console.py index 9f3b8354..3b7d5f26 100644 --- a/tests/test_console.py +++ b/tests/test_console.py @@ -122,6 +122,7 @@ def test_timeline(mock_get, monkeypatch, capsys): 'id': '111111111111111111', 'account': { 'display_name': 'Frank Zappa 🎸', + 'last_status_at': '2017-04-12T15:53:18.174Z', 'acct': 'fz' }, 'created_at': '2017-04-12T15:53:18.174Z', @@ -164,6 +165,7 @@ def test_timeline_with_re(mock_get, monkeypatch, capsys): 'created_at': '2017-04-12T15:53:18.174Z', 'account': { 'display_name': 'Johnny Cash', + 'last_status_at': '2011-04-12', 'acct': 'jc' }, 'content': "

The computer can't tell you the emotional story. It can give you the exact mathematical design, but what's missing is the eyebrows.

",