Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libutil Add support for parsing the data format "@<secon...



details:   https://anonhg.NetBSD.org/src/rev/38056bb4ccda
branches:  trunk
changeset: 757259:38056bb4ccda
user:      tron <tron%NetBSD.org@localhost>
date:      Sat Aug 21 16:17:40 2010 +0000

description:
Add support for parsing the data format "@<seconds since epoch>" e.g.
"@735275209" for "Tue Apr 20 03:06:49 UTC 1993". This change was inspired
by coreutil's "date" utility.

diffstat:

 lib/libutil/parsedate.y |  36 +++++++++++++++++++++++++++++++++++-
 1 files changed, 35 insertions(+), 1 deletions(-)

diffs (67 lines):

diff -r 5a3cd73257e3 -r 38056bb4ccda lib/libutil/parsedate.y
--- a/lib/libutil/parsedate.y   Sat Aug 21 15:37:35 2010 +0000
+++ b/lib/libutil/parsedate.y   Sat Aug 21 16:17:40 2010 +0000
@@ -96,7 +96,7 @@
 }
 
 %token tAGO tDAY tDAYZONE tID tMERIDIAN tMINUTE_UNIT tMONTH tMONTH_UNIT
-%token tSEC_UNIT tSNUMBER tUNUMBER tZONE tDST
+%token tSEC_UNIT tSNUMBER tUNUMBER tZONE tDST AT_SIGN
 
 %type  <Number>        tDAY tDAYZONE tMINUTE_UNIT tMONTH tMONTH_UNIT
 %type  <Number>        tSEC_UNIT tSNUMBER tUNUMBER tZONE
@@ -128,6 +128,11 @@
            yyHaveDate++;
            yyHaveZone++;
        }
+       | epochdate {
+           yyHaveTime++;
+           yyHaveDate++;
+           yyHaveZone++;
+       }
        | number
        ;
 
@@ -144,6 +149,31 @@
        }
        ;
 
+epochdate: AT_SIGN tUNUMBER {
+            time_t    when = $2;
+            struct tm tmbuf;
+            if (gmtime_r(&when, &tmbuf) != NULL) {
+               yyYear = tmbuf.tm_year + 1900;
+               yyMonth = tmbuf.tm_mon + 1;
+               yyDay = tmbuf.tm_mday;
+
+               yyHour = tmbuf.tm_hour;
+               yyMinutes = tmbuf.tm_min;
+               yySeconds = tmbuf.tm_sec;
+           } else {
+               yyYear = 1970;
+               yyMonth = 1;
+               yyDay = 1;
+
+               yyHour = 0;
+               yyMinutes = 0;
+               yySeconds = 0;
+           }
+           yyDSTmode = DSToff;
+           yyTimezone = 0;
+       }
+       ;
+
 time   : tUNUMBER tMERIDIAN {
            yyHour = $1;
            yyMinutes = 0;
@@ -817,6 +847,10 @@
            yyInput--;
            return LookupWord(buff);
        }
+       if (c == '@') {
+           yyInput++;
+           return AT_SIGN;
+       }
        if (c != '(')
            return *yyInput++;
        Count = 0;



Home | Main Index | Thread Index | Old Index