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

report/log: add lunar start time options 🌔 #215

Merged
merged 2 commits into from
Jul 30, 2018
Merged
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
6 changes: 6 additions & 0 deletions docs/user-guide/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ You can also use special shortcut options for easier timespan control:
`--day` sets the log timespan to the current day (beginning at 00:00h)
and `--year`, `--month` and `--week` to the current year, month or week
respectively.
The shortcut `--luna` sets the timespan to the current moon cycle with
the last full moon marking the start of the cycle.

If you are outputting to the terminal, you can selectively enable a pager
through the `--pager` option.
Expand Down Expand Up @@ -172,6 +174,7 @@ Flag | Help
`-t, --to DATE` | The date at which the log should stop (inclusive). Defaults to tomorrow.
`-y, --year` | Reports activity for the current year.
`-m, --month` | Reports activity for the current month.
`-l, --luna` | Reports activity for the current moon cycle.
`-w, --week` | Reports activity for the current week.
`-d, --day` | Reports activity for the current day.
`-a, --all` | Reports all activities.
Expand Down Expand Up @@ -329,6 +332,8 @@ You can also use special shortcut options for easier timespan control:
`--day` sets the report timespan to the current day (beginning at 00:00h)
and `--year`, `--month` and `--week` to the current year, month or week
respectively.
The shortcut `--luna` sets the timespan to the current moon cycle with
the last full moon marking the start of the cycle.

You can limit the report to a project or a tag using the `--project` and
`--tag` options. They can be specified several times each to add multiple
Expand Down Expand Up @@ -416,6 +421,7 @@ Flag | Help
`-t, --to DATE` | The date at which the report should stop (inclusive). Defaults to tomorrow.
`-y, --year` | Reports activity for the current year.
`-m, --month` | Reports activity for the current month.
`-l, --luna` | Reports activity for the current moon cycle.
`-w, --week` | Reports activity for the current week.
`-d, --day` | Reports activity for the current day.
`-a, --all` | Reports all activities.
Expand Down
26 changes: 26 additions & 0 deletions tests/test_fullmoon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Unit test for the 'fullmoon' helper"""

import arrow
import pytest

from watson.fullmoon import get_last_full_moon


def test_with_known_date():
aniceday = arrow.Arrow(2018, 7, 27, 10, 51)
aniceday_lastMoon = arrow.Arrow(2018, 6, 28, 4, 55)
aniceday_result = get_last_full_moon(aniceday)
assert aniceday_result == aniceday_lastMoon
thenextday = aniceday.shift(days=1)
thenextday_lastMoon = arrow.Arrow(2018, 7, 27, 20, 22)
thenextday_result = get_last_full_moon(thenextday)
assert thenextday_result == thenextday_lastMoon


def test_invalid_ranges():
fail = arrow.Arrow(1970, 1, 1)
fail2 = arrow.Arrow(2100, 5, 5)
with pytest.raises(ValueError):
get_last_full_moon(fail)
with pytest.raises(ValueError):
get_last_full_moon(fail2)
2 changes: 1 addition & 1 deletion watson.completion
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ _watson_complete () {
COMPREPLY=($(compgen -W "$tags" -- ${cur}))
;;
*)
COMPREPLY=($(compgen -W "-a -c -C -d -f -g -G -j -m -p -t -T -w -y --all --current --no-current --pager --no-pager --from --to --project --tag --day --week --month --year --json" -- ${cur})) ;;
COMPREPLY=($(compgen -W "-a -c -C -d -f -g -G -j -m -p -t -T -w -y --all --current --no-current --pager --no-pager --from --to --project --tag --day --week --month --year --luna --json" -- ${cur})) ;;
esac
;;
merge)
Expand Down
34 changes: 23 additions & 11 deletions watson/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def status(watson, project, tags, elapsed):
))


_SHORTCUT_OPTIONS = ['all', 'year', 'month', 'week', 'day']
_SHORTCUT_OPTIONS = ['all', 'year', 'month', 'luna', 'week', 'day']


@cli.command()
Expand All @@ -321,23 +321,27 @@ def status(watson, project, tags, elapsed):
"Defaults to tomorrow.")
@click.option('-y', '--year', cls=MutuallyExclusiveOption, type=Date,
flag_value=get_start_time_for_period('year'),
mutually_exclusive=['day', 'week', 'month', 'all'],
mutually_exclusive=['day', 'week', 'luna', 'month', 'all'],
help='Reports activity for the current year.')
@click.option('-m', '--month', cls=MutuallyExclusiveOption, type=Date,
flag_value=get_start_time_for_period('month'),
mutually_exclusive=['day', 'week', 'year', 'all'],
mutually_exclusive=['day', 'week', 'luna', 'year', 'all'],
help='Reports activity for the current month.')
@click.option('-l', '--luna', cls=MutuallyExclusiveOption, type=Date,
flag_value=get_start_time_for_period('luna'),
mutually_exclusive=['day', 'week', 'month', 'year', 'all'],
help='Reports activity for the current moon cycle.')
@click.option('-w', '--week', cls=MutuallyExclusiveOption, type=Date,
flag_value=get_start_time_for_period('week'),
mutually_exclusive=['day', 'month', 'year', 'all'],
mutually_exclusive=['day', 'month', 'luna', 'year', 'all'],
help='Reports activity for the current week.')
@click.option('-d', '--day', cls=MutuallyExclusiveOption, type=Date,
flag_value=get_start_time_for_period('day'),
mutually_exclusive=['week', 'month', 'year', 'all'],
mutually_exclusive=['week', 'month', 'luna', 'year', 'all'],
help='Reports activity for the current day.')
@click.option('-a', '--all', cls=MutuallyExclusiveOption, type=Date,
flag_value=get_start_time_for_period('all'),
mutually_exclusive=['day', 'week', 'month', 'year'],
mutually_exclusive=['day', 'week', 'month', 'luna', 'year'],
help='Reports all activities.')
@click.option('-p', '--project', 'projects', multiple=True,
help="Reports activity only for the given project. You can add "
Expand All @@ -351,8 +355,8 @@ def status(watson, project, tags, elapsed):
@click.option('-g/-G', '--pager/--no-pager', 'pager', default=None,
help="(Don't) view output through a pager.")
@click.pass_obj
def report(watson, current, from_, to, projects,
tags, year, month, week, day, all, format_json, pager):
def report(watson, current, from_, to, projects, tags, year, month,
week, day, luna, all, format_json, pager):
"""
Display a report of the time spent on each project.

Expand All @@ -367,6 +371,8 @@ def report(watson, current, from_, to, projects,
`--day` sets the report timespan to the current day (beginning at 00:00h)
and `--year`, `--month` and `--week` to the current year, month or week
respectively.
The shortcut `--luna` sets the timespan to the current moon cycle with
the last full moon marking the start of the cycle.

You can limit the report to a project or a tag using the `--project` and
`--tag` options. They can be specified several times each to add multiple
Expand Down Expand Up @@ -448,7 +454,7 @@ def report(watson, current, from_, to, projects,
try:
report = watson.report(from_, to, current, projects, tags,
year=year, month=month, week=week, day=day,
all=all)
luna=luna, all=all)
except watson.WatsonError as e:
raise click.ClickException(e)

Expand Down Expand Up @@ -535,6 +541,10 @@ def _final_print(lines):
flag_value=get_start_time_for_period('month'),
mutually_exclusive=['day', 'week', 'year', 'all'],
help='Reports activity for the current month.')
@click.option('-l', '--luna', cls=MutuallyExclusiveOption, type=Date,
flag_value=get_start_time_for_period('luna'),
mutually_exclusive=['day', 'week', 'month', 'year', 'all'],
help='Reports activity for the current moon cycle.')
@click.option('-w', '--week', cls=MutuallyExclusiveOption, type=Date,
flag_value=get_start_time_for_period('week'),
mutually_exclusive=['day', 'month', 'year', 'all'],
Expand All @@ -560,7 +570,7 @@ def _final_print(lines):
help="(Don't) view output through a pager.")
@click.pass_obj
def log(watson, current, from_, to, projects, tags, year, month, week, day,
all, format_json, pager):
luna, all, format_json, pager):
"""
Display each recorded session during the given timespan.

Expand All @@ -572,6 +582,8 @@ def log(watson, current, from_, to, projects, tags, year, month, week, day,
`--day` sets the log timespan to the current day (beginning at 00:00h)
and `--year`, `--month` and `--week` to the current year, month or week
respectively.
The shortcut `--luna` sets the timespan to the current moon cycle with
the last full moon marking the start of the cycle.

If you are outputting to the terminal, you can selectively enable a pager
through the `--pager` option.
Expand Down Expand Up @@ -609,7 +621,7 @@ def log(watson, current, from_, to, projects, tags, year, month, week, day,
02cb269 09:53 to 12:43 2h 50m 07s apollo11 [wheels]
1070ddb 13:48 to 16:17 2h 29m 11s voyager1 [antenna, sensors]
""" # noqa
for start_time in (_ for _ in [day, week, month, year, all]
for start_time in (_ for _ in [day, week, month, luna, year, all]
if _ is not None):
from_ = start_time

Expand Down
Loading