Merge pull request #1114 from jzelinskie/datefix

update format_date to handle December
This commit is contained in:
Jimmy Zelinskie 2016-01-01 19:07:15 -05:00
commit 286e408b9e

View file

@ -3,6 +3,7 @@
import json import json
from datetime import datetime, timedelta from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
from endpoints.api import (resource, nickname, ApiResource, query_param, parse_args, from endpoints.api import (resource, nickname, ApiResource, query_param, parse_args,
RepositoryParamResource, require_repo_admin, related_user_resource, RepositoryParamResource, require_repo_admin, related_user_resource,
@ -39,15 +40,14 @@ def aggregated_log_view(log, kinds, start_time):
# Because we aggregate based on the day of the month in SQL, we only have that information. # Because we aggregate based on the day of the month in SQL, we only have that information.
# Therefore, create a synthetic date based on the day and the month of the start time. # Therefore, create a synthetic date based on the day and the month of the start time.
# Logs are allowed for a maximum period of one week, so this calculation should always work. # Logs are allowed for a maximum period of one week, so this calculation should always work.
day = int(log.day) synthetic_date = datetime(start_time.year, start_time.month, int(log.day))
month = start_time.month if synthetic_date.day < start_time.day:
if day < start_time.day: synthetic_date = synthetic_date + relativedelta(months=1)
month = month + 1
view = { view = {
'kind': kinds[log.kind_id], 'kind': kinds[log.kind_id],
'count': log.count, 'count': log.count,
'datetime': format_date(datetime(start_time.year, month, day)) 'datetime': format_date(synthetic_date),
} }
return view return view