Skip to content

Commit 1f1a5f6

Browse files
committed
Fix - correctly decode time offest
1 parent 53f7ab0 commit 1f1a5f6

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

scripts/JSRootPainter.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -598,19 +598,30 @@
598598
var idF = axis.fTimeFormat.indexOf('%F');
599599
if (idF < 0) return JSROOT.gStyle.TimeOffset;
600600
var sof = axis.fTimeFormat.substr(idF + 2);
601-
if (sof == '1995-01-01 00:00:00s0') return 788918400000;
601+
// default string in axis offset
602+
if (sof.indexOf('1995-01-01 00:00:00s0')==0) return 788918400000;
602603
// special case, used from DABC painters
603604
if ((sof == "0") || (sof == "")) return 0;
604605

605606
// decode time from ROOT string
606-
var dt = new Date(0);
607-
var pos = sof.indexOf("-"); dt.setFullYear(sof.substr(0,pos)); sof = sof.substr(pos+1);
608-
pos = sof.indexOf("-"); dt.setMonth(parseInt(sof.substr(0,pos))-1); sof = sof.substr(pos+1);
609-
pos = sof.indexOf(" "); dt.setDate(sof.substr(0,pos)); sof = sof.substr(pos+1);
610-
pos = sof.indexOf(":"); dt.setHours(sof.substr(0,pos)); sof = sof.substr(pos+1);
611-
pos = sof.indexOf(":"); dt.setMinutes(sof.substr(0,pos)); sof = sof.substr(pos+1);
612-
pos = sof.indexOf("s"); dt.setSeconds(sof.substr(0,pos));
613-
if (pos>0) { sof = sof.substr(pos+1); dt.setMilliseconds(sof); }
607+
function next(separ, min, max) {
608+
var pos = sof.indexOf(separ);
609+
if (pos < 0) { pos = ""; return min; }
610+
var val = parseInt(sof.substr(0,pos));
611+
sof = sof.substr(pos+1);
612+
if (isNaN(val) || (val<min) || (val>max)) { pos = ""; return min; }
613+
return val;
614+
}
615+
616+
var year = next("-", 1970, 2300),
617+
month = next("-", 1, 12) - 1,
618+
day = next(" ", 1, 31),
619+
hour = next(":", 0, 23),
620+
min = next(":", 0, 59),
621+
sec = next("s", 0, 59),
622+
msec = next(" ", 0, 999);
623+
624+
var dt = new Date(Date.UTC(year, month, day, hour, min, sec, msec));
614625
return dt.getTime();
615626
}
616627

0 commit comments

Comments
 (0)