[PATCH] introduce "epoch" as base time reference

"Peter Stamfest" <[email protected]>
Newsgroups gmane.comp.db.rrdtool.devel
Message-ID <OF72739600.FC085FBC-ONC12577CB.0024CF85-C12577CB.00253586@domino.stamfest.net>
Hello!

Find attached a patch that introduces "epoch" as a new base time 
reference, meaning timestamp 0.

I use it to disambiguate between some "at-style" time specs:

eg: 

11111111 yields an error message:

did you really mean month 1111111?

and 

19711205 denotes Dec 12, 1971 and not the timestamp.



The patch allows to write:

epoch+11111111s or epoch+19711205s

which fixes both problems.

The patch also updates documentation in rrdfetch.pod

peter

_______________________________________________
rrd-developers mailing list
[email protected]
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-developers
introduce-epoch.patch (application/octet-stream, 2.7 KB)
diff -ur rrdtool-1.4.4.002139/doc/rrdfetch.pod rrdtool-1.4.4.002139-fixed/doc/rrdfetch.pod
--- rrdtool-1.4.4.002139/doc/rrdfetch.pod	2008-09-25 17:25:51.000000000 +0200
+++ rrdtool-1.4.4.002139-fixed/doc/rrdfetch.pod	2010-10-29 08:25:06.000000000 +0200
@@ -158,11 +158,16 @@
 I<NOTE2>: if you specify the I<day> in this way, the I<time-of-day> is
 REQUIRED as well.
 
-Finally, you can use the words B<now>, B<start>, or B<end> as your time
+Finally, you can use the words B<now>, B<start>, B<end> or B<epoch> as your time
 reference. B<Now> refers to the current moment (and is also the default
 time reference). B<Start> (B<end>) can be used to specify a time
 relative to the start (end) time for those tools that use these
-categories (B<rrdfetch>, L<rrdgraph>).
+categories (B<rrdfetch>, L<rrdgraph>) and B<epoch> indicates the 
+*IX epoch (*IX timestamp 0 = 1970-01-01 00:00:00 UTC). B<epoch> is
+useful to disambiguate between a timestamp value and some forms
+of abbreviated date/time specifications, because it allows to use 
+time offset specifications using units, eg. B<epoch>+19711205s unambiguously
+denotes timestamp 19711205 and not 1971-12-05 00:00:00 UTC.
 
 Month and day of the week names can be used in their naturally
 abbreviated form (e.g., Dec for December, Sun for Sunday, etc.). The
diff -ur rrdtool-1.4.4.002139/src/rrd.h rrdtool-1.4.4.002139-fixed/src/rrd.h
--- rrdtool-1.4.4.002139/src/rrd.h	2010-07-05 17:38:22.000000000 +0200
+++ rrdtool-1.4.4.002139-fixed/src/rrd.h	2010-10-29 07:00:08.000000000 +0200
@@ -270,7 +270,8 @@
     typedef enum {
         ABSOLUTE_TIME,
         RELATIVE_TO_START_TIME,
-        RELATIVE_TO_END_TIME
+        RELATIVE_TO_END_TIME,
+        RELATIVE_TO_EPOCH
     } rrd_timetype_t;
 
 #define TIME_OK NULL
diff -ur rrdtool-1.4.4.002139/src/rrd_parsetime.c rrdtool-1.4.4.002139-fixed/src/rrd_parsetime.c
--- rrdtool-1.4.4.002139/src/rrd_parsetime.c	2008-11-18 18:19:17.000000000 +0100
+++ rrdtool-1.4.4.002139-fixed/src/rrd_parsetime.c	2010-10-29 06:59:26.000000000 +0200
@@ -124,7 +124,7 @@
 
 enum {                  /* symbols */
     MIDNIGHT, NOON, TEATIME,
-    PM, AM, YESTERDAY, TODAY, TOMORROW, NOW, START, END,
+    PM, AM, YESTERDAY, TODAY, TOMORROW, NOW, START, END, EPOCH,
     SECONDS, MINUTES, HOURS, DAYS, WEEKS, MONTHS, YEARS,
     MONTHS_MINUTES,
     NUMBER, PLUS, MINUS, DOT, COLON, SLASH, ID, JUNK,
@@ -157,6 +157,7 @@
     {"s", START},
     {"end", END},
     {"e", END},
+    {"epoch", EPOCH},
 
     {"jan", JAN},
     {"feb", FEB},
@@ -859,6 +860,9 @@
     case MINUS:
         break;          /* jump to OFFSET-SPEC part */
 
+    case EPOCH:
+        ptv->type = RELATIVE_TO_EPOCH;
+        goto KeepItRelative;
     case START:
         ptv->type = RELATIVE_TO_START_TIME;
         goto KeepItRelative;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.