ref: 0850c5b8bb1562625f822fe7b4e7c0da5f5b28f7
parent: 92a6483fc287984ca6b5c40c480f7d7d0c7b5fc7
author: Ori Bernstein <[email protected]>
date: Wed Aug 26 15:15:02 EDT 2020
add test for stray spaces
--- a/libc/date.c
+++ b/libc/date.c
@@ -131,7 +131,7 @@
fail("failed parse: %r\n");
testtm("parse-notz3", 1970, 0, 1, 0, 0, 0, 0, &tm);
- if(tmparse(&tm, "YYYY MMMM DD WW hh:mm:ss", "2020 April 10 Friday 16:04:00", gmt, nil) == nil)
+ if(tmparse(&tm, "YYYY MMMM DD WWW hh:mm:ss", "2020 April 10 Friday 16:04:00", gmt, nil) == nil)
sysfatal("failed parse: %r\n");
testtm("parse-notz4", 2020, 3, 10, 16, 4, 0, 0, &tm);
@@ -191,7 +191,11 @@
fail("failed leap year feb 29: %r\n");
testtm("parse-leapfeb", 2020, 1, 29, 20, 14, 30, 0, &tm);
if(tmparse(&tm, "YYYY MM DD hh:mm:ss Z", "2021 02 29 20:14:30 -0400", nil, nil) != nil)
+
fail("incorrectly accepted non-leap year feb 29\n");
+ /* stray spaces */
+ if(tmparse(&tm, "YYYY MM DD hh:mm:ss Z", " 2020 02 29 20:14:30 -0400 ", nil, nil) == nil)
+ fail("failed leap year feb 29: %r\n");
/* lots of round trips: Jan 1960 => Jun 2020, in almost-11 day increments */
for(i = -315619200; i < 1592179806; i += 23*3600 + 1732){
@@ -199,9 +203,9 @@
fail("load time %d\n", i);
if(tmnorm(&tm) != i)
fail("wrong load time: %d\n", i);
- if(snprint(buf, sizeof(buf), "%τ", tmfmt(&tm, "W MMM DD hh:mm:ss Z YYYY")) == -1)
+ if(snprint(buf, sizeof(buf), "%τ", tmfmt(&tm, "WW MMM DD hh:mm:ss Z YYYY")) == -1)
fail("format: %r\n");
- if(tmparse(&tt, "W MMM DD hh:mm:ss Z YYYY", buf, nil, nil) == nil)
+ if(tmparse(&tt, "WW MMM DD hh:mm:ss Z YYYY", buf, nil, nil) == nil)
fail("parse: %r\n");
if(tmnorm(&tm) != tmnorm(&tt))
fail("parse: wrong time (%lld != %lld)\n", tmnorm(&tm), tmnorm(&tt));
@@ -213,9 +217,9 @@
fail("load time %d\n", i);
if(tmnorm(&tm) != i)
fail("wrong load time: %d\n", i);
- if(snprint(buf, sizeof(buf), "%τ", tmfmt(&tm, "W MMM DD hh:mm:ss Z YYYY")) == -1)
+ if(snprint(buf, sizeof(buf), "%τ", tmfmt(&tm, "WW MMM DD hh:mm:ss Z YYYY")) == -1)
fail("format: %r\n");
- if(tmparse(&tt, "W MMM DD hh:mm:ss Z YYYY", buf, us_arizona, nil) == nil)
+ if(tmparse(&tt, "WW MMM DD hh:mm:ss Z YYYY", buf, us_arizona, nil) == nil)
fail("parse: %r\n");
if(tmnorm(&tm) != tmnorm(&tt))
fail("parse: wrong time (%lld != %lld)\n", tmnorm(&tm), tmnorm(&tt));
@@ -226,13 +230,13 @@
if(tmtime(&tm, -624623143, nil) == nil)
fail("tmtime: %r");
- if(snprint(buf, sizeof(buf), "%τ", tmfmt(&tm, "W, DD MMM YYYY hh:mm:ss Z")) == -1)
+ if(snprint(buf, sizeof(buf), "%τ", tmfmt(&tm, "WW, DD MMM YYYY hh:mm:ss Z")) == -1)
fail("format: %r");
if(strcmp(buf, "Fri, 17 Mar 1950 13:34:17 +0000") != 0)
fail("wrong output: %s\n", buf);
if(tmtime(&tm, -624623143, us_eastern) == nil)
fail("tmtime: %r");
- if(snprint(buf, sizeof(buf), "%τ", tmfmt(&tm, "W, DD MMM YYYY hh:mm:ss Z")) == -1)
+ if(snprint(buf, sizeof(buf), "%τ", tmfmt(&tm, "WW, DD MMM YYYY hh:mm:ss Z")) == -1)
fail("format: %r");
if(strcmp(buf, "Fri, 17 Mar 1950 08:34:17 -0500") != 0)
fail("wrong output: %s\n", buf);
@@ -258,7 +262,7 @@
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) == nil)
+ if(tmparse(&tm, "WW MMM D hh:mm:ss ZZZ YYYY", buf, nil, nil) == nil)
fail("parse: %r\n");
if(tmnorm(&tm) != 1520733600)
fail("round trip timezone: %lld != 1520733600\n", tmnorm(&tm));
@@ -269,7 +273,7 @@
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) == nil)
+ if(tmparse(&tm, "WW MMM D hh:mm:ss ZZZ YYYY", buf, nil, nil) == nil)
fail("parse: %r");
if(tmnorm(&tm) != 1541296800)
fail("round trip timezone: %lld != 1541296800\n", tmnorm(&tm));