+
+ const dow = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
+ const mn = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
+
+ function getcombx(tmin, tmax) {
+ var comb = [], lb = [];
+ var trange = tmax - tmin;
+ var inc, inc2, base, base2, t, dt, zoff;
+ var label = function(t) { return "<<" + t.toFixed(1) + ">>"; }
+ function tohour(t) { var dt = new Date(t*1000); return dt.getHours(); }
+ function todow(t) { var dt = new Date(t*1000); return dow[dt.getDay()]; }
+ function todom(t) { var dt = new Date(t*1000); return dt.getDate(); }
+ function tomonth(t) { var dt = new Date(t*1000); return mn[dt.getMonth()]; }
+
+ if (trange < 172800) { /* two days -> one hour */
+ inc = 3600;
+ inc2 = 21600;
+ label = tohour;
+ }
+ else if (trange < 864000) { /* 10 days -> six hours */
+ inc = 21600;
+ inc2 = 86400;
+ label = todow;
+ }
+ else if (trange < 2678400) { /* 31 days -> 1 day */
+ inc = 86400;
+ inc2 = 86400;
+ label = todom;
+ }
+ else { /* ~ one month */
+ /* TODO: make this a separate case with loop over months rather than
+ fixed number of seconds. */
+ inc = 86400;
+ inc2 = 2592000;
+ label = tomonth;
+ }
+
+ dt = new Date(tmin*1000);
+ zoff = 60 * dt.getTimezoneOffset();
+ base = (Math.floor((tmin - zoff - 1) / inc) + 1) * inc + zoff;
+ for (t = base; t < tmax; t += inc)
+ comb.push(t);
+ base2 = (Math.floor((tmin - zoff - 1) / inc2) + 1) * inc2 + zoff;
+ for (t = base2; t < tmax; t += inc2)
+ lb.push([t, label(t)]);
+ //dbg.innerHTML = "inc=" + inc + "<br>inc2=" + inc2 + "<br>"
+ // + "tmin=" + tmin + " tmax=" + tmax + "<br>"
+ // + "base=" + base + " base2=" + base2 + "<br>"
+ // + comb + "<br>" + lb;
+ return [comb, lb];
+ }
+