From 45bae2c2b39e37d73cfeeb724c6566fd285e5291 Mon Sep 17 00:00:00 2001 From: Marcin Swiderski Date: Sun, 12 Dec 2021 16:18:35 +0100 Subject: [PATCH 1/3] Support for night owls: starting a day at later hour, e.g. 6, to properly report late night work --- docs/user-guide/configuration.md | 1 + watson/cli.py | 3 ++- watson/frames.py | 12 ++++++------ watson/watson.py | 3 ++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/docs/user-guide/configuration.md b/docs/user-guide/configuration.md index fbccd93..4a49e5b 100644 --- a/docs/user-guide/configuration.md +++ b/docs/user-guide/configuration.md @@ -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 diff --git a/watson/cli.py b/watson/cli.py index 31b5887..da26f4f 100644 --- a/watson/cli.py +++ b/watson/cli.py @@ -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, diff --git a/watson/frames.py b/watson/frames.py index 0e51157..a195de5 100644 --- a/watson/frames.py +++ b/watson/frames.py @@ -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 @@ -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) diff --git a/watson/watson.py b/watson/watson.py index 3f39be2..beb4f66 100644 --- a/watson/watson.py +++ b/watson/watson.py @@ -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( From 9b9474f367c288fd9389aeb3808c81048c3adac5 Mon Sep 17 00:00:00 2001 From: Marcin Swiderski Date: Tue, 14 Dec 2021 00:34:18 +0100 Subject: [PATCH 2/3] Better handling of --day, --week, etc arguments with custom day_start_hour --- watson/cli.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/watson/cli.py b/watson/cli.py index da26f4f..bf17b96 100644 --- a/watson/cli.py +++ b/watson/cli.py @@ -105,6 +105,10 @@ def convert(self, value, param, ctx) -> arrow: "options", "week_start", "monday") date = apply_weekday_offset( start_time=date, week_start=week_start) + if param.name in ["day", "week", "month", "luna", "year"]: + day_start_hour = ctx.obj.config.get( + "options", "day_start_hour", 0) + date = date.shift(hours=-int(day_start_hour)) return date def _parse_multiformat(self, value) -> arrow: From e0ff01e90c45e8c7e1f165d2ff56834174fe1e34 Mon Sep 17 00:00:00 2001 From: Marcin Swiderski Date: Tue, 14 Dec 2021 16:02:20 +0100 Subject: [PATCH 3/3] Revert "Better handling of --day, --week, etc arguments with custom day_start_hour" This reverts commit 3214d4ca12cdd20e8f72546e682cc9bf715b6a05. --- watson/cli.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/watson/cli.py b/watson/cli.py index bf17b96..da26f4f 100644 --- a/watson/cli.py +++ b/watson/cli.py @@ -105,10 +105,6 @@ def convert(self, value, param, ctx) -> arrow: "options", "week_start", "monday") date = apply_weekday_offset( start_time=date, week_start=week_start) - if param.name in ["day", "week", "month", "luna", "year"]: - day_start_hour = ctx.obj.config.get( - "options", "day_start_hour", 0) - date = date.shift(hours=-int(day_start_hour)) return date def _parse_multiformat(self, value) -> arrow: