shithub: regress

Download patch

ref: 814dce91ef582a850d1bdc5464cebe1091559b55
parent: ef3d02cda8c74294c9461c0ef45497781a118d63
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Jun 19 22:34:31 EDT 2020

More date tests

--- a/cmd/date.rc
+++ b/cmd/date.rc
@@ -38,7 +38,8 @@
 check '2020-06-14'			1592092800
 check '2020-06-14T22:14:17-07:00'	1592198057
 
-# colloquial american formats (eww)
+# colloquial american format (eww)
 check '06/14/2020'			1592092800
+check '06/01/2020'			1590969600
 
 exit ''
--- a/libc/date.c
+++ b/libc/date.c
@@ -53,8 +53,8 @@
 	Tzone *gmt, *us_arizona, *us_eastern;
 	Tm here, there;
 	Tzone *zl, *zp;
-	char buf[1024];
-	int i;
+	char buf[128], buf1[128];
+	int i, h;
 
 	tmfmtinstall();
 	if((gmt = tmgetzone("GMT")) == nil)
@@ -208,6 +208,44 @@
 		fail("format: %r");
 	if(strcmp(buf, "Fri, 17 Mar 1950 08:34:17 -0500") != 0)
 		fail("wrong output: %s\n", buf);
+
+	/* AM and PM parsing */
+	for(i = 0; i < 24; i++){
+		h = i % 12;
+		if(h == 0)
+			h = 12;
+		snprint(buf, sizeof(buf), "2021 02 01 %d:14:30 -0400", i);
+		snprint(buf1, sizeof(buf1), "2021 02 01 %d:14:30 -0400 %s", h, (i < 12) ? "AM" : "PM");
+		if(tmparse(&tm, "YYYY MM DD hh:mm:ss ZZZ", buf, nil) == nil)
+			fail("parse: %r\n");
+		if(tmparse(&tt, "YYYY MM DD hh:mm:ss ZZZ A", buf1, nil) == nil)
+			fail("parse: %r\n");
+		if(tm.abs != tt.abs)
+			print("bad am/pm parsed: %s != %s (%lld != %lld)\n", buf, buf1, tm.abs, tt.abs);
+	}
+
+	/* Time zone boundaries: entering DST */
+	if(tmtime(&tm, 1520733600, us_eastern) == nil)
+		fail("tmtime: tz boundary");
+	if(snprint(buf, sizeof(buf), "%τ", tmfmt(&tm, nil)) == -1)
+		fail("format: %r");
+	memset(&tm, 0, sizeof(tm));
+	if(tmparse(&tm, "W MMM D hh:mm:ss ZZZ YYYY", buf, nil) == nil)
+		fail("parse: %r\n");
+	if(tm.abs != 1520733600)
+		fail("round trip timezone: %lld != 1520733600\n", tm.abs);
+
+	/* Time zone boundaries: leaving DST */
+	if(tmtime(&tm, 1541296800, us_eastern) == nil)
+		fail("tmtime: tz boundary");
+	if(snprint(buf, sizeof(buf), "%τ", tmfmt(&tm, nil)) == -1)
+		fail("format: %r\n");
+	memset(&tm, 0, sizeof(tm));
+	if(tmparse(&tm, "W MMM D hh:mm:ss ZZZ YYYY", buf, nil) == nil)
+		fail("parse: %r");
+	if(tm.abs != 1541296800)
+		fail("round trip timezone: %lld != 1541296800\n", tm.abs);
+	
 
 	/* flexible date parsing */
 	if(tmparse(&tm, "?YYYY ?MM DD hh:mm:ss ?ZZZ", "89 04 10 20:14:30 -0400", nil) == nil)
--- a/regress
+++ b/regress
@@ -23,3 +23,13 @@
 
 $O.%:	%.$O $OFILES $LIB
 	$LD $LDFLAGS -o $target $prereq
+
+# [$OS].??* avoids file names like 9.h
+nuke:V:
+	rm -f *.[$OS] y.tab.? lex.yy.c y.debug y.output [$OS].??* *.acid $TARG $CLEANFILES
+
+clean:V:
+	rm -f *.[$OS] *.a[$OS] y.tab.? lex.yy.c y.debug y.output [$OS].??* $TARG $CLEANFILES
+
+%.clean:V:
+	rm -f $stem.[$OS] [$OS].$stem $stem.acid $stem