Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for night owls: starting a day at later hour, e.g. 6, to properly report late night work #4

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/user-guide/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ stop_on_restart = false
date_format = %Y.%m.%d
time_format = %H:%M:%S%z
week_start = monday
day_start_hour = 0
log_current = false
pager = true
report_current = false
Expand Down
3 changes: 2 additions & 1 deletion watson/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1088,7 +1088,8 @@ def log(watson, current, reverse, from_, to, projects, tags, ignore_projects,
if reverse is None:
reverse = watson.config.getboolean('options', 'reverse_log', True)

span = watson.frames.span(from_, to)
day_start_hour = watson.config.getint('options', 'day_start_hour', 0)
span = watson.frames.span(from_, to, day_start_hour)
filtered_frames = watson.frames.filter(
projects=projects or None, tags=tags or None,
ignore_projects=ignore_projects or None,
Expand Down
12 changes: 6 additions & 6 deletions watson/frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ def __gte__(self, other):


class Span(object):
def __init__(self, start, stop, timeframe='day'):
self.timeframe = timeframe
self.start = start.floor(self.timeframe)
self.stop = stop.ceil(self.timeframe)
def __init__(self, start, stop, shift_hours):
timeframe = 'day'
self.start = start.floor(timeframe).shift(hours=shift_hours)
self.stop = stop.ceil(timeframe).shift(hours=shift_hours)

def overlaps(self, frame):
return frame.start <= self.stop and frame.stop >= self.start
Expand Down Expand Up @@ -183,5 +183,5 @@ def filter(
stop = span.stop if frame.stop > span.stop else frame.stop
yield frame._replace(start=start, stop=stop)

def span(self, start, stop):
return Span(start, stop)
def span(self, start, stop, shift_hours):
return Span(start, stop, shift_hours)
3 changes: 2 additions & 1 deletion watson/watson.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,8 @@ def report(self, from_, to, current=None, projects=None, tags=None,
self.frames.add(cur['project'], cur['start'], arrow.utcnow(),
cur['tags'], id="current")

span = self.frames.span(from_, to)
day_start_hour = self.config.getint('options', 'day_start_hour', 0)
span = self.frames.span(from_, to, day_start_hour)

frames_by_project = sorted_groupby(
self.frames.filter(
Expand Down
Loading