I am using a Python library gitlab to get last commits for the current day. The main purpose is to find out time diff between last and previous commits for my time tracker.
It works in this way however when the very first commit does not exist in this day I am getting, for example, 10:00 hour as a base (starting work) And here is my problem, Gitlab time and my pc time is not the same and it gives me incorrect diff.
I would like to know whether there is a way to get current DateTime from Gitlab to compare my pc time and find out a real diff.
Here is an example:
def oneDayCommitsBy(user, project, cDate = datetime.datetime.now()):
untilDt = cDate + datetime.timedelta(days=1)
strcDate = "%s-%s-%s" % (cDate.year, cDate.month, cDate.day)
strUntilDt = "%s-%s-%s" % (untilDt.year, untilDt.month, untilDt.day)
cDayCommits = project.commits.list(ref_name="master", since=strcDate, until=strUntilDt)
print 'commmits [' + strcDate + ', ' + strUntilDt + ']'
for c in cDayCommits:
if c.author_name == user:
print c
print '\n'
ctime = datetime.datetime.now()
commitTm = datetime.datetime.strptime(str(c.created_at),"%Y-%m-%dT%H:%M:%S.%fZ")
diff = ctime - commitTm
print diff.total_seconds()/3600
print '\r'
# private token or personal token authentication
gl = gitlab.Gitlab(HOST, private_token=TOKEN, api_version=4)
gl.auth()
project = gl.projects.get(REPO)
oneDayCommitsBy('harry', project)
What it does is getting commits and comparing created_at time to local time and calculates diff in an hour but the difference is an incorrect cause in my pc time is different and in gitlab is different too.