public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/2] strftime.c, strptime.c: add %i, %q, %v, tests; tweak %Z docs
@ 2022-09-17  5:00 Brian Inglis
  2022-09-17  5:00 ` [PATCH 1/2] strftime.c(__strftime): " Brian Inglis
  2022-09-17  5:00 ` [PATCH 2/2] strptime.c(strptime_l): add %i, %q, %v Brian Inglis
  0 siblings, 2 replies; 9+ messages in thread
From: Brian Inglis @ 2022-09-17  5:00 UTC (permalink / raw)
  To: Newlib

[Please Reply All due to email issues]

newlib/libc/time/strftime.c(strftime): add %i, %q, %v, tests; tweak %Z docs
newlib/libc/time/strptime.c(strptime_l): add %i, %q, %v

%i year in century [00..99] Synonym for "%y". Non-POSIX extension. [tm_year]
%q GNU quarter of the year (from `<<1>>' to `<<4>>') [tm_mon]
%v OSX/Ruby VMS/Oracle date "%d-%b-%Y". Non-POSIX extension. [tm_mday, tm_mon, tm_year]
add %i %q %v tests
%Z clarify current time zone *abbreviation* not "name" [tm_isdst]

Brian Inglis (2):
  strftime.c(__strftime): add %i, %q, %v, tests; tweak %Z docs
  strptime.c(strptime_l): add %i, %q, %v

 newlib/libc/time/strftime.c    | 67 ++++++++++++++++++++++++++++++++--
 newlib/libc/time/strptime.c    | 18 ++++++++-
 2 files changed, 85 insertions(+), 3 deletions(-)

-- 
2.37.2


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/2] strftime.c(__strftime): add %i, %q, %v, tests; tweak %Z docs
  2022-09-17  5:00 [PATCH 0/2] strftime.c, strptime.c: add %i, %q, %v, tests; tweak %Z docs Brian Inglis
@ 2022-09-17  5:00 ` Brian Inglis
       [not found]   ` <BN2P110MB15443B0E0009D450989B3ECF9A4D9@BN2P110MB1544.NAMP110.PROD.OUTLOOK.COM>
  2022-09-17  5:00 ` [PATCH 2/2] strptime.c(strptime_l): add %i, %q, %v Brian Inglis
  1 sibling, 1 reply; 9+ messages in thread
From: Brian Inglis @ 2022-09-17  5:00 UTC (permalink / raw)
  To: Newlib

[-- Attachment #1: Type: text/plain, Size: 481 bytes --]


newlib/libc/time/strftime.c(__strftime):
%i year in century [00..99] Synonym for "%y". Non-POSIX extension. [tm_year]
%q GNU quarter of the year (from `<<1>>' to `<<4>>') [tm_mon]
%v OSX/Ruby VMS/Oracle date "%d-%b-%Y". Non-POSIX extension. [tm_mday, tm_mon, tm_year]
add %i %q %v tests
%Z clarify current time zone *abbreviation* not "name" [tm_isdst]
---
 newlib/libc/time/strftime.c | 67 +++++++++++++++++++++++++++++++++++--
 1 file changed, 64 insertions(+), 3 deletions(-)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-strftime.c-__strftime-add-i-q-v-tests-tweak-Z-docs.patch --]
[-- Type: text/x-patch; name="0001-strftime.c-__strftime-add-i-q-v-tests-tweak-Z-docs.patch", Size: 7077 bytes --]

diff --git a/newlib/libc/time/strftime.c b/newlib/libc/time/strftime.c
index 9c884dca9766..d434c0d0233c 100644
--- a/newlib/libc/time/strftime.c
+++ b/newlib/libc/time/strftime.c
@@ -128,6 +128,9 @@ o %I
 The hour (on a 12-hour clock), formatted with two digits (from
 `<<01>>' to `<<12>>'). [tm_hour]
 
+o %i
+Synonym for "%y". Non-POSIX extension. [tm_year]
+
 o %j
 The count of days in the year, formatted with three digits
 (from `<<001>>' to `<<366>>'). [tm_yday]
@@ -161,6 +164,10 @@ the current locale. [tm_hour]
 o %P
 Same as '<<%p>>', but in lowercase.  This is a GNU extension. [tm_hour]
 
+o %q
+Quarter of the year (from `<<1>>' to `<<4>>'), with January starting
+the first quarter. This is a GNU extension. [tm_mon]
+
 o %r
 Replaced by the time in a.m. and p.m. notation.  In the "C" locale this
 is equivalent to "%I:%M:%S %p".  In locales which don't define a.m./p.m.
@@ -198,6 +205,10 @@ The week number, where weeks start on Monday, week 1 contains January 4th,
 and earlier days are in the previous year.  Formatted with two digits
 (from `<<01>>' to `<<53>>').  See also <<%G>>. [tm_year, tm_wday, tm_yday]
 
+o %v
+A string representing the OSX/Ruby VMS/Oracle date format, in the form
+`<<"%d-%b-%Y">>'. Non-POSIX extension. [tm_mday, tm_mon, tm_year]
+
 o %w
 The weekday as a number, 0-based from Sunday (from `<<0>>' to `<<6>>').
 [tm_wday]
@@ -235,9 +246,9 @@ savings offset for the current timezone. The offset is determined from
 the TZ environment variable, as if by calling tzset(). [tm_isdst]
 
 o %Z
-The time zone name.  If tm_isdst is negative, no output is generated.
-Otherwise, the time zone name is based on the TZ environment variable,
-as if by calling tzset(). [tm_isdst]
+The current time zone abbreviation. If tm_isdst is negative, no output
+is generated. Otherwise, the time zone abbreviation is based on the TZ
+environment variable, as if by calling tzset(). [tm_isdst]
 
 o %%
 A single character, `<<%>>'.
@@ -1086,6 +1097,11 @@ recurse:
 		return 0;
 	    }
 	  break;
+	case CQ('q'):	/* GNU quarter year */
+	  len = snprintf (&s[count], maxsize - count, CQ("%.1d"),
+			  tim_p->tm_mon / 3 + 1);
+	  CHECK_LENGTH ();
+	  break;
 	case CQ('R'):
           len = snprintf (&s[count], maxsize - count, CQ("%.2d:%.2d"),
 			  tim_p->tm_hour, tim_p->tm_min);
@@ -1241,6 +1257,36 @@ recurse:
             CHECK_LENGTH ();
 	  }
           break;
+	case CQ('v'):	/* OSX/Ruby extension VMS/Oracle date format */
+	  { /* %v is equivalent to "%d-%b-%Y", flags and width can change year
+	       format. Recurse to avoid need to replicate %b and %Y formation. */
+	    CHAR fmtbuf[32], *fmt = fmtbuf;
+	    STRCPY (fmt, CQ("%d-%b-%"));
+	    fmt += STRLEN (fmt);
+	    if (pad) /* '0' or '+' */
+	      *fmt++ = pad;
+	    else
+	      *fmt++ = '+';
+	    if (!pad)
+	      width = 10;
+	    if (width < 6)
+	      width = 6;
+	    width -= 6;
+	    if (width)
+	      {
+		len = snprintf (fmt, fmtbuf + 32 - fmt, CQ("%lu"), width);
+		if (len > 0)
+		  fmt += len;
+	      }
+	    STRCPY (fmt, CQ("Y"));
+	    len = __strftime (&s[count], maxsize - count, fmtbuf, tim_p,
+			      locale, era_info, alt_digits);
+	    if (len > 0)
+	      count += len;
+	    else
+	      return 0;
+	  }
+	  break;
 	case CQ('w'):
 #ifdef _WANT_C99_TIME_FORMATS
 	  if (alt == CQ('O') && *alt_digits)
@@ -1270,6 +1316,7 @@ recurse:
             CHECK_LENGTH ();
 	  }
 	  break;
+	case CQ('i'):	/* Non-POSIX extension. */
 	case CQ('y'):
 	    {
 #ifdef _WANT_C99_TIME_FORMATS
@@ -1524,6 +1571,7 @@ const struct test  Vec0[] = {
 	{ CQ("%h"), 3+1, EXP(CQ("Dec")) },
 	{ CQ("%H"), 2+1, EXP(CQ("09")) },
 	{ CQ("%I"), 2+1, EXP(CQ("09")) },
+	{ CQ("%i"), 2+1, EXP(CQ("08")) },
 	{ CQ("%j"), 3+1, EXP(CQ("365")) },
 	{ CQ("%k"), 2+1, EXP(CQ(" 9")) },
 	{ CQ("%l"), 2+1, EXP(CQ(" 9")) },
@@ -1531,6 +1579,7 @@ const struct test  Vec0[] = {
 	{ CQ("%M"), 2+1, EXP(CQ("53")) },
 	{ CQ("%n"), 1+1, EXP(CQ("\n")) },
 	{ CQ("%p"), 2+1, EXP(CQ("AM")) },
+	{ CQ("%q"), 1+1, EXP(CQ("4")) },
 	{ CQ("%r"), 11+1, EXP(CQ("09:53:47 AM")) },
 	{ CQ("%R"), 5+1, EXP(CQ("09:53")) },
 	{ CQ("%s"), 2+1, EXP(CQ("1230648827")) },
@@ -1540,6 +1589,7 @@ const struct test  Vec0[] = {
 	{ CQ("%u"), 1+1, EXP(CQ("2")) },
 	{ CQ("%U"), 2+1, EXP(CQ("52")) },
 	{ CQ("%V"), 2+1, EXP(CQ("01")) },
+	{ CQ("%v"), 11+1, EXP(CQ("30-Dec-2008")) },
 	{ CQ("%w"), 1+1, EXP(CQ("2")) },
 	{ CQ("%W"), 2+1, EXP(CQ("52")) },
 	{ CQ("%x"), 8+1, EXP(CQ("12/30/08")) },
@@ -1585,6 +1635,7 @@ const struct test  Vec1[] = {
 	{ CQ("%h"), 3+1, EXP(CQ("Jul")) },
 	{ CQ("%H"), 2+1, EXP(CQ("23")) },
 	{ CQ("%I"), 2+1, EXP(CQ("11")) },
+	{ CQ("%i"), 2+1, EXP(CQ("08")) },
 	{ CQ("%j"), 3+1, EXP(CQ("184")) },
 	{ CQ("%k"), 2+1, EXP(CQ("23")) },
 	{ CQ("%l"), 2+1, EXP(CQ("11")) },
@@ -1592,6 +1643,7 @@ const struct test  Vec1[] = {
 	{ CQ("%M"), 2+1, EXP(CQ("01")) },
 	{ CQ("%n"), 1+1, EXP(CQ("\n")) },
 	{ CQ("%p"), 2+1, EXP(CQ("PM")) },
+	{ CQ("%q"), 1+1, EXP(CQ("3")) },
 	{ CQ("%r"), 11+1, EXP(CQ("11:01:13 PM")) },
 	{ CQ("%R"), 5+1, EXP(CQ("23:01")) },
 	{ CQ("%s"), 2+1, EXP(CQ("1215054073")) },
@@ -1601,6 +1653,7 @@ const struct test  Vec1[] = {
 	{ CQ("%u"), 1+1, EXP(CQ("3")) },
 	{ CQ("%U"), 2+1, EXP(CQ("26")) },
 	{ CQ("%V"), 2+1, EXP(CQ("27")) },
+	{ CQ("%v"), 11+1, EXP(CQ("02-Jul-2008")) },
 	{ CQ("%w"), 1+1, EXP(CQ("3")) },
 	{ CQ("%W"), 2+1, EXP(CQ("26")) },
 	{ CQ("%x"), 8+1, EXP(CQ("07/02/08")) },
@@ -1662,6 +1715,8 @@ const struct test  Vecyr0[] = {
 	{ CQ("%c"), OUTSIZE, EXP(CQ("Wed Jul  2 23:01:13 ")YEAR) },
 	{ CQ("%D"), OUTSIZE, EXP(CQ("07/02/")Year) },
 	{ CQ("%F"), OUTSIZE, EXP(YEAR CQ("-07-02")) },
+	{ CQ("%i"), OUTSIZE, EXP(Year) },
+	{ CQ("%v"), OUTSIZE, EXP(CQ("02-Jul-")YEAR) },
 	{ CQ("%x"), OUTSIZE, EXP(CQ("07/02/")Year) },
 	{ CQ("%y"), OUTSIZE, EXP(Year) },
 	{ CQ("%Y"), OUTSIZE, EXP(YEAR) },
@@ -1708,6 +1763,8 @@ const struct test  Vecyr1[] = {
 	{ CQ("%c"), OUTSIZE, EXP(CQ("Wed Jul  2 23:01:13 ")YEAR) },
 	{ CQ("%D"), OUTSIZE, EXP(CQ("07/02/")Year) },
 	{ CQ("%F"), OUTSIZE, EXP(YEAR CQ("-07-02")) },
+	{ CQ("%i"), OUTSIZE, EXP(Year) },
+	{ CQ("%v"), OUTSIZE, EXP(CQ("02-Jul-")YEAR) },
 	{ CQ("%x"), OUTSIZE, EXP(CQ("07/02/")Year) },
 	{ CQ("%y"), OUTSIZE, EXP(Year) },
 	{ CQ("%Y"), OUTSIZE, EXP(YEAR) },
@@ -1745,6 +1802,8 @@ const struct test  Vecyrzp[] = {
 	{ CQ("%c"), OUTSIZE, EXP(CQ("Wed Jul  2 23:01:60 ")YEAR) },
 	{ CQ("%D"), OUTSIZE, EXP(CQ("07/02/")Year) },
 	{ CQ("%F"), OUTSIZE, EXP(YEAR CQ("-07-02")) },
+	{ CQ("%i"), OUTSIZE, EXP(Year) },
+	{ CQ("%v"), OUTSIZE, EXP(CQ("02-Jul-")YEAR) },
 	{ CQ("%x"), OUTSIZE, EXP(CQ("07/02/")Year) },
 	{ CQ("%y"), OUTSIZE, EXP(Year) },
 	{ CQ("%Y"), OUTSIZE, EXP(YEAR) },
@@ -1780,6 +1839,8 @@ const struct test  Vecyrzn[] = {
 	{ CQ("%c"), OUTSIZE, EXP(CQ("Wed Jul  2 23:01:00 ")YEAR) },
 	{ CQ("%D"), OUTSIZE, EXP(CQ("07/02/")Year) },
 	{ CQ("%F"), OUTSIZE, EXP(YEAR CQ("-07-02")) },
+	{ CQ("%i"), OUTSIZE, EXP(Year) },
+	{ CQ("%v"), OUTSIZE, EXP(CQ("02-Jul-")YEAR) },
 	{ CQ("%x"), OUTSIZE, EXP(CQ("07/02/")Year) },
 	{ CQ("%y"), OUTSIZE, EXP(Year) },
 	{ CQ("%Y"), OUTSIZE, EXP(YEAR) },

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 2/2] strptime.c(strptime_l): add %i, %q, %v
  2022-09-17  5:00 [PATCH 0/2] strftime.c, strptime.c: add %i, %q, %v, tests; tweak %Z docs Brian Inglis
  2022-09-17  5:00 ` [PATCH 1/2] strftime.c(__strftime): " Brian Inglis
@ 2022-09-17  5:00 ` Brian Inglis
  1 sibling, 0 replies; 9+ messages in thread
From: Brian Inglis @ 2022-09-17  5:00 UTC (permalink / raw)
  To: Newlib

[-- Attachment #1: Type: text/plain, Size: 377 bytes --]


newlib/libc/time/strptime.c(strptime_l):
%i year in century [00..99] Synonym for "%y". Non-POSIX extension. [tm_year]
%q GNU quarter of the year (from `<<1>>' to `<<4>>') [tm_mon]
%v OSX/Ruby VMS/Oracle date "%d-%b-%Y". Non-POSIX extension. [tm_mday, tm_mon, tm_year]:
---
 newlib/libc/time/strptime.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-strptime.c-strptime_l-add-i-q-v.patch --]
[-- Type: text/x-patch; name="0002-strptime.c-strptime_l-add-i-q-v.patch", Size: 1530 bytes --]

diff --git a/newlib/libc/time/strptime.c b/newlib/libc/time/strptime.c
index 12b2ef4695de..5e64af262516 100644
--- a/newlib/libc/time/strptime.c
+++ b/newlib/libc/time/strptime.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999 Kungliga Tekniska H?gskolan
+ * Copyright (c) 1999 Kungliga Tekniska Högskolan
  * (Royal Institute of Technology, Stockholm, Sweden). 
  * All rights reserved. 
  *
@@ -298,6 +298,14 @@ strptime_l (const char *buf, const char *format, struct tm *timeptr,
 		} else
 		    timeptr->tm_hour += 12;
 		break;
+	    case 'q' :		/* quarter year - GNU extension */
+		ret = strtol_l (buf, &s, 10, locale);
+		if (s == buf)
+		    return NULL;
+		timeptr->tm_mon = (ret - 1)*3;
+		buf = s;
+		ymd |= SET_MON;
+		break;
 	    case 'r' :		/* %I:%M:%S %p */
 		s = strptime_l (buf, _ctloc (ampm_fmt), timeptr, locale);
 		if (s == NULL)
@@ -365,6 +373,13 @@ strptime_l (const char *buf, const char *format, struct tm *timeptr,
 		buf = s;
 		ymd |= SET_WDAY;
 		break;
+	    case 'v' :	/* %d-%b-%Y - OSX/Ruby extension VMS/Oracle date */
+		s = strptime_l (buf, "%d-%b-%Y", timeptr, locale);
+		if (s == NULL || s == buf)
+		    return NULL;
+		buf = s;
+		ymd |= SET_YMD;
+		break;
 	    case 'U' :
 		ret = strtol_l (buf, &s, 10, locale);
 		if (s == buf)
@@ -402,6 +417,7 @@ strptime_l (const char *buf, const char *format, struct tm *timeptr,
 		    return NULL;
 		buf = s;
 	    	break;
+	    case 'i' :	    /* Non-POSIX extension. */
 	    case 'y' :
 		ret = strtol_l (buf, &s, 10, locale);
 		if (s == buf)

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Fw: [PATCH 1/2] strftime.c(__strftime): add %i, %q, %v, tests; tweak %Z docs
       [not found]   ` <BN2P110MB15443B0E0009D450989B3ECF9A4D9@BN2P110MB1544.NAMP110.PROD.OUTLOOK.COM>
@ 2022-09-19 15:51     ` C Howland
  2022-09-19 23:21       ` Brian Inglis
  2022-10-18 14:03       ` Corinna Vinschen
  0 siblings, 2 replies; 9+ messages in thread
From: C Howland @ 2022-09-19 15:51 UTC (permalink / raw)
  To: newlib, Brian.Inglis

[-- Attachment #1: Type: text/plain, Size: 1228 bytes --]

>
> ------------------------------
> *From:* Newlib <newlib-bounces+craig.howland=caci.com@sourceware.org> on
> behalf of Brian Inglis <Brian.Inglis@SystematicSW.ab.ca>
> *Sent:* Saturday, September 17, 2022 1:00 AM
> *To:* Newlib <newlib@Sourceware.org>
> *Subject:* [PATCH 1/2] strftime.c(__strftime): add %i, %q, %v, tests;
> tweak %Z docs
>
>
>
> newlib/libc/time/strftime.c(__strftime):
> %i year in century [00..99] Synonym for "%y". Non-POSIX extension.
> [tm_year]
> %q GNU quarter of the year (from `<<1>>' to `<<4>>') [tm_mon]
> %v OSX/Ruby VMS/Oracle date "%d-%b-%Y". Non-POSIX extension. [tm_mday,
> tm_mon, tm_year]
> add %i %q %v tests
> %Z clarify current time zone *abbreviation* not "name" [tm_isdst]
> ---
>  newlib/libc/time/strftime.c | 67 +++++++++++++++++++++++++++++++++++--
>  1 file changed, 64 insertions(+), 3 deletions(-)
>
>
While the additions themselves nominally look good, all being extensions
they ought to be gated by the appropriate ifdefs, and the manual would best
mention what gates are needed to get them.  %q would be __GNU_VISIBLE as
the gate and _GNU_SOURCE for the user/manual, and I'd guess probably
__MISC_VISIBLE gate for the others (user action as noted in sys/features.h).
Craig

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Fw: [PATCH 1/2] strftime.c(__strftime): add %i, %q, %v, tests; tweak %Z docs
  2022-09-19 15:51     ` Fw: " C Howland
@ 2022-09-19 23:21       ` Brian Inglis
  2022-10-18 14:03       ` Corinna Vinschen
  1 sibling, 0 replies; 9+ messages in thread
From: Brian Inglis @ 2022-09-19 23:21 UTC (permalink / raw)
  To: newlib

On 2022-09-19 09:51, C Howland wrote:
>     newlib/libc/time/strftime.c(__strftime):
>     %i year in century [00..99] Synonym for "%y". Non-POSIX extension.
>     [tm_year]
>     %q GNU quarter of the year (from `<<1>>' to `<<4>>') [tm_mon]
>     %v OSX/Ruby VMS/Oracle date "%d-%b-%Y". Non-POSIX extension.
>     [tm_mday, tm_mon, tm_year]
>     add %i %q %v tests
>     %Z clarify current time zone *abbreviation* not "name" [tm_isdst]

> While the additions themselves nominally look good, all being extensions 
> they ought to be gated by the appropriate ifdefs, and the manual would 
> best mention what gates are needed to get them.  %q would be 
> __GNU_VISIBLE as the gate and _GNU_SOURCE for the user/manual, and I'd 
> guess probably __MISC_VISIBLE gate for the others (user action as noted 
> in sys/features.h).

Those features are more appropriate for application build time feature 
support selection, not for library implementations.

I checked and implementations (including BSD, and Cygwin strptime.cc) 
don't gate features, except by what the build config supports and desires:

	__CYGWIN__, __HAVE_LOCALE_INFO_EXTENDED__, __TM_GMTOFF,
	__TM_ZONE, _WANT_C99_TIME_FORMATS, MAKE_WCSFTIME, YEAR_BASE

and strptime.c *#defines _GNU_SOURCE* before all #include-s.

The overhead of the additions is minimal compared to existing 
conversions, the likely impact of issues with new conversions used in 
existing sources is low, and any use is defined as UB.

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.
[Data in binary units and prefixes, physical quantities in SI.]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Fw: [PATCH 1/2] strftime.c(__strftime): add %i, %q, %v, tests; tweak %Z docs
  2022-09-19 15:51     ` Fw: " C Howland
  2022-09-19 23:21       ` Brian Inglis
@ 2022-10-18 14:03       ` Corinna Vinschen
  2022-10-20 22:07         ` Brian Inglis
  1 sibling, 1 reply; 9+ messages in thread
From: Corinna Vinschen @ 2022-10-18 14:03 UTC (permalink / raw)
  To: newlib, Brian.Inglis

On Sep 19 11:51, C Howland wrote:
> >
> > ------------------------------
> > *From:* Newlib <newlib-bounces+craig.howland=caci.com@sourceware.org> on
> > behalf of Brian Inglis <Brian.Inglis@SystematicSW.ab.ca>
> > *Sent:* Saturday, September 17, 2022 1:00 AM
> > *To:* Newlib <newlib@Sourceware.org>
> > *Subject:* [PATCH 1/2] strftime.c(__strftime): add %i, %q, %v, tests;
> > tweak %Z docs
> >
> >
> >
> > newlib/libc/time/strftime.c(__strftime):
> > %i year in century [00..99] Synonym for "%y". Non-POSIX extension.
> > [tm_year]
> > %q GNU quarter of the year (from `<<1>>' to `<<4>>') [tm_mon]
> > %v OSX/Ruby VMS/Oracle date "%d-%b-%Y". Non-POSIX extension. [tm_mday,
> > tm_mon, tm_year]
> > add %i %q %v tests
> > %Z clarify current time zone *abbreviation* not "name" [tm_isdst]
> > ---
> >  newlib/libc/time/strftime.c | 67 +++++++++++++++++++++++++++++++++++--
> >  1 file changed, 64 insertions(+), 3 deletions(-)
> >
> >
> While the additions themselves nominally look good, all being extensions
> they ought to be gated by the appropriate ifdefs, and the manual would best
> mention what gates are needed to get them.  %q would be __GNU_VISIBLE as
> the gate

You're misunderstanding how these foo_VISIBLE macros are supposed to be
used.  They guard definitions and prototypes in header files depending
on the application layer environment in terms of portability.  They are
not supposed to be used inside newlib code to create conditionalized
library code.

Of course you can argue that the code should not go in unconditionalized
based on target preferences, but that should use one of the documented
macros for newlib builds, e. g., _ELIX_LEVEL, _GLIBC_EXTENSION, or
whatever.

You can also argue that they should not go in at all.  I'm doing this
now for the sake of discussion:

- %i: Where is used and documented?  I don't see this in glibc, not even
  in the latest from the glibc git repo.

- %q: Ditto. For a GNU extension, it's surprisingly absent from the
  most recent glibc code, or do I miss something?

- %v: OSX/Ruby?  Isn't that already gone?  Also, it introduces another
  ambiguous date format where %F or equivalent should be used instead.

It's nice to add features, but it wouldn't hurt to have some
clarification and justification if it's non-standard stuff.
Availability in glibc or in the BSDs is typically justification enough,
but I don't see this here.


Thanks,
Corinna


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Fw: [PATCH 1/2] strftime.c(__strftime): add %i, %q, %v, tests; tweak %Z docs
  2022-10-18 14:03       ` Corinna Vinschen
@ 2022-10-20 22:07         ` Brian Inglis
  2022-10-21 12:12           ` Corinna Vinschen
  0 siblings, 1 reply; 9+ messages in thread
From: Brian Inglis @ 2022-10-20 22:07 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 2268 bytes --]

On 2022-10-18 08:03, Corinna Vinschen wrote:
> On Sep 19 11:51, C Howland wrote:
>> On Saturday, September 17, 2022 1:00 AM, Brian Inglis wrote:
>>> newlib/libc/time/strftime.c(__strftime):
>>> %i year in century [00..99] Synonym for "%y". Non-POSIX extension.
>>> [tm_year]
>>> %q GNU quarter of the year (from `<<1>>' to `<<4>>') [tm_mon]
>>> %v OSX/Ruby VMS/Oracle date "%d-%b-%Y". Non-POSIX extension. [tm_mday,
>>> tm_mon, tm_year]
>>> add %i %q %v tests
>>> %Z clarify current time zone *abbreviation* not "name" [tm_isdst]
>>> ---
>>>   newlib/libc/time/strftime.c | 67 +++++++++++++++++++++++++++++++++++--
>>>   1 file changed, 64 insertions(+), 3 deletions(-)

> - %i: Where is used and documented?  I don't see this in glibc, not even
>    in the latest from the glibc git repo.

Some portable language implementations for non-Unix platforms that I came across 
and documented but did not keep track of, and now can't find!

> - %q: Ditto. For a GNU extension, it's surprisingly absent from the
>    most recent glibc code, or do I miss something?

Looks like this may have been lost in the discussion:

https://inbox.sourceware.org/libc-alpha/2f5f737e-2e42-08c6-ae2b-33aab798a1d9@draigBrady.com/

but as he says, it was already in gnulib, and made it into date the same month:

https://git.savannah.gnu.org/cgit/coreutils.git/diff/?id=30012b290facf66551cdf395ace397903d00483d

also in Perl and ksh93 printf %(...)T.

> - %v: OSX/Ruby?  Isn't that already gone?  Also, it introduces another
>    ambiguous date format where %F or equivalent should be used instead.

All the BSDs, Darwin, Oracle, and Ruby support it: it is localized, but not 
ambiguous, as it's dd-Mon-yyyy.

> It's nice to add features, but it wouldn't hurt to have some
> clarification and justification if it's non-standard stuff.
> Availability in glibc or in the BSDs is typically justification enough,
> but I don't see this here.

See attached sh and log for doc and code searches.

-- 
Take care. Thanks, Brian Inglis			Calgary, Alberta, Canada

La perfection est atteinte			Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter	not when there is no more to add
mais lorsqu'il n'y a plus rien à retirer	but when there is no more to cut
			-- Antoine de Saint-Exupéry

[-- Attachment #2: date-iqv.sh --]
[-- Type: text/plain, Size: 639 bytes --]

#!/bin/bash
# date-iqv.sh

echo "$ man date | grep \"'[iqv]'\|%[iqv]\""
man date | grep "'[iqv]'\|%[iqv]"

echo "$ perldoc Date::Format | grep \"'[iqv]'\|%[iqv]\""
perldoc Date::Format | grep "'[iqv]'\|%[iqv]"

echo "$ ri Date.strftime | grep \"'[iqv]'\|%[iqv]\""
ri Date.strftime | grep "'[iqv]'\|%[iqv]"

echo "$ grep -A8 \"'[iqv]'\|%[iqv]\" ../{BSD/*BSD,cygwin/coreutils/coreutils-9.0-?.x*/origsrc/coreutils-9.0/*,glibc/time,gnulib/lib,musl/time}/*{date,{str,wcs}[fp]time}*"
grep -A8 "'[iqv]'\|%[iqv]" ../{BSD/*BSD,cygwin/coreutils/coreutils-9.0-?.x*/origsrc/coreutils-9.0/*,glibc/time,gnulib/lib,musl/time}/*{date,{str,wcs}[fp]time}*


[-- Attachment #3: date-iqv.log --]
[-- Type: text/plain, Size: 13064 bytes --]

$ man date | grep "'[iqv]'\|%[iqv]"
       %q     quarter of year (1..4)
$ perldoc Date::Format | grep "'[iqv]'\|%[iqv]"
            %q      Quarter number, starting with 1
    %d, %e, %H, %I, %j, %k, %l, %m, %M, %q, %y and %Y can be output in Roman
$ ri Date.strftime | grep "'[iqv]'\|%[iqv]"
    %v - VMS date (%e-%b-%Y)
$ grep -A8 "'[iqv]'\|%[iqv]" ../{BSD/*BSD,cygwin/coreutils/coreutils-9.0-?.x*/origsrc/coreutils-9.0/*,glibc/time,gnulib/lib,musl/time}/*{date,{str,wcs}[fp]time}*
../BSD/FreeBSD/strftime.c:			case 'v':
../BSD/FreeBSD/strftime.c-				/*
../BSD/FreeBSD/strftime.c-				 * From Arnold Robbins' strftime version 3.0:
../BSD/FreeBSD/strftime.c-				 * "date as dd-bbb-YYYY"
../BSD/FreeBSD/strftime.c-				 * (ado, 1993-05-24)
../BSD/FreeBSD/strftime.c-				 */
../BSD/FreeBSD/strftime.c-				pt = _fmt("%e-%b-%Y", t, pt, ptlim, warnp, loc);
../BSD/FreeBSD/strftime.c-				continue;
../BSD/FreeBSD/strftime.c-			case 'W':
--
../BSD/NetBSD/strftime.c:			case 'v':
../BSD/NetBSD/strftime.c-				/*
../BSD/NetBSD/strftime.c-				** From Arnold Robbins' strftime version 3.0:
../BSD/NetBSD/strftime.c-				** "date as dd-bbb-YYYY"
../BSD/NetBSD/strftime.c-				** (ado, 1993-05-24)
../BSD/NetBSD/strftime.c-				*/
../BSD/NetBSD/strftime.c-				pt = _fmt(sp, "%e-%b-%Y", t, pt, ptlim, warnp,
../BSD/NetBSD/strftime.c-				    loc);
../BSD/NetBSD/strftime.c-				continue;
--
../BSD/OpenBSD/strftime.c:			case 'v':
../BSD/OpenBSD/strftime.c-				/*
../BSD/OpenBSD/strftime.c-				** From Arnold Robbins' strftime version 3.0:
../BSD/OpenBSD/strftime.c-				** "date as dd-bbb-YYYY"
../BSD/OpenBSD/strftime.c-				** (ado, 1993-05-24)
../BSD/OpenBSD/strftime.c-				*/
../BSD/OpenBSD/strftime.c-				pt = _fmt("%e-%b-%Y", t, pt, ptlim, warnp);
../BSD/OpenBSD/strftime.c-				continue;
../BSD/OpenBSD/strftime.c-			case 'W':
--
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/man/date.1:%q
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/man/date.1-quarter of year (1..4)
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/man/date.1-.TP
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/man/date.1-%r
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/man/date.1-locale's 12\-hour clock time (e.g., 11:11:04 PM)
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/man/date.1-.TP
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/man/date.1-%R
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/man/date.1-24\-hour hour and minute; same as %H:%M
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/man/date.1-.TP
--
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/src/date.c:  %q   quarter of year (1..4)\n\
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/src/date.c-  %r   locale's 12-hour clock time (e.g., 11:11:04 PM)\n\
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/src/date.c-  %R   24-hour hour and minute; same as %H:%M\n\
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/src/date.c-  %s   seconds since the Epoch (1970-01-01 00:00 UTC)\n\
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/src/date.c-"), stdout);
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/src/date.c-      fputs (_("\
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/src/date.c-  %S   second (00..60)\n\
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/src/date.c-  %t   a tab\n\
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/src/date.c-  %T   time; same as %H:%M:%S\n\
--
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/gnulib-tests/test-nstrftime.c:  /* Check %q.  */
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/gnulib-tests/test-nstrftime.c-  for (mon = 1; mon <= 12; mon++)
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/gnulib-tests/test-nstrftime.c-    {
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/gnulib-tests/test-nstrftime.c-      char out[2];
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/gnulib-tests/test-nstrftime.c-      char exp[2] = {0,};
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/gnulib-tests/test-nstrftime.c-      struct tm qtm = { .tm_mon = mon - 1 };
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/gnulib-tests/test-nstrftime.c:      char fmt[3] = {'%','q','\0'};
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/gnulib-tests/test-nstrftime.c-
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/gnulib-tests/test-nstrftime.c-      size_t r = nstrftime (out, sizeof (out), fmt, &qtm, 0, 0);
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/gnulib-tests/test-nstrftime.c-      if (r == 0)
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/gnulib-tests/test-nstrftime.c-        {
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/gnulib-tests/test-nstrftime.c:          puts ("nstrftime(\"%q\") failed");
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/gnulib-tests/test-nstrftime.c-          result = 1;
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/gnulib-tests/test-nstrftime.c-          break;
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/gnulib-tests/test-nstrftime.c-        }
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/gnulib-tests/test-nstrftime.c-
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/gnulib-tests/test-nstrftime.c-      exp[0] = mon < 4 ? '1' : mon < 7 ? '2' : mon < 10 ? '3' : '4';
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/gnulib-tests/test-nstrftime.c-      if (strcmp (out, exp) != 0)
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/gnulib-tests/test-nstrftime.c-        {
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/gnulib-tests/test-nstrftime.c:          printf ("nstrftime %%q: expected \"%s\", got \"%s\"\n", exp, out);
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/gnulib-tests/test-nstrftime.c-          result = 1;
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/gnulib-tests/test-nstrftime.c-          break;
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/gnulib-tests/test-nstrftime.c-        }
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/gnulib-tests/test-nstrftime.c-    }
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/gnulib-tests/test-nstrftime.c-
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/gnulib-tests/test-nstrftime.c-  return result;
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/gnulib-tests/test-nstrftime.c-}
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/gnulib-tests/test-nstrftime.c-
--
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/lib/nstrftime.c:        case L_('e'): case L_('f'): case L_('g'): case L_('h'): case L_('i'):
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/lib/nstrftime.c-        case L_('j'): case L_('k'): case L_('l'): case L_('m'): case L_('n'):
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/lib/nstrftime.c:        case L_('o'): case L_('p'): case L_('q'): case L_('r'): case L_('s'):
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/lib/nstrftime.c:        case L_('t'): case L_('u'): case L_('v'): case L_('w'): case L_('x'):
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/lib/nstrftime.c-        case L_('y'): case L_('z'): case L_('{'): case L_('|'): case L_('}'):
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/lib/nstrftime.c-        case L_('~'):
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/lib/nstrftime.c-          /* The C Standard requires these 98 characters (plus '%') to
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/lib/nstrftime.c-             be in the basic execution character set.  None of these
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/lib/nstrftime.c-             characters can start a multibyte sequence, so they need
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/lib/nstrftime.c-             not be analyzed further.  */
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/lib/nstrftime.c-          add1 (*f);
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/lib/nstrftime.c-          continue;
--
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/lib/nstrftime.c:        case L_('q'):           /* GNU extension.  */
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/lib/nstrftime.c-          DO_SIGNED_NUMBER (1, false, ((tp->tm_mon * 11) >> 5) + 1);
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/lib/nstrftime.c-          break;
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/lib/nstrftime.c-
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/lib/nstrftime.c-        case L_('R'):
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/lib/nstrftime.c-          subfmt = L_("%H:%M");
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/lib/nstrftime.c-          goto subformat;
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/lib/nstrftime.c-
../cygwin/coreutils/coreutils-9.0-1.x86_64/origsrc/coreutils-9.0/lib/nstrftime.c-        case L_('r'):
--
../glibc/time/strftime_l.c:	case L_('e'): case L_('f'): case L_('g'): case L_('h'): case L_('i'):
../glibc/time/strftime_l.c-	case L_('j'): case L_('k'): case L_('l'): case L_('m'): case L_('n'):
../glibc/time/strftime_l.c:	case L_('o'): case L_('p'): case L_('q'): case L_('r'): case L_('s'):
../glibc/time/strftime_l.c:	case L_('t'): case L_('u'): case L_('v'): case L_('w'): case L_('x'):
../glibc/time/strftime_l.c-	case L_('y'): case L_('z'): case L_('{'): case L_('|'): case L_('}'):
../glibc/time/strftime_l.c-	case L_('~'):
../glibc/time/strftime_l.c-	  /* The C Standard requires these 98 characters (plus '%') to
../glibc/time/strftime_l.c-	     be in the basic execution character set.  None of these
../glibc/time/strftime_l.c-	     characters can start a multibyte sequence, so they need
../glibc/time/strftime_l.c-	     not be analyzed further.  */
../glibc/time/strftime_l.c-	  add (1, *p = *f);
../glibc/time/strftime_l.c-	  continue;
--
../gnulib/lib/nstrftime.c:        case L_('e'): case L_('f'): case L_('g'): case L_('h'): case L_('i'):
../gnulib/lib/nstrftime.c-        case L_('j'): case L_('k'): case L_('l'): case L_('m'): case L_('n'):
../gnulib/lib/nstrftime.c:        case L_('o'): case L_('p'): case L_('q'): case L_('r'): case L_('s'):
../gnulib/lib/nstrftime.c:        case L_('t'): case L_('u'): case L_('v'): case L_('w'): case L_('x'):
../gnulib/lib/nstrftime.c-        case L_('y'): case L_('z'): case L_('{'): case L_('|'): case L_('}'):
../gnulib/lib/nstrftime.c-        case L_('~'):
../gnulib/lib/nstrftime.c-          /* The C Standard requires these 98 characters (plus '%') to
../gnulib/lib/nstrftime.c-             be in the basic execution character set.  None of these
../gnulib/lib/nstrftime.c-             characters can start a multibyte sequence, so they need
../gnulib/lib/nstrftime.c-             not be analyzed further.  */
../gnulib/lib/nstrftime.c-          add1 (*f);
../gnulib/lib/nstrftime.c-          continue;
--
../gnulib/lib/nstrftime.c:        case L_('q'):           /* GNU extension.  */
../gnulib/lib/nstrftime.c-          DO_SIGNED_NUMBER (1, false, ((tp->tm_mon * 11) >> 5) + 1);
../gnulib/lib/nstrftime.c-
../gnulib/lib/nstrftime.c-        case L_('R'):
../gnulib/lib/nstrftime.c-          subfmt = L_("%H:%M");
../gnulib/lib/nstrftime.c-          goto subformat;
../gnulib/lib/nstrftime.c-
../gnulib/lib/nstrftime.c-        case L_('r'):
../gnulib/lib/nstrftime.c-#ifdef _NL_CURRENT
--
../gnulib/lib/strptime.c:        case 'q':
../gnulib/lib/strptime.c-          /* Match quarter of year.  GNU extension.  */
../gnulib/lib/strptime.c-          get_number (1, 4, 1);
../gnulib/lib/strptime.c-          tm->tm_mon = (val - 1) * 3;
../gnulib/lib/strptime.c-          tm->tm_mday = 1;
../gnulib/lib/strptime.c-          have_mon = 1;
../gnulib/lib/strptime.c-          have_mday = 1;
../gnulib/lib/strptime.c-          want_xday = 1;
../gnulib/lib/strptime.c-          break;
--
../gnulib/lib/strptime.c:            case 'q':
../gnulib/lib/strptime.c-              /* Match quarter using alternate numeric symbols.  */
../gnulib/lib/strptime.c-              get_alt_number (1, 4, 1);
../gnulib/lib/strptime.c-              tm->tm_mon = (val - 1) * 3;
../gnulib/lib/strptime.c-              tm->tm_mday = 1;
../gnulib/lib/strptime.c-              have_mon = 1;
../gnulib/lib/strptime.c-              have_mday = 1;
../gnulib/lib/strptime.c-              want_xday = 1;
../gnulib/lib/strptime.c-              break;

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Fw: [PATCH 1/2] strftime.c(__strftime): add %i, %q, %v, tests; tweak %Z docs
  2022-10-20 22:07         ` Brian Inglis
@ 2022-10-21 12:12           ` Corinna Vinschen
  2022-10-21 20:43             ` Brian Inglis
  0 siblings, 1 reply; 9+ messages in thread
From: Corinna Vinschen @ 2022-10-21 12:12 UTC (permalink / raw)
  To: newlib

On Oct 20 16:07, Brian Inglis wrote:
> On 2022-10-18 08:03, Corinna Vinschen wrote:
> > On Sep 19 11:51, C Howland wrote:
> > > On Saturday, September 17, 2022 1:00 AM, Brian Inglis wrote:
> > > > newlib/libc/time/strftime.c(__strftime):
> > > > %i year in century [00..99] Synonym for "%y". Non-POSIX extension.
> > > > [tm_year]
> > > > %q GNU quarter of the year (from `<<1>>' to `<<4>>') [tm_mon]
> > > > %v OSX/Ruby VMS/Oracle date "%d-%b-%Y". Non-POSIX extension. [tm_mday,
> > > > tm_mon, tm_year]
> > > > add %i %q %v tests
> > > > %Z clarify current time zone *abbreviation* not "name" [tm_isdst]
> > > > ---
> > > >   newlib/libc/time/strftime.c | 67 +++++++++++++++++++++++++++++++++++--
> > > >   1 file changed, 64 insertions(+), 3 deletions(-)
> 
> > - %i: Where is used and documented?  I don't see this in glibc, not even
> >    in the latest from the glibc git repo.
> 
> Some portable language implementations for non-Unix platforms that I came
> across and documented but did not keep track of, and now can't find!

So we don't have that in either BSD, nor GNU, nor POSIX, but only
in other non-POSIX platforms.  Hmm.  Along these lines, we could also
make a case for supporting Microsoft's %I64 printf format and I'm
not so hot on that...

For the time being, please let's drop %i.  Defining it now may result in
accidental collisions with the POSIX standard, should it get extended.

> > - %q: Ditto. For a GNU extension, it's surprisingly absent from the
> >    most recent glibc code, or do I miss something?
> 
> Looks like this may have been lost in the discussion:
> 
> https://inbox.sourceware.org/libc-alpha/2f5f737e-2e42-08c6-ae2b-33aab798a1d9@draigBrady.com/
> 
> but as he says, it was already in gnulib, and made it into date the same month:
> 
> https://git.savannah.gnu.org/cgit/coreutils.git/diff/?id=30012b290facf66551cdf395ace397903d00483d

Ok, that's fine then.

> > - %v: OSX/Ruby?  Isn't that already gone?  Also, it introduces another
> >    ambiguous date format where %F or equivalent should be used instead.
> 
> All the BSDs, Darwin, Oracle, and Ruby support it: it is localized, but not
> ambiguous, as it's dd-Mon-yyyy.

I found it in all three BSDs with a comment

    /*      
    ** From Arnold Robbins' strftime version 3.0:
    ** "date as dd-bbb-YYYY"
    ** (ado, 1993-05-24)
    */

Also, it's defined as a recursion with the format "%e-%b-%Y",
unconditionally (no padding, etc).  Maybe we should replicate that
verbatim (including the comment) to keep in line with BSD.

Also, the BSDs do *not* define %v in strptime, so I think we shouldn't
do this either.  It may accidentally collide with a standards extension,
just as %i.


Thanks,
Corinna


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Fw: [PATCH 1/2] strftime.c(__strftime): add %i, %q, %v, tests; tweak %Z docs
  2022-10-21 12:12           ` Corinna Vinschen
@ 2022-10-21 20:43             ` Brian Inglis
  0 siblings, 0 replies; 9+ messages in thread
From: Brian Inglis @ 2022-10-21 20:43 UTC (permalink / raw)
  To: newlib

On 2022-10-21 06:12, Corinna Vinschen wrote:
> On Oct 20 16:07, Brian Inglis wrote:
>> On 2022-10-18 08:03, Corinna Vinschen wrote:
>>> On Sep 19 11:51, C Howland wrote:
>>>> On Saturday, September 17, 2022 1:00 AM, Brian Inglis wrote:
>>>>> newlib/libc/time/strftime.c(__strftime):
>>>>> %i year in century [00..99] Synonym for "%y". Non-POSIX extension.
>>>>> [tm_year]
>>>>> %q GNU quarter of the year (from `<<1>>' to `<<4>>') [tm_mon]
>>>>> %v OSX/Ruby VMS/Oracle date "%d-%b-%Y". Non-POSIX extension. [tm_mday,
>>>>> tm_mon, tm_year]
>>>>> add %i %q %v tests
>>>>> %Z clarify current time zone *abbreviation* not "name" [tm_isdst]
>>>>> ---
>>>>>    newlib/libc/time/strftime.c | 67 +++++++++++++++++++++++++++++++++++--
>>>>>    1 file changed, 64 insertions(+), 3 deletions(-)
>>
>>> - %i: Where is used and documented?  I don't see this in glibc, not even
>>>     in the latest from the glibc git repo.
>>
>> Some portable language implementations for non-Unix platforms that I came
>> across and documented but did not keep track of, and now can't find!
> 
> So we don't have that in either BSD, nor GNU, nor POSIX, but only
> in other non-POSIX platforms.  Hmm.  Along these lines, we could also
> make a case for supporting Microsoft's %I64 printf format and I'm
> not so hot on that...
> 
> For the time being, please let's drop %i.  Defining it now may result in
> accidental collisions with the POSIX standard, should it get extended.
> 
>>> - %q: Ditto. For a GNU extension, it's surprisingly absent from the
>>>     most recent glibc code, or do I miss something?
>>
>> Looks like this may have been lost in the discussion:
>>
>> https://inbox.sourceware.org/libc-alpha/2f5f737e-2e42-08c6-ae2b-33aab798a1d9@draigBrady.com/
>>
>> but as he says, it was already in gnulib, and made it into date the same month:
>>
>> https://git.savannah.gnu.org/cgit/coreutils.git/diff/?id=30012b290facf66551cdf395ace397903d00483d
> 
> Ok, that's fine then.
> 
>>> - %v: OSX/Ruby?  Isn't that already gone?  Also, it introduces another
>>>     ambiguous date format where %F or equivalent should be used instead.
>>
>> All the BSDs, Darwin, Oracle, and Ruby support it: it is localized, but not
>> ambiguous, as it's dd-Mon-yyyy.
> 
> I found it in all three BSDs with a comment
> 
>      /*
>      ** From Arnold Robbins' strftime version 3.0:
>      ** "date as dd-bbb-YYYY"
>      ** (ado, 1993-05-24)
>      */
> 
> Also, it's defined as a recursion with the format "%e-%b-%Y",
> unconditionally (no padding, etc).  Maybe we should replicate that
> verbatim (including the comment) to keep in line with BSD.
> 
> Also, the BSDs do *not* define %v in strptime, so I think we shouldn't
> do this either.  It may accidentally collide with a standards extension,
> just as %i.

Consensus seems to be that, as it's been claimed by BSDs, it may be standardized 
or will have to be avoided: but no problem with your decision to drop from 
strptime.

Noticed "%+" in man-pages-linux and BSD strftime(3) defined as default locale 
(C/POSIX) date(1) format like as/ctime with %Z - "%a %b %e %T %Z %Y".
Presumably added so that the previous default locale output could easily be 
provided for backward compatibility once %c %x %X could be localized.
Should I also add this to our newlib strftime patch?

Are there pointers to that default locale and "%c" format in newlib and Cygwin?
I will search and check but could miss something defined away in the wild.

Presumably I should also drop %i and %v from Cygwin strptime.cc patch on 
cygwin-patches?

-- 
Take care. Thanks, Brian Inglis			Calgary, Alberta, Canada

La perfection est atteinte			Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter	not when there is no more to add
mais lorsqu'il n'y a plus rien à retirer	but when there is no more to cut
			-- Antoine de Saint-Exupéry

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-10-21 20:44 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-17  5:00 [PATCH 0/2] strftime.c, strptime.c: add %i, %q, %v, tests; tweak %Z docs Brian Inglis
2022-09-17  5:00 ` [PATCH 1/2] strftime.c(__strftime): " Brian Inglis
     [not found]   ` <BN2P110MB15443B0E0009D450989B3ECF9A4D9@BN2P110MB1544.NAMP110.PROD.OUTLOOK.COM>
2022-09-19 15:51     ` Fw: " C Howland
2022-09-19 23:21       ` Brian Inglis
2022-10-18 14:03       ` Corinna Vinschen
2022-10-20 22:07         ` Brian Inglis
2022-10-21 12:12           ` Corinna Vinschen
2022-10-21 20:43             ` Brian Inglis
2022-09-17  5:00 ` [PATCH 2/2] strptime.c(strptime_l): add %i, %q, %v Brian Inglis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).