code: regress

Download patch

ref: ef4281a5027fe3aeff75fb4017a4078e395cdab2
parent: fae865e8a1013e2756b5053e680160eabf92febf
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Sep 22 22:15:06 EDT 2020

date: check for expected time ranges.

--- a/libc/date.c
+++ b/libc/date.c
@@ -47,6 +47,15 @@
 }
 
 void
+rangechk(vlong sec, char *s, vlong val, vlong lo, vlong hi)
+{
+	if(val < lo || val > hi){
+		fprint(2, "%lld: %s: expected %lld <= %lld <= %lld", sec, s, lo, val, hi);
+		failed++;
+	}
+}
+
+void
 main(int, char **)
 {
 	Tm tm, tt;
@@ -75,6 +84,19 @@
 	     sysfatal("get time: %r\n");
 	if(tmtime(&there, tmnorm(&here), zp) == nil)
 	     sysfatal("shift time: %r\n");
+
+	for(i = 0; i < 1600826575; i += 3613){
+		tmtime(&tm, i, nil);
+		rangechk(i, "nsec", tm.nsec, 0, 1e9);
+		rangechk(i, "sec", tm.sec, 0, 59);
+		rangechk(i, "min", tm.min, 0, 59);
+		rangechk(i, "hour", tm.hour, 0, 23);
+		rangechk(i, "mday", tm.mday, 1, 31);
+		rangechk(i, "mon", tm.mon, 0, 11);
+		rangechk(i, "year", tm.year, 69 ,120);
+		rangechk(i, "wday", tm.wday, 0, 6);
+		rangechk(i, "yday", tm.yday, 0, 365);
+	}
 
 	tmtime(&tm, 1586574870, gmt);
 	testtm("tmtime-gmt", 2020, 3, 11, 3, 14, 30, 0, &tm);