Index | Thread | Search

From:
Christian Weisgerber <naddy@mips.inka.de>
Subject:
Re: strftime.3: clarify %G and %g description
To:
"Todd C. Miller" <Todd.Miller@sudo.ws>
Cc:
Theo Buehler <tb@theobuehler.org>, tech@openbsd.org, Ingo Schwarze <schwarze@openbsd.org>, Lucas Gabriel Vuotto <lucas@sexy.is>
Date:
Wed, 24 Apr 2024 19:58:53 +0200

Download raw body.

Thread
Todd C. Miller:

> How about this?  Some of the wording is from the upstream version.

> --- strftime.3	16 May 2019 13:35:17 -0000	1.38
> +++ strftime.3	24 Apr 2024 14:29:06 -0000
> @@ -111,10 +111,20 @@ is replaced by the date in the format
>  is replaced by the
>  .St -iso8601
>  year with century as a decimal number.
> +See also the
> +.Cm \&%V
> +conversion specification and the
> +.Sx STANDARDS
> +section for more details.

This still fails to alert the unwary.

You want to turn a time_t value into a Gregorian calendar year and
go through the list of specifiers.  You want %Y, but you don't know
that, and it's easy to stop at %G.  I think that happened to stsp@.
I handled the same code, but didn't notice--possibly I checked the
man page and mistook %G for an alias of %Y.  The reference to
ISO 8601 is opaque as that standard specifies all sorts of things,
e.g., the YYYY-MM-DD format.

Wikipedia uses the term "ISO week-numbering year", so this is both
pedantically correct and, I hope, sufficiently weird to warn the
reader:

diff refs/heads/master refs/heads/local
commit - 19e99d061340840dc52e10ae9c02d78a0a455689
commit + 00b4e1d44178992b06f5a333a6ae9106be408cfa
blob - a2adf880bbe93ed8e05dc6b6d77989ea842152a9
blob + b83f800a89fde368fc7b0f428a8a4e2acc800c01
--- lib/libc/time/strftime.3
+++ lib/libc/time/strftime.3
@@ -110,11 +110,21 @@ is replaced by the date in the format
 .It Cm \&%G
 is replaced by the
 .St -iso8601
-year with century as a decimal number.
+week-numbering year with century as a decimal number.
+See also the
+.Cm \&%V
+conversion specification and the
+.Sx STANDARDS
+section for more details.
 .It Cm \&%g
 is replaced by the
 .St -iso8601
-year without century as a decimal number (00\-99).
+week-numbering year without century as a decimal number (00\-99).
+See also the
+.Cm \&%V
+conversion specification and the
+.Sx STANDARDS
+section for more details.
 .It Cm \&%H
 is replaced by the hour (24-hour clock) as a decimal number (00\-23).
 .It Cm \&%I
@@ -169,6 +179,12 @@ the week) as a decimal number (01\-53).
 If the week containing January
 1 has four or more days in the new year, then it is week 1; otherwise
 it is week 53 of the previous year, and the next week is week 1.
+The year is given by the
+.Cm \&%G
+conversion specification.
+See the
+.Sx STANDARDS
+section for more details.
 .It Cm \&%v
 is replaced by the date in the format
 .Dq Li "%e-%b-%Y" .
-- 
Christian "naddy" Weisgerber                          naddy@mips.inka.de