From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 8EBCE3857C58; Tue, 25 Oct 2022 10:37:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8EBCE3857C58 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666694256; bh=s6e4FhdUVbUP8vPBcFEymIqWdWUju5QYHMDULETJKFQ=; h=From:To:Subject:Date:From; b=Avh4rzxOylkwVWY5E29e7Qi0DKXm43GERjdLWoFLPxEIleZykpZ6oTno8fL/2Gd3O QHdMSrRuN+159JyYDCvWVhoCuCbMOEGDjtuLa3CbZ1Y+YXa9qcy2e63oh1Kkew4grp mo5H/gyDVOvaa3nfE0oVcWiKHHhXtlExR2hEH7Jo= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] strftime.c(__strftime): add %q, %v, tests; tweak %Z doc X-Act-Checkin: newlib-cygwin X-Git-Author: Brian Inglis X-Git-Refname: refs/heads/master X-Git-Oldrev: 7f7e4e5bc5e01a4dc90a10ebff8949f1c0c034dd X-Git-Newrev: 737e2004a3bbf8a9419b4b7a95c4e4735c5c0a97 Message-Id: <20221025103736.8EBCE3857C58@sourceware.org> Date: Tue, 25 Oct 2022 10:37:36 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D737e2004a3b= bf8a9419b4b7a95c4e4735c5c0a97 commit 737e2004a3bbf8a9419b4b7a95c4e4735c5c0a97 Author: Brian Inglis Date: Fri Oct 21 23:13:52 2022 -0600 strftime.c(__strftime): add %q, %v, tests; tweak %Z doc =20 %q GNU quarter year 1-4 %v BSD/OSX/Ruby VMS/Oracle %e-%b-%Y %Z change time zone *name* to *abbreviation* Diff: --- newlib/libc/time/strftime.c | 58 +++++++++++++++++++++++++++++++++++++++++= +--- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/newlib/libc/time/strftime.c b/newlib/libc/time/strftime.c index 9c884dca9..420745d90 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] =20 +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 c= ontains 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] =20 +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] =20 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] =20 o %% A single character, `<<%>>'. @@ -1086,6 +1094,11 @@ recurse: return 0; } break; + case CQ('q'): /* GNU quarter year */ + len =3D snprintf (&s[count], maxsize - count, CQ("%.1d"), + tim_p->tm_mon / 3 + 1); + CHECK_LENGTH (); + break; case CQ('R'): len =3D 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 =3D fmtbuf; + STRCPY (fmt, CQ("%e-%b-%")); + fmt +=3D strlen (fmt); + if (pad) /* '0' or '+' */ + *fmt++ =3D pad; + else + *fmt++ =3D '+'; + if (!pad) + width =3D 10; + if (width < 6) + width =3D 6; + width -=3D 6; + if (width) + { + len =3D snprintf (fmt, fmtbuf + 32 - fmt, CQ("%lu"), width); + if (len > 0) + fmt +=3D len; + } + STRCPY (fmt, CQ("Y")); + len =3D __strftime (&s[count], maxsize - count, fmtbuf, tim_p, + locale, era_info, alt_digits); + if (len > 0) + count +=3D len; + else + return 0; + } + break; case CQ('w'): #ifdef _WANT_C99_TIME_FORMATS if (alt =3D=3D CQ('O') && *alt_digits) @@ -1531,6 +1575,7 @@ const struct test Vec0[] =3D { { 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[] =3D { { 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[] =3D { { 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[] =3D { { 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[] =3D { { 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[] =3D { { 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[] =3D { { 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[] =3D { { 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) },