update format_date to handle December

This commit is contained in:
Jimmy Zelinskie 2016-01-01 18:34:38 -05:00
parent 28eb31ed36
commit a967340aad

View file

@ -3,6 +3,7 @@
import json
from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
from endpoints.api import (resource, nickname, ApiResource, query_param, parse_args,
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.
# 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.
day = int(log.day)
month = start_time.month
if day < start_time.day:
month = month + 1
synthetic_date = datetime(start_time.year, start_time.month, int(log.day))
if synthetic_date.day < start_time.day:
synthetic_date = synthetic_date + relativedelta(months=1)
view = {
'kind': kinds[log.kind_id],
'count': log.count,
'datetime': format_date(datetime(start_time.year, month, day))
'datetime': format_date(synthetic_date),
}
return view