Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
fix for timezone regression Issue rashidkpc#156
Browse files Browse the repository at this point in the history
  • Loading branch information
Rashid Khan authored and Rashid Khan committed Nov 14, 2012
1 parent f685f56 commit 25f31b1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
29 changes: 17 additions & 12 deletions static/lib/js/ajax.js
Expand Up @@ -422,7 +422,6 @@ function getAnalysis() {
for (var x in remain) { r += remain[x].data; }
data = data.slice(0,window.graph_colors.length)
data.push({ label: "The Rest", data: r, color: '#AAA' })
console.log(r)
pieChart(data,'#piechart')

break;
Expand Down Expand Up @@ -555,7 +554,6 @@ function termsTable(resultjson) {
for (var obj in resultjson.facets.terms.terms) {
var object = resultjson.facets.terms.terms[obj];
var metric = {};
console.log(window.graph_colors.length)
var color = i < window.graph_colors.length ?
" <i class=icon-sign-blank style='color:"+window.graph_colors[i]+"'><i>" : '';

Expand Down Expand Up @@ -1103,22 +1101,25 @@ function datepickers(from,to) {
"<button id='timechange' class='btn btn-small jlink' " +
"style='visibility: hidden'> filter</button></div>");

var from_date = utc_date_obj(new Date(from - tOffset))
var to_date = utc_date_obj(new Date(to - tOffset));
$('#timefrom').datetimeEntry({
maxDatetime : new Date(to - tOffset),
maxDatetime : to_date,
datetimeFormat: 'Y-O-D H:M:S',
spinnerImage: ''
});
$('#timefrom').datetimeEntry('setDatetime',new Date(from-tOffset))
$('#timefrom').datetimeEntry('setDatetime',from_date)

$('#timeto').datetimeEntry({
minDatetime: $('#timefrom').datetimeEntry('getDatetime'),
maxDatetime: new Date(),
maxDatetime: utc_date_obj(new Date()),
datetimeFormat: 'Y-O-D H:M:S',
spinnerImage: ''
},to);
$('#timeto').datetimeEntry('setDatetime',new Date(to-tOffset))
$('#timeto').datetimeEntry('setDatetime',to_date)


// LOL Wat? o_from and o_to are globals?!
$('#timefrom,#timeto').datepicker({
format: 'yyyy-mm-dd'
}).on('show', function(ev) {
Expand All @@ -1132,6 +1133,9 @@ function datepickers(from,to) {
function renderDateTimePicker(from, to, force) {
$('.datepicker').remove()

from = from + tOffset
to = to + tOffset

if (!$('#timechange').length || force == true) {

datepickers(from,to)
Expand Down Expand Up @@ -1208,9 +1212,10 @@ function renderDateTimePicker(from, to, force) {

function field_time(selector) {
var tz_offset = int_to_tz(window.tOffset);
return ISODateString(
new Date($(selector).datetimeEntry('getDatetime').getTime() + tOffset)
var str = ISODateString(
new Date($(selector).datetimeEntry('getDatetime').getTime())
) + tz_offset;
return str;
}


Expand Down Expand Up @@ -1278,11 +1283,11 @@ function logGraph(data, interval, metric) {
$('#graph').bind("plotselected", function (event, ranges) {
if (!intset) {
intset = true;
var from = utc_date_obj(new Date(parseInt(ranges.xaxis.from.toFixed(0))))
var to = utc_date_obj(new Date(parseInt(ranges.xaxis.to.toFixed(0))))
var time = {
"from": ISODateString(
parseInt(ranges.xaxis.from.toFixed(0)))+int_to_tz(window.tOffset),
"to": ISODateString(
parseInt(ranges.xaxis.to.toFixed(0)))+int_to_tz(window.tOffset)
"from": ISODateString(from)+int_to_tz(window.tOffset),
"to": ISODateString(to)+int_to_tz(window.tOffset)
};
window.hashjson.offset = 0;
window.hashjson.time = time;
Expand Down
21 changes: 14 additions & 7 deletions static/lib/js/shared.js
Expand Up @@ -286,23 +286,30 @@ function ISODateString(d) {
function pad(n) {
return n < 10 ? '0' + n : n
}
return d.getUTCFullYear() + '-' +
pad(d.getUTCMonth() + 1) + '-' +
pad(d.getUTCDate()) + 'T' +
pad(d.getUTCHours()) + ':' +
pad(d.getUTCMinutes()) + ':' +
pad(d.getUTCSeconds());
return d.getFullYear() + '-' +
pad(d.getMonth() + 1) + '-' +
pad(d.getDate()) + 'T' +
pad(d.getHours()) + ':' +
pad(d.getMinutes()) + ':' +
pad(d.getSeconds());
}

function pickDateString(d) {
return dateFormat(d,'yyyy-mm-dd HH:MM:ss')
}

function prettyDateString(d) {
d = new Date(parseInt(d - window.tOffset));
d = new Date(parseInt(d));
d = utc_date_obj(d);
return dateFormat(d,window.time_format);
}

function utc_date_obj(d) {
return new Date(
d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(),
d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds());
}

function is_int(value) {
if ((parseFloat(value) == parseInt(value)) && !isNaN(value)) {
return true;
Expand Down

0 comments on commit 25f31b1

Please sign in to comment.