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

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.report import report
from gitlabtime.report import report_csv
......@@ -19,6 +21,14 @@ import click
'--month',
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(
'--project',
help='Filter for project name',
......@@ -31,9 +41,18 @@ import click
'--csv',
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(
month=month,
start=start,
end=end,
project=project,
username=username,
)
......
......@@ -39,7 +39,10 @@ def fetch_project(project, filter):
for author, date, seconds in fetch_times(item):
if filter['username'] not in (author, None):
continue
if not date.startswith(filter['month'] or ''):
if (filter['start'] or '') > date:
continue
if (filter['end'] or '9999-99-99') < date:
continue
entries[author, date] += seconds
......
Markdown is supported
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