Commit 0794f2c1 authored by Thomas Lotze's avatar Thomas Lotze
Browse files

fix collection of tracking entries: count time tracked via issue description

parent 5424b55e
......@@ -16,3 +16,19 @@ See `$ gitlabtime --help`.
Options can be pre-specified as environment variables, e.g. the default value
of `--url` is taken from `GITLABTIME_URL`.
Timestamps are reported by Gitlab as time-zone aware. However, time tracking
notes include a date that is unaware of time zones. As we cannot avoid dealing
with both, and we don't know the details of how Gitlab converts between them,
we cannot guarantee consistency of the tracking data as meant by the user who
entered their quick actions.
We can only try to be consistent in how to interpret times and dates as
reported by the Gitlab API. So, whenever having to extract a date from a
timestamp, it is as a good a guess as any to just ignore the time zone, hoping
that this is what Gitlab itself does when producing those plain dates, and
that it does so using the same time zone as for reporting timestamps.
......@@ -78,6 +78,7 @@ def fetch_issue(issue):
notes = issue.notes.list(
all=True, order_by='created_at', sort='desc')
total = 0
for note in notes:
if not note.system:
......@@ -90,5 +91,25 @@ def fetch_issue(issue):
seconds = parse_action(action)
total += seconds
yield['username'], date, seconds
# We've now visited all notes up until issue creation. Time may also
# have been tracked by a quick action in the original project
# description (but not later edits). In that case, no system note is
# added and if that time tracking was applied to some date, that date
# is lost. We can only infer the amount of time as the difference
# between the total time as given by the issue's time stats and the
# total time tracked by notes, and apply it to the creation date of
# the issue.
seconds = issue.time_stats()['total_time_spent'] - total
if not seconds:
# Dates come without time zones and we don't know how Gitlab converts
# from time-zone aware to unaware, so we don't think about time zones
# and hope for the best.
date = issue.created_at.split('T')[0]
yield['username'], date, seconds
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment