From c7b266579a6e8bc28c44a7b6c16de18d7278e7ba Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Sat, 10 Nov 2018 14:34:21 +0000 Subject: [PATCH] Patch timezone so it uses standard python object --- commits/__init__.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/commits/__init__.py b/commits/__init__.py index a7944dd..4a582c0 100644 --- a/commits/__init__.py +++ b/commits/__init__.py @@ -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,