From 94f2fb46149bb08e0fe2ce0d00f35d12701ecd31 Mon Sep 17 00:00:00 2001 From: Marcin Swiderski Date: Sat, 30 Nov 2024 16:40:57 +0100 Subject: [PATCH] * Fix shifting from_ parameter for the nth time. It's simple math, it shouldn't be so hard XD --- watson/cli.py | 5 ++--- watson/frames.py | 8 ++++++++ watson/watson.py | 5 ++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/watson/cli.py b/watson/cli.py index 81910c5..a21ff61 100644 --- a/watson/cli.py +++ b/watson/cli.py @@ -19,7 +19,7 @@ get_rename_types, get_tags, ) -from .frames import Frame, shifted_floor +from .frames import Frame, shifted_from from .utils import ( apply_weekday_offset, build_csv, @@ -1066,8 +1066,7 @@ def log(watson, current, reverse, from_, to, projects, tags, ignore_projects, if _ is not None): from_ = start_time - if from_ == from_.floor('day'): - from_ = shifted_floor(from_, 'day') + from_ = shifted_from(from_) if from_ > to: raise click.ClickException("'from' must be anterior to 'to'") diff --git a/watson/frames.py b/watson/frames.py index 26c58a0..4a62680 100644 --- a/watson/frames.py +++ b/watson/frames.py @@ -21,6 +21,14 @@ def shifted_ceil(time, timeframe): return time.shift(hours=-hour_shift).ceil(timeframe).shift(hours=hour_shift) +def shifted_from(from_): + if from_ == from_.floor('day'): + if arrow.now().hour < hour_shift: + from_ = from_.shift(days=-1) + from_ = from_.shift(hours=hour_shift) + return from_ + + class Frame(namedtuple('Frame', HEADERS)): def __new__(cls, start, stop, project, id, tags=None, updated_at=None,): try: diff --git a/watson/watson.py b/watson/watson.py index dfffe5a..764d0bb 100644 --- a/watson/watson.py +++ b/watson/watson.py @@ -10,7 +10,7 @@ import subprocess from .config import ConfigParser -from .frames import Frames, set_hour_shift, shifted_floor +from .frames import Frames, set_hour_shift, shifted_from from .utils import deduplicate, make_json_writer, safe_save, sorted_groupby from .version import version as __version__ # noqa @@ -535,8 +535,7 @@ def report(self, from_, to, current=None, projects=None, tags=None, if _ is not None): from_ = start_time - if from_ == from_.floor('day'): - from_ = shifted_floor(from_, 'day') + from_ = shifted_from(from_) if not self._validate_report_options(projects, ignore_projects): raise WatsonError(