Fix timezone bug

This commit is contained in:
Maximilian Friedersdorff 2025-08-27 13:50:25 +01:00
parent 0c6d1064d5
commit 093da880ca

View file

@ -1,7 +1,9 @@
#!/usr/bin/env python3
from collections import defaultdict
from collections.abc import Iterable
from datetime import datetime, timedelta, timezone, time
from datetime import datetime, timedelta
from zoneinfo import ZoneInfo
import json
@ -48,6 +50,7 @@ def print_projects(projects) -> None:
)
def main():
for line in sys.stdin:
if line.strip() == "":
break
@ -56,12 +59,20 @@ input = json.load(sys.stdin)
projects = defaultdict(dict)
for record in input:
record["start"] = datetime.strptime(record["start"], DATE_FORMAT)
record["start"] = (
datetime.strptime(record["start"], DATE_FORMAT)
.replace(tzinfo=ZoneInfo("UTC"))
.astimezone()
)
if "end" in record:
record["end"] = datetime.strptime(record["end"], DATE_FORMAT)
record["end"] = (
datetime.strptime(record["end"], DATE_FORMAT)
.replace(tzinfo=ZoneInfo("UTC"))
.astimezone()
)
else:
record["end"] = datetime.now()
record["end"] = datetime.now(tz=ZoneInfo("UTC")).astimezone()
record["duration"] = record["end"] - record["start"]
record["project"] = ""
@ -81,7 +92,10 @@ for record in input:
projects[record["project"]]["duration"] += record["duration"]
projects[record["project"]]["tags"] += record["tags"]
print_projects(projects)
print()
print_details(input)
if __name__ == "__main__":
main()