diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cb53341..9430dc07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Stylize prompt to create new project or tag (#310). +- Aggregate calculates wrong time if used with `--current` (#293) ## [1.8.0] - 2019-08-26 diff --git a/tests/test_watson.py b/tests/test_watson.py index 09a5ec47..96b2da1c 100644 --- a/tests/test_watson.py +++ b/tests/test_watson.py @@ -795,6 +795,33 @@ def test_report(watson): watson.report(arrow.now(), arrow.now(), tags=["A"], ignore_tags=["A"]) +def test_report_current(config_dir): + watson = Watson( + current={'project': 'foo', 'start': arrow.now().shift(hours=-1)}, + config_dir=config_dir + ) + + _ = watson.report( + arrow.now(), arrow.now(), current=True, projects=['foo'] + ) + report = watson.report( + arrow.now(), arrow.now(), current=True, projects=['foo'] + ) + assert len(report['projects']) == 1 + assert report['projects'][0]['name'] == 'foo' + assert report['projects'][0]['time'] == pytest.approx(3600, rel=1e-2) + + report = watson.report( + arrow.now(), arrow.now(), current=False, projects=['foo'] + ) + assert len(report['projects']) == 0 + + report = watson.report( + arrow.now(), arrow.now(), projects=['foo'] + ) + assert len(report['projects']) == 0 + + # renaming project updates frame last_updated time def test_rename_project_with_time(mock, watson): """ diff --git a/watson/watson.py b/watson/watson.py index 65ddc71d..60e88594 100644 --- a/watson/watson.py +++ b/watson/watson.py @@ -467,13 +467,13 @@ def report(self, from_, to, current=None, projects=None, tags=None, if from_ > to: raise WatsonError("'from' must be anterior to 'to'") - if self.current: - if current or (current is None and - self.config.getboolean( - 'options', 'report_current')): - cur = self.current - self.frames.add(cur['project'], cur['start'], arrow.utcnow(), - cur['tags'], id="current") + if current is None: + current = self.config.getboolean('options', 'report_current') + + if self.current and current: + cur = self.current + self.frames.add(cur['project'], cur['start'], arrow.utcnow(), + cur['tags'], id="current") span = self.frames.span(from_, to) @@ -487,6 +487,9 @@ def report(self, from_, to, current=None, projects=None, tags=None, operator.attrgetter('project') ) + if self.current and current: + del self.frames['current'] + total = datetime.timedelta() report = {