Module Name: src Committed By: tron Date: Sat Aug 21 16:17:40 UTC 2010
Modified Files: src/lib/libutil: parsedate.y Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/lib/libutil/parsedate.y Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libutil/parsedate.y diff -u src/lib/libutil/parsedate.y:1.4 src/lib/libutil/parsedate.y:1.5 --- src/lib/libutil/parsedate.y:1.4 Sun Jan 11 02:57:17 2009 +++ src/lib/libutil/parsedate.y Sat Aug 21 16:17:40 2010 @@ -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;