Fix timezone bug
This commit is contained in:
parent
0c6d1064d5
commit
093da880ca
1 changed files with 48 additions and 34 deletions
|
|
@ -1,7 +1,9 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from collections.abc import Iterable
|
from collections.abc import Iterable
|
||||||
from datetime import datetime, timedelta, timezone, time
|
from datetime import datetime, timedelta
|
||||||
|
from zoneinfo import ZoneInfo
|
||||||
|
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
@ -48,6 +50,7 @@ def print_projects(projects) -> None:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
for line in sys.stdin:
|
for line in sys.stdin:
|
||||||
if line.strip() == "":
|
if line.strip() == "":
|
||||||
break
|
break
|
||||||
|
|
@ -56,12 +59,20 @@ input = json.load(sys.stdin)
|
||||||
projects = defaultdict(dict)
|
projects = defaultdict(dict)
|
||||||
|
|
||||||
for record in input:
|
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:
|
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:
|
else:
|
||||||
record["end"] = datetime.now()
|
record["end"] = datetime.now(tz=ZoneInfo("UTC")).astimezone()
|
||||||
|
|
||||||
record["duration"] = record["end"] - record["start"]
|
record["duration"] = record["end"] - record["start"]
|
||||||
record["project"] = ""
|
record["project"] = ""
|
||||||
|
|
@ -81,7 +92,10 @@ for record in input:
|
||||||
projects[record["project"]]["duration"] += record["duration"]
|
projects[record["project"]]["duration"] += record["duration"]
|
||||||
projects[record["project"]]["tags"] += record["tags"]
|
projects[record["project"]]["tags"] += record["tags"]
|
||||||
|
|
||||||
|
|
||||||
print_projects(projects)
|
print_projects(projects)
|
||||||
print()
|
print()
|
||||||
print_details(input)
|
print_details(input)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue