aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/js/RrdTime.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/RrdTime.js')
-rw-r--r--js/RrdTime.js42
1 files changed, 23 insertions, 19 deletions
diff --git a/js/RrdTime.js b/js/RrdTime.js
index 95ea0ae..c1de1fc 100644
--- a/js/RrdTime.js
+++ b/js/RrdTime.js
@@ -25,12 +25,12 @@
25 * RrdTimeError 25 * RrdTimeError
26 * @constructor 26 * @constructor
27 */ 27 */
28var RrdTimeError = function (message) 28var RrdTimeError = function (message)
29{ 29{
30 this.prototype = Error.prototype; 30 this.prototype = Error.prototype;
31 this.name = "RrdTimeError"; 31 this.name = "RrdTimeError";
32 this.message = (message) ? message : "Error"; 32 this.message = (message) ? message : "Error";
33}; 33};
34 34
35/** 35/**
36 * RrdTime 36 * RrdTime
@@ -40,7 +40,7 @@ var RrdTime = function(tspec) /* parser */
40{ 40{
41 var date = new Date(); 41 var date = new Date();
42 var hr = 0; 42 var hr = 0;
43 43
44 this.tspec = tspec; 44 this.tspec = tspec;
45 45
46 this.tokens = (tspec+'').match(/[0-9]+|[A-Za-z]+|[:.+-\/]/g); 46 this.tokens = (tspec+'').match(/[0-9]+|[A-Za-z]+|[:.+-\/]/g);
@@ -70,18 +70,20 @@ var RrdTime = function(tspec) /* parser */
70 break; /* jump to OFFSET-SPEC part */ 70 break; /* jump to OFFSET-SPEC part */
71 case RrdTime.EPOCH: 71 case RrdTime.EPOCH:
72 this.type = RrdTime.RELATIVE_TO_EPOCH; 72 this.type = RrdTime.RELATIVE_TO_EPOCH;
73 /* falls through */
73 case RrdTime.START: 74 case RrdTime.START:
74 case RrdTime.END: 75 case RrdTime.END:
75 if (this.tokid === RrdTime.EPOCH) 76 if (this.tokid === RrdTime.EPOCH)
76 this.type = RrdTime.RELATIVE_TO_START_TIME; 77 this.type = RrdTime.RELATIVE_TO_START_TIME;
77 else 78 else
78 this.type = RrdTime.RELATIVE_TO_END_TIME; 79 this.type = RrdTime.RELATIVE_TO_END_TIME;
79 this.tm_sec = 0; 80 this.tm_sec = 0;
80 this.tm_min = 0; 81 this.tm_min = 0;
81 this.tm_hour = 0; 82 this.tm_hour = 0;
82 this.tm_mday = 0; 83 this.tm_mday = 0;
83 this.tm_mon = 0; 84 this.tm_mon = 0;
84 this.tm_year = 0; 85 this.tm_year = 0;
86 /* falls through */
85 case RrdTime.NOW: 87 case RrdTime.NOW:
86 var time_reference = this.tokid; 88 var time_reference = this.tokid;
87 this.gettok(); 89 this.gettok();
@@ -126,8 +128,10 @@ var RrdTime = function(tspec) /* parser */
126 break; 128 break;
127 case RrdTime.TEATIME: 129 case RrdTime.TEATIME:
128 hr += 4; 130 hr += 4;
131 /* falls through */
129 case RrdTime.NOON: 132 case RrdTime.NOON:
130 hr += 12; 133 hr += 12;
134 /* falls through */
131 case RrdTime.MIDNIGHT: 135 case RrdTime.MIDNIGHT:
132 this.tm_hour = hr; 136 this.tm_hour = hr;
133 this.tm_min = 0; 137 this.tm_min = 0;
@@ -137,7 +141,6 @@ var RrdTime = function(tspec) /* parser */
137 break; 141 break;
138 default: 142 default:
139 throw new RrdTimeError("unparsable time: "+this.token+" "+this.sct); 143 throw new RrdTimeError("unparsable time: "+this.token+" "+this.sct);
140 break;
141 } /* ugly case statement */ 144 } /* ugly case statement */
142 145
143 /* 146 /*
@@ -303,7 +306,7 @@ RrdTime.RELATIVE_TO_START_TIME = 1;
303RrdTime.RELATIVE_TO_END_TIME = 2; 306RrdTime.RELATIVE_TO_END_TIME = 2;
304RrdTime.RELATIVE_TO_EPOCH = 3; 307RrdTime.RELATIVE_TO_EPOCH = 3;
305 308
306RrdTime.prototype.gettok = function () 309RrdTime.prototype.gettok = function ()
307{ 310{
308 if (this.tokidx >= this.toklen) { 311 if (this.tokidx >= this.toklen) {
309 this.tokid = RrdTime.EOF; 312 this.tokid = RrdTime.EOF;
@@ -332,7 +335,7 @@ RrdTime.prototype.gettok = function ()
332 return this.tokid; 335 return this.tokid;
333}; 336};
334 337
335RrdTime.prototype.plus_minus = function (doop) 338RrdTime.prototype.plus_minus = function (doop)
336{ 339{
337 var op = RrdTime.PLUS; 340 var op = RrdTime.PLUS;
338 var prev_multiplier = -1; 341 var prev_multiplier = -1;
@@ -377,6 +380,7 @@ RrdTime.prototype.plus_minus = function (doop)
377 return; 380 return;
378 case RrdTime.WEEKS: 381 case RrdTime.WEEKS:
379 delta *= 7; 382 delta *= 7;
383 /* falls through */
380 case RrdTime.DAYS: 384 case RrdTime.DAYS:
381 this.tm_mday += ( op == RrdTime.PLUS) ? delta : -delta; 385 this.tm_mday += ( op == RrdTime.PLUS) ? delta : -delta;
382 return; 386 return;
@@ -446,12 +450,12 @@ RrdTime.prototype.tod = function() /* tod() computes the time of day (TIME-OF-DA
446 this.tm_min = minute; 450 this.tm_min = minute;
447 this.tm_sec = 0; 451 this.tm_sec = 0;
448 if (this.tm_hour == 24) { 452 if (this.tm_hour == 24) {
449 this.tm_hour = 0; 453 this.tm_hour = 0;
450 this.tm_mday++; 454 this.tm_mday++;
451 } 455 }
452}; 456};
453 457
454RrdTime.prototype.assign_date = function(mday, mon, year) 458RrdTime.prototype.assign_date = function(mday, mon, year)
455{ 459{
456 if (year > 138) { 460 if (year > 138) {
457 if (year > 1970) { 461 if (year > 1970) {
@@ -472,14 +476,14 @@ RrdTime.prototype.assign_date = function(mday, mon, year)
472 this.tm_year = year; 476 this.tm_year = year;
473}; 477};
474 478
475RrdTime.prototype.day = function () 479RrdTime.prototype.day = function ()
476{ 480{
477 var mday = 0, wday, mon, year = this.tm_year; 481 var mday = 0, wday, mon, year = this.tm_year;
478 var tlen;
479 482
480 switch (this.tokid) { 483 switch (this.tokid) {
481 case RrdTime.YESTERDAY: 484 case RrdTime.YESTERDAY:
482 this.tm_mday--; 485 this.tm_mday--;
486 /* falls through */
483 case RrdTime.TODAY: 487 case RrdTime.TODAY:
484 this.gettok(); 488 this.gettok();
485 break; 489 break;
@@ -565,7 +569,7 @@ RrdTime.prototype.day = function ()
565 } 569 }
566}; 570};
567 571
568RrdTime.prototype.localtime = function (tm) 572RrdTime.prototype.localtime = function (tm)
569{ 573{
570 var date = new Date(tm*1000); 574 var date = new Date(tm*1000);
571 this.tm_sec = date.getSeconds(); 575 this.tm_sec = date.getSeconds();
@@ -577,13 +581,13 @@ RrdTime.prototype.localtime = function (tm)
577 this.tm_wday = date.getDay(); 581 this.tm_wday = date.getDay();
578}; 582};
579 583
580RrdTime.prototype.mktime = function() 584RrdTime.prototype.mktime = function()
581{ 585{
582 var date = new Date(this.tm_year+1900, this.tm_mon, this.tm_mday, this.tm_hour, this.tm_min, this.tm_sec); 586 var date = new Date(this.tm_year+1900, this.tm_mon, this.tm_mday, this.tm_hour, this.tm_min, this.tm_sec);
583 return Math.round(date.getTime()/1000.0); 587 return Math.round(date.getTime()/1000.0);
584}; 588};
585 589
586RrdTime.proc_start_end = function(start_t, end_t) 590RrdTime.proc_start_end = function(start_t, end_t)
587{ 591{
588 var start, end; 592 var start, end;
589 593