Skip to content

Commit

Permalink
* Fix shifting from_ parameter for the nth time. It's simple math, it…
Browse files Browse the repository at this point in the history
… shouldn't be so hard XD
  • Loading branch information
sfider committed Nov 30, 2024
1 parent 53fa898 commit 94f2fb4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
5 changes: 2 additions & 3 deletions watson/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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'")
Expand Down
8 changes: 8 additions & 0 deletions watson/frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions watson/watson.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 94f2fb4

Please sign in to comment.