public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] strftime.c(__strftime): add %q, %v, tests; tweak %Z doc
@ 2022-10-22  5:13 Brian Inglis
  2022-10-24 12:07 ` Corinna Vinschen
  0 siblings, 1 reply; 5+ messages in thread
From: Brian Inglis @ 2022-10-22  5:13 UTC (permalink / raw)
  To: newlib

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

%q GNU quarter year 1-4
%v BSD/OSX/Ruby VMS/Oracle %e-%b-%Y
%Z change time zone *name* to *abbreviation*

---
 newlib/libc/time/strftime.c | 58 +++++++++++++++++++++++++++++++++++--
 1 file changed, 55 insertions(+), 3 deletions(-)


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

diff --git a/newlib/libc/time/strftime.c b/newlib/libc/time/strftime.c
index 9c884dca9766..420745d90333 100644
--- a/newlib/libc/time/strftime.c
+++ b/newlib/libc/time/strftime.c
@@ -161,6 +161,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 +202,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 BSD/OSX/Ruby VMS/Oracle date format, in the form
+"%e-%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 +243,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 +1094,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 +1254,37 @@ recurse:
             CHECK_LENGTH ();
 	  }
           break;
+	case CQ('v'):	/* BSD/OSX/Ruby extension VMS/Oracle date format
+			   from Arnold Robbins strftime version 3.0 */
+	  { /* %v is equivalent to "%e-%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("%e-%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)
@@ -1531,6 +1575,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 +1585,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")) },
@@ -1592,6 +1638,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 +1648,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(" 2-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 +1710,7 @@ 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("%v"), OUTSIZE, EXP(CQ(" 2-Jul-")YEAR) },
 	{ CQ("%x"), OUTSIZE, EXP(CQ("07/02/")Year) },
 	{ CQ("%y"), OUTSIZE, EXP(Year) },
 	{ CQ("%Y"), OUTSIZE, EXP(YEAR) },
@@ -1708,6 +1757,7 @@ 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("%v"), OUTSIZE, EXP(CQ(" 2-Jul-")YEAR) },
 	{ CQ("%x"), OUTSIZE, EXP(CQ("07/02/")Year) },
 	{ CQ("%y"), OUTSIZE, EXP(Year) },
 	{ CQ("%Y"), OUTSIZE, EXP(YEAR) },
@@ -1745,6 +1795,7 @@ 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("%v"), OUTSIZE, EXP(CQ(" 2-Jul-")YEAR) },
 	{ CQ("%x"), OUTSIZE, EXP(CQ("07/02/")Year) },
 	{ CQ("%y"), OUTSIZE, EXP(Year) },
 	{ CQ("%Y"), OUTSIZE, EXP(YEAR) },
@@ -1780,6 +1831,7 @@ 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("%v"), OUTSIZE, EXP(CQ(" 2-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] 5+ messages in thread

* Re: [PATCH] strftime.c(__strftime): add %q, %v, tests; tweak %Z doc
  2022-10-22  5:13 [PATCH] strftime.c(__strftime): add %q, %v, tests; tweak %Z doc Brian Inglis
@ 2022-10-24 12:07 ` Corinna Vinschen
  2022-10-24 23:50   ` Brian Inglis
  0 siblings, 1 reply; 5+ messages in thread
From: Corinna Vinschen @ 2022-10-24 12:07 UTC (permalink / raw)
  To: newlib

Hi Brian,

On Oct 21 23:13, Brian Inglis wrote:
> +	case CQ('v'):	/* BSD/OSX/Ruby extension VMS/Oracle date format
> +			   from Arnold Robbins strftime version 3.0 */
> +	  { /* %v is equivalent to "%e-%b-%Y", flags and width can change year
                                               ^^^^^
                                               pad?
> +	       format. Recurse to avoid need to replicate %b and %Y formation. */

Sorry for being a nag, but doesn't that introduce an incompatible
change?  The BSDs don't handle pad and width, they just call
_fmt("%e-%b-%Y", ...).  Or am I missing how the BSD function works?


Corinna


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

* Re: [PATCH] strftime.c(__strftime): add %q, %v, tests; tweak %Z doc
  2022-10-24 12:07 ` Corinna Vinschen
@ 2022-10-24 23:50   ` Brian Inglis
  2022-10-25 10:38     ` Corinna Vinschen
  0 siblings, 1 reply; 5+ messages in thread
From: Brian Inglis @ 2022-10-24 23:50 UTC (permalink / raw)
  To: newlib; +Cc: Brian.Inglis

On 2022-10-24 06:07, Corinna Vinschen wrote:
> On Oct 21 23:13, Brian Inglis wrote:
>> +	case CQ('v'):	/* BSD/OSX/Ruby extension VMS/Oracle date format
>> +			   from Arnold Robbins strftime version 3.0 */
>> +	  { /* %v is equivalent to "%e-%b-%Y", flags and width can change year
>                                                 ^^^^^
>                                                 pad?
>> +	       format. Recurse to avoid need to replicate %b and %Y formation. */
> 
> Sorry for being a nag, but doesn't that introduce an incompatible
> change?  The BSDs don't handle pad and width, they just call
> _fmt("%e-%b-%Y", ...).  Or am I missing how the BSD function works?

Yes if this function was actually BSD-like, but newlib strftime supports all the 
POSIX and GNU flags (including +, which was why why I couldn't add BSD %+ for 
default locale formatting), so I thought I should add POSIX extended year 
handling to support the extended year range and formats required, for 
compatibility with other %Y formatting in that function, and tests of that 
functionality.

-- 
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] 5+ messages in thread

* Re: [PATCH] strftime.c(__strftime): add %q, %v, tests; tweak %Z doc
  2022-10-24 23:50   ` Brian Inglis
@ 2022-10-25 10:38     ` Corinna Vinschen
  2022-10-26  3:05       ` Brian Inglis
  0 siblings, 1 reply; 5+ messages in thread
From: Corinna Vinschen @ 2022-10-25 10:38 UTC (permalink / raw)
  To: newlib

On Oct 24 17:50, Brian Inglis wrote:
> On 2022-10-24 06:07, Corinna Vinschen wrote:
> > On Oct 21 23:13, Brian Inglis wrote:
> > > +	case CQ('v'):	/* BSD/OSX/Ruby extension VMS/Oracle date format
> > > +			   from Arnold Robbins strftime version 3.0 */
> > > +	  { /* %v is equivalent to "%e-%b-%Y", flags and width can change year
> >                                                 ^^^^^
> >                                                 pad?
> > > +	       format. Recurse to avoid need to replicate %b and %Y formation. */
> > 
> > Sorry for being a nag, but doesn't that introduce an incompatible
> > change?  The BSDs don't handle pad and width, they just call
> > _fmt("%e-%b-%Y", ...).  Or am I missing how the BSD function works?
> 
> Yes if this function was actually BSD-like, but newlib strftime supports all
> the POSIX and GNU flags (including +, which was why why I couldn't add BSD
> %+ for default locale formatting), so I thought I should add POSIX extended
> year handling to support the extended year range and formats required, for
> compatibility with other %Y formatting in that function, and tests of that
> functionality.

Sounds ok to me on second thought.  Pushed.


Thanks,
Corinna


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

* Re: [PATCH] strftime.c(__strftime): add %q, %v, tests; tweak %Z doc
  2022-10-25 10:38     ` Corinna Vinschen
@ 2022-10-26  3:05       ` Brian Inglis
  0 siblings, 0 replies; 5+ messages in thread
From: Brian Inglis @ 2022-10-26  3:05 UTC (permalink / raw)
  To: newlib

On 2022-10-25 04:38, Corinna Vinschen wrote:
> On Oct 24 17:50, Brian Inglis wrote:
>> On 2022-10-24 06:07, Corinna Vinschen wrote:
>>> On Oct 21 23:13, Brian Inglis wrote:
>>>> +	case CQ('v'):	/* BSD/OSX/Ruby extension VMS/Oracle date format
>>>> +			   from Arnold Robbins strftime version 3.0 */
>>>> +	  { /* %v is equivalent to "%e-%b-%Y", flags and width can change year
>>>                                                  ^^^^^
>>>                                                  pad?
>>>> +	       format. Recurse to avoid need to replicate %b and %Y formation. */
>>>
>>> Sorry for being a nag, but doesn't that introduce an incompatible
>>> change?  The BSDs don't handle pad and width, they just call
>>> _fmt("%e-%b-%Y", ...).  Or am I missing how the BSD function works?
>>
>> Yes if this function was actually BSD-like, but newlib strftime supports all
>> the POSIX and GNU flags (including +, which was why why I couldn't add BSD
>> %+ for default locale formatting), so I thought I should add POSIX extended
>> year handling to support the extended year range and formats required, for
>> compatibility with other %Y formatting in that function, and tests of that
>> functionality.
> 
> Sounds ok to me on second thought.  Pushed.

Cheers!

-- 
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] 5+ messages in thread

end of thread, other threads:[~2022-10-26  3:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-22  5:13 [PATCH] strftime.c(__strftime): add %q, %v, tests; tweak %Z doc Brian Inglis
2022-10-24 12:07 ` Corinna Vinschen
2022-10-24 23:50   ` Brian Inglis
2022-10-25 10:38     ` Corinna Vinschen
2022-10-26  3:05       ` 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).