Fix handling of dates in logs view
- Fixes #1742 - Also fixes the time zone on the aggregated logs API
This commit is contained in:
parent
987bd53c2d
commit
b459581637
3 changed files with 9 additions and 11 deletions
|
@ -14,6 +14,7 @@ from auth.auth_context import get_authenticated_user
|
||||||
from data import model, database
|
from data import model, database
|
||||||
from auth import scopes
|
from auth import scopes
|
||||||
from app import avatar
|
from app import avatar
|
||||||
|
from tzlocal import get_localzone
|
||||||
|
|
||||||
LOGS_PER_PAGE = 20
|
LOGS_PER_PAGE = 20
|
||||||
SERVICE_LEVEL_LOG_KINDS = set(['service_key_create', 'service_key_approve', 'service_key_delete',
|
SERVICE_LEVEL_LOG_KINDS = set(['service_key_create', 'service_key_approve', 'service_key_delete',
|
||||||
|
@ -41,7 +42,7 @@ 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.
|
||||||
synthetic_date = datetime(start_time.year, start_time.month, int(log.day))
|
synthetic_date = datetime(start_time.year, start_time.month, int(log.day), tzinfo=get_localzone())
|
||||||
if synthetic_date.day < start_time.day:
|
if synthetic_date.day < start_time.day:
|
||||||
synthetic_date = synthetic_date + relativedelta(months=1)
|
synthetic_date = synthetic_date + relativedelta(months=1)
|
||||||
|
|
||||||
|
|
|
@ -62,3 +62,4 @@ bencode
|
||||||
cryptography
|
cryptography
|
||||||
httmock
|
httmock
|
||||||
moto
|
moto
|
||||||
|
tzlocal
|
||||||
|
|
|
@ -1125,18 +1125,14 @@ LogUsageChart.prototype.buildData_ = function(aggregatedLogs) {
|
||||||
var aggregated = aggregatedLogs[i];
|
var aggregated = aggregatedLogs[i];
|
||||||
var title = this.titleMap_[aggregated.kind] || aggregated.kind;
|
var title = this.titleMap_[aggregated.kind] || aggregated.kind;
|
||||||
var datetime = parseDate(aggregated.datetime);
|
var datetime = parseDate(aggregated.datetime);
|
||||||
var dateDay = datetime.getDate();
|
|
||||||
if (dateDay < 10) {
|
|
||||||
dateDay = '0' + dateDay;
|
|
||||||
}
|
|
||||||
|
|
||||||
var formatted = (datetime.getMonth() + 1) + '/' + dateDay;
|
var formatted = (datetime.getMonth() + 1) + '/' + datetime.getDate();
|
||||||
var adjusted = new Date(datetime.getFullYear(), datetime.getMonth(), datetime.getDate());
|
var justdate = new Date(datetime.getFullYear(), datetime.getMonth(), datetime.getDate());
|
||||||
var key = title + '_' + formatted;
|
var key = title + '_' + formatted;
|
||||||
var entry = {
|
var entry = {
|
||||||
'kind': aggregated.kind,
|
'kind': aggregated.kind,
|
||||||
'title': title,
|
'title': title,
|
||||||
'adjusted': adjusted,
|
'justdate': justdate,
|
||||||
'formatted': datetime.getDate(),
|
'formatted': datetime.getDate(),
|
||||||
'count': aggregated.count
|
'count': aggregated.count
|
||||||
};
|
};
|
||||||
|
@ -1162,11 +1158,11 @@ LogUsageChart.prototype.buildData_ = function(aggregatedLogs) {
|
||||||
}
|
}
|
||||||
|
|
||||||
found.values.push({
|
found.values.push({
|
||||||
'x': entry.adjusted,
|
'x': entry.justdate,
|
||||||
'y': entry.count
|
'y': entry.count
|
||||||
});
|
});
|
||||||
|
|
||||||
dateMap[entry.adjusted.toString()] = entry.adjusted;
|
dateMap[entry.justdate.toString()] = entry.justdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: nvd3 has a bug that causes d3 to fail if there is not an entry for every single
|
// Note: nvd3 has a bug that causes d3 to fail if there is not an entry for every single
|
||||||
|
@ -1197,7 +1193,7 @@ LogUsageChart.prototype.buildData_ = function(aggregatedLogs) {
|
||||||
}
|
}
|
||||||
|
|
||||||
datum.values.sort(function(a, b) {
|
datum.values.sort(function(a, b) {
|
||||||
return a['x'].getDate() - b['x'].getDate();
|
return (a['x'].getDate() * 1) - (b['x'].getDate() * 1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue