From 91e55622986bc2e837824a75da3e17e16ba4e2ca Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Sun, 24 Nov 2024 18:44:04 +0100 Subject: [PATCH] Parse datetimes to UTC. --- obsidian_import/__init__.py | 3 +++ personal_data/parse_util.py | 2 +- personal_data/util.py | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/obsidian_import/__init__.py b/obsidian_import/__init__.py index 3c3b1c3..dc4070c 100644 --- a/obsidian_import/__init__.py +++ b/obsidian_import/__init__.py @@ -211,6 +211,9 @@ def import_watched_series_csv_from_file(vault: ObsidianVault) -> int: def import_played_games_csv_from_file(vault: ObsidianVault) -> int: data_path = Path('output/games_played.csv') + if not data_path.exists(): + logger.warning('Skipping import of played games: %s is missing', data_path) + return 0 return import_activity_sample_csv_from_file( vault, data_path, diff --git a/personal_data/parse_util.py b/personal_data/parse_util.py index 50f1128..ec8b468 100644 --- a/personal_data/parse_util.py +++ b/personal_data/parse_util.py @@ -67,7 +67,7 @@ def parse_time(text: str) -> datetime.datetime: if time.tzinfo is None: msg = 'Could not parse timezone: ' + text raise RuntimeError(msg) - return time + return time.astimezone(datetime.UTC) def parse_date(text: str) -> datetime.date: diff --git a/personal_data/util.py b/personal_data/util.py index 0afd187..4fa57f8 100644 --- a/personal_data/util.py +++ b/personal_data/util.py @@ -20,7 +20,8 @@ def csv_safe_value(v: Any) -> str: return v.geturl() if isinstance(v, datetime.datetime): if v.tzinfo is None or v.tzinfo != datetime.UTC: - raise ValueError(v) + msg = f'Timezone must be UTC: {v}' + raise ValueError(msg) return str(v)