Patch timezone so it uses standard python object

This commit is contained in:
Dima Gerasimov 2018-11-10 14:34:21 +00:00
parent 6b0cd6a9a7
commit c7b266579a

View file

@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timezone
from typing import List, NamedTuple, Optional
from os.path import basename, islink, isdir, join
from os import listdir
@ -42,6 +42,16 @@ class Commit(NamedTuple):
sha: str
# TODO filter so they are authored by me
# TODO not sure, maybe a better idea to move it to timeline?
def fix_datetime(dt) -> datetime:
# git module got it's own tzinfo object.. and it's pretty weird
tz = dt.tzinfo
assert tz._name == 'fixed'
offset = tz._offset
ntz = timezone(offset)
return dt.replace(tzinfo=ntz)
def iter_commits(repo: str):
# TODO other branches?
rr = basename(repo)
@ -49,7 +59,7 @@ def iter_commits(repo: str):
for c in gr.iter_commits():
if by_me(c.author):
yield Commit(
dt=c.committed_datetime, # TODO authored??
dt=fix_datetime(c.committed_datetime), # TODO authored??
message=c.message.strip(),
repo=rr,
sha=c.hexsha,