From 77c3cb50fb529740c57908cc5f0655fba0257c91 Mon Sep 17 00:00:00 2001 From: Ori Bernstein Date: Tue, 22 Sep 2020 19:21:51 -0700 Subject: [PATCH 1/2] libc: make yday 0-based, as docs suggest Tm.yday is docuemnted as being 0-based, and our new api should respect that. Fix the code so that this is true. --- sys/src/libc/port/date.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/src/libc/port/date.c b/sys/src/libc/port/date.c index 44ae15696..1c90a7985 100644 --- a/sys/src/libc/port/date.c +++ b/sys/src/libc/port/date.c @@ -330,7 +330,7 @@ tmfill(Tm *tm, vlong abs, vlong nsec) if(d < 0) d += mdays[m - 1]; - tm->yday = d; + tm->yday = d - 1; for(i = 0; i < m - 1; i++) tm->yday += mdays[i]; if(m > 1 && isleap(y)) From 9f8d62ab644553b11286dbcd283db56c83d6ebdd Mon Sep 17 00:00:00 2001 From: Ori Bernstein Date: Tue, 22 Sep 2020 19:24:01 -0700 Subject: [PATCH 2/2] libc: ignore '?' in date format strings Ignoring '?' when formatting date strings allows the format strings to be reused for parsing. This is convenient, since we don't need to duplicate the format strings. --- sys/man/2/tmdate | 7 ++++--- sys/src/libc/port/date.c | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/sys/man/2/tmdate b/sys/man/2/tmdate index e4123c3e1..ba5c4441a 100644 --- a/sys/man/2/tmdate +++ b/sys/man/2/tmdate @@ -134,8 +134,7 @@ For example, will format to a width of 3. When parsing, this acts as whitespace. .TP .B ? -When parsing, this makes the following argument match fuzzily. -Fuzzy matching means that all formats are tried, from most to least specific. +When parsing, all formats of the following argument are tried from most to least specific. For example, .I ?M will match @@ -144,7 +143,9 @@ will match .IR 01 , and .IR 1 , -in that order of preference. +in that order. When formatting, +.B ? +is ignored. .TP .B ~ When parsing a date, this slackens range enforcement, accepting diff --git a/sys/src/libc/port/date.c b/sys/src/libc/port/date.c index 1c90a7985..7be6cb52f 100644 --- a/sys/src/libc/port/date.c +++ b/sys/src/libc/port/date.c @@ -428,6 +428,9 @@ static int switch(c0){ case 0: break; + /* Ignore '?' so we can share parse and format strings */ + case '?': + continue; case 'Y': switch(w){ case 1: n += fmtprint(f, "%*d", pad, tm->year + 1900); break;