Skip to content

Commit

Permalink
Show durations aggregation at sum command (#170)
Browse files Browse the repository at this point in the history
Co-authored-by: Adam Uhlíř <[email protected]>
  • Loading branch information
figarocorso and AuHau authored Dec 7, 2020
1 parent 184c0ac commit 1143639
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion toggl/cli/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,12 @@ def entry_ls(ctx, fields, today, use_reports, **conditions):
help='Defines start of a date range to filter the entries by.')
@click.option('--stop', '-p', type=types.DateTimeType(), help='Defines stop of a date range to filter the entries by.')
@click.option('--today', '-t', is_flag=True, help='Scopes the time to the current day')
@click.option('--show-total', '-st', is_flag=True, help='Shows total aggregation.')
@click.option('--project', '-o', type=types.ResourceType(api.Project),
help='Filters the entries by project. Can be ID or name of the project.', )
@click.option('--tags', '-a', type=types.SetType(), help='Filters the entries by list of tags delimited with \',\'')
@click.pass_context
def entry_sum(ctx, use_reports, today, **conditions):
def entry_sum(ctx, use_reports, today, show_total, **conditions):
"""
Shows summary of totally tracked time based on days.
Displayed Total time is in format HH:MM:SS
Expand All @@ -311,6 +312,10 @@ def entry_sum(ctx, use_reports, today, **conditions):
entries = get_entries(ctx, use_reports, **conditions)
sums_per_day = get_times_based_on_days(entries, config)

if show_total:
sums_per_day.insert(0, ["total",
reduce((lambda x, y: x + y), [duration for _, duration in sums_per_day])])

table = PrettyTable()
table.field_names = [click.style('Day', **theme.header), click.style('Total time', **theme.header)]
table.border = False
Expand Down
2 changes: 1 addition & 1 deletion toggl/cli/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,4 @@ def format_duration(duration):
if isinstance(duration, int):
duration = pendulum.duration(seconds=duration)

return '{}:{:02d}:{:02d}'.format(duration.hours, duration.minutes, duration.remaining_seconds)
return '{}:{:02d}:{:02d}'.format(duration.in_hours(), duration.minutes, duration.remaining_seconds)

0 comments on commit 1143639

Please sign in to comment.