Commit 128de74c authored by ale's avatar ale

show all dates in UTC

parent a6440402
......@@ -10,25 +10,37 @@ lens.localTzOffset = (new Date()).getTimezoneOffset() * 60000;
lens.util = {};
// Date and timestamp helper functions.
/*
* Date and timestamp helper functions.
*
* The following types are known:
*
* 'timestamp' is a standard UNIX timestamp (seconds since epoch UTC);
* 'EStimestamp' is in microseconds.
*
* All dates are printed in UTC: since Javascript date support is
* horrifying, this is achieved simply by creating bad Date objects
* with wrong timezone information so that they display the UTC date
* when printed...
*/
lens.util.timestampToDate = function(ts) {
return new Date(ts * 1000);
return new Date(ts * 1000 + lens.localTzOffset);
};
lens.util.dateToTimestamp = function(d) {
return (d.getTime() / 1000);
return (d.getTime() / 1000);
};
lens.util.timestampNow = function() {
return lens.util.dateToTimestamp(new Date());
return lens.util.dateToTimestamp(new Date());
};
lens.util.timestampAdd = function(ts, seconds) {
return (ts + seconds);
return (ts + seconds);
};
lens.util.timestampToString = function(ts) {
return lens.util.timestampToDate(ts).strftime('%Y/%m/%d %H:%M:%S');
return lens.util.timestampToDate(ts).strftime('%Y/%m/%d %H:%M:%S');
};
lens.util.EStimestampToString = function(ts) {
......@@ -85,6 +97,7 @@ lens.Lens = function(rootObj, resultViewObj, config) {
format: 'yyyy/mm/dd hh:ii',
autoclose: true,
todayBtn: true,
todayHighlight: true,
minuteStep: 10,
pickerPosition: 'bottom-left'
};
......@@ -92,6 +105,8 @@ lens.Lens = function(rootObj, resultViewObj, config) {
'changeDate', function(ev) {
var t = lens.util.dateToTimestamp(ev.date);
lensobj.query_params.time_range.start = t;
console.log('set time_range.start orig=' + ev.date + ' dst=' + t + ' ' +
lens.util.timestampToDate(t).strftime('%Y/%m/%d %H:%M'));
var end_limit = t + 300;
if (lensobj.query_params.time_range.end < end_limit) {
lensobj.setEndTime(end_limit);
......@@ -131,14 +146,16 @@ lens.Lens = function(rootObj, resultViewObj, config) {
lens.Lens.prototype.setStartTime = function(t) {
this.query_params.time_range.start = t;
this.time_start_elem.find('input').val(
console.log('set time_range.start to ' + t + ' ' +
lens.util.timestampToDate(t).strftime('%Y/%m/%d %H:%M'));
this.time_start_elem.val(
lens.util.timestampToDate(t).strftime('%Y/%m/%d %H:%M'));
this.time_start_elem.datetimepicker('update');
};
lens.Lens.prototype.setEndTime = function(t) {
this.query_params.time_range.end = t;
this.time_end_elem.find('input').val(
this.time_end_elem.val(
lens.util.timestampToDate(t).strftime('%Y/%m/%d %H:%M'));
this.time_end_elem.datetimepicker('update');
};
......@@ -322,10 +339,17 @@ lens.Lens.prototype.renderPagination = function(logs) {
} else {
this.pagination_next_elem.hide();
}
this.pagination_prev_elem.show();
if (this.query_params.offset + this.query_params.page_size < this.total_results) {
this.pagination_prev_elem.show();
} else {
this.pagination_prev_elem.hide();
}
this.pagination_title_elem.text(
this.query_params.offset + '/' + this.total_results);
// Show "page numbers".
var cur_page = 1 + Math.floor(this.query_params.offset / this.query_params.page_size);
var tot_pages = Math.ceil(this.total_results / this.query_params.page_size);
this.pagination_title_elem.text('' + cur_page + '/' + tot_pages);
this.pagination_div_elem.show();
};
......@@ -394,15 +418,16 @@ lens.Lens.prototype.doSearch = function() {
**/
// Perform the query.
var lensobj = this;
var time_range_str = ('' + this.query_params.time_range.start +
':' + (
(this.query_params.time_range.end > 0)
? this.query_params.time_range.end
: lens.util.timestampNow()));
console.log('Query: ' + JSON.stringify(this.query_params));
var lensobj = this;
var time_range_str = (
'' + Math.floor(this.query_params.time_range.start) +
':' + (
(this.query_params.time_range.end > 0)
? Math.floor(this.query_params.time_range.end)
: lens.util.timestampNow()));
$.ajax({
url: this.search_endpoint,
type: 'POST',
......
......@@ -43,23 +43,11 @@
name="q" id="query_field" size="60"
placeholder="Search...">
<div class="input-group date form_datetime lens-time-start"
data-date="{{ time_from }}">
<input class="form-control" name="time_from"
size="15" type="text" value="" readonly>
<span class="input-group-addon">
<span class="glyphicon glyphicon-th"></span>
</span>
</div>
<input class="form-control form_datetime lens-time-start"
type="text" size="15" name="time_start" readonly>
<div class="input-group date form_datetime lens-time-end"
data-date="{{ time_to }}">
<input class="form-control" name="time_to"
size="15" type="text" value="" readonly>
<span class="input-group-addon">
<span class="glyphicon glyphicon-th"></span>
</span>
</div>
<input class="form-control form_datetime lens-time-end"
type="text" size="15" name="time_end" readonly>
<button type="submit" class="btn btn-default">
<span class="glyphicon glyphicon-search"></span>
......
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