Module Name:    src
Committed By:   riz
Date:           Sun Nov 21 20:38:38 UTC 2010

Modified Files:
        src/lib/libutil [netbsd-5]: parsedate.3 parsedate.y

Log Message:
Pull up following revision(s) (requested by tron in ticket #1443):
        lib/libutil/parsedate.3: revision 1.7
        lib/libutil/parsedate.y: revision 1.5
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.
Mention recent enhancement and not that this function is neither
re-entrant nor thread-safe.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.4.6.1 src/lib/libutil/parsedate.3
cvs rdiff -u -r1.3 -r1.3.4.1 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.3
diff -u src/lib/libutil/parsedate.3:1.4 src/lib/libutil/parsedate.3:1.4.6.1
--- src/lib/libutil/parsedate.3:1.4	Wed Apr 30 13:10:52 2008
+++ src/lib/libutil/parsedate.3	Sun Nov 21 20:38:38 2010
@@ -1,4 +1,4 @@
-.\"     $NetBSD: parsedate.3,v 1.4 2008/04/30 13:10:52 martin Exp $
+.\"     $NetBSD: parsedate.3,v 1.4.6.1 2010/11/21 20:38:38 riz Exp $
 .\"
 .\" Copyright (c) 2006 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd November 17, 2006
+.Dd Aug 28, 2010
 .Dt PARSEDATE 3
 .Os
 .Sh NAME
@@ -228,6 +228,12 @@
 .It next sunday
 .It +2 years
 .El
+.Pp
+Seconds since epoch (also known as UNIX time) are also supported:
+.Bl -tag -compact -width "@735275209"
+.It @735275209
+Tue Apr 20 03:06:49 UTC 1993
+.El
 .Sh RETURN VALUES
 .Fn parsedate
 returns the number of seconds passed since the Epoch, or
@@ -236,6 +242,8 @@
 .Sh SEE ALSO
 .Xr date 1 ,
 .Xr eeprom 8
+.Sh BUGS
+The parsedate function is not re-entrant or thread-safe.
 .Sh HISTORY
 The parser used in
 .Fn parsedate

Index: src/lib/libutil/parsedate.y
diff -u src/lib/libutil/parsedate.y:1.3 src/lib/libutil/parsedate.y:1.3.4.1
--- src/lib/libutil/parsedate.y:1.3	Thu Jul 17 16:24:55 2008
+++ src/lib/libutil/parsedate.y	Sun Nov 21 20:38:38 2010
@@ -100,7 +100,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
@@ -132,6 +132,11 @@
 	    yyHaveDate++;
 	    yyHaveZone++;
 	}
+	| epochdate {
+	    yyHaveTime++;
+	    yyHaveDate++;
+	    yyHaveZone++;
+	}
 	| number
 	;
 
@@ -148,6 +153,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;
@@ -821,6 +851,10 @@
 	    yyInput--;
 	    return LookupWord(buff);
 	}
+	if (c == '@') {
+	    yyInput++;
+	    return AT_SIGN;
+	}
 	if (c != '(')
 	    return *yyInput++;
 	Count = 0;

Reply via email to