Commit 2bc04131 authored by Thomas Lotze's avatar Thomas Lotze
Browse files

re #2: add filters for start and end date, fallback to month

parent f55ef92c
from calendar import monthrange
from datetime import date
from gitlabtime.fetch import fetch from gitlabtime.fetch import fetch
from gitlabtime.report import report from gitlabtime.report import report
from gitlabtime.report import report_csv from gitlabtime.report import report_csv
...@@ -19,6 +21,14 @@ import click ...@@ -19,6 +21,14 @@ import click
'--month', '--month',
help='Filter for month (yyyy-mm)', help='Filter for month (yyyy-mm)',
) )
@click.option(
'--start',
help='Filter for start date (yyyy-mm-dd)',
)
@click.option(
'--end',
help='Filter for end date (yyyy-mm-dd)',
)
@click.option( @click.option(
'--project', '--project',
help='Filter for project name', help='Filter for project name',
...@@ -31,9 +41,18 @@ import click ...@@ -31,9 +41,18 @@ import click
'--csv', '--csv',
help='path to CSV output file', help='path to CSV output file',
) )
def cli(url, token, month, project, username, csv): def cli(url, token, month, start, end, project, username, csv):
if month:
first = month + '-01'
if not start:
start = first
if not end:
first = date.fromisoformat(first)
_, last = monthrange(first.year, first.month)
end = '{}-{}'.format(month, last)
filter = dict( filter = dict(
month=month, start=start,
end=end,
project=project, project=project,
username=username, username=username,
) )
......
...@@ -39,7 +39,10 @@ def fetch_project(project, filter): ...@@ -39,7 +39,10 @@ def fetch_project(project, filter):
for author, date, seconds in fetch_times(item): for author, date, seconds in fetch_times(item):
if filter['username'] not in (author, None): if filter['username'] not in (author, None):
continue continue
if not date.startswith(filter['month'] or ''):
if (filter['start'] or '') > date:
continue
if (filter['end'] or '9999-99-99') < date:
continue continue
entries[author, date] += seconds entries[author, date] += seconds
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment