mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] strptime: Add %F format (glibc extension).
@ 2018-02-22 21:53 Przemyslaw Pawelczyk
  2018-02-22 23:44 ` Rich Felker
  0 siblings, 1 reply; 3+ messages in thread
From: Przemyslaw Pawelczyk @ 2018-02-22 21:53 UTC (permalink / raw)
  To: musl

%F is a shortcut for %Y-%m-%d, the ISO 8601 date format.
It's already present in POSIX's strftime(), so it makes sense to support
it in a converse function too.
---

I'm not subscribed to ML, so please CC me in case of replying.

 src/time/strptime.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/time/strptime.c b/src/time/strptime.c
index c54a0d8c4c52..2c0d45574819 100644
--- a/src/time/strptime.c
+++ b/src/time/strptime.c
@@ -59,6 +59,10 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
 			s = strptime(s, "%m/%d/%y", tm);
 			if (!s) return 0;
 			break;
+		case 'F':
+			s = strptime(s, "%Y-%m-%d", tm);
+			if (!s) return 0;
+			break;
 		case 'H':
 			dest = &tm->tm_hour;
 			min = 0;
-- 
2.13.5



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

* Re: [PATCH] strptime: Add %F format (glibc extension).
  2018-02-22 21:53 [PATCH] strptime: Add %F format (glibc extension) Przemyslaw Pawelczyk
@ 2018-02-22 23:44 ` Rich Felker
  2018-02-23 10:56   ` Natanael Copa
  0 siblings, 1 reply; 3+ messages in thread
From: Rich Felker @ 2018-02-22 23:44 UTC (permalink / raw)
  To: musl

On Thu, Feb 22, 2018 at 10:53:39PM +0100, Przemyslaw Pawelczyk wrote:
> %F is a shortcut for %Y-%m-%d, the ISO 8601 date format.
> It's already present in POSIX's strftime(), so it makes sense to support
> it in a converse function too.
> ---
> 
> I'm not subscribed to ML, so please CC me in case of replying.
> 
>  src/time/strptime.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/src/time/strptime.c b/src/time/strptime.c
> index c54a0d8c4c52..2c0d45574819 100644
> --- a/src/time/strptime.c
> +++ b/src/time/strptime.c
> @@ -59,6 +59,10 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
>  			s = strptime(s, "%m/%d/%y", tm);
>  			if (!s) return 0;
>  			break;
> +		case 'F':
> +			s = strptime(s, "%Y-%m-%d", tm);
> +			if (!s) return 0;
> +			break;
>  		case 'H':
>  			dest = &tm->tm_hour;
>  			min = 0;

Not having looked at this function in a while, I was doubtful the
above would work, but in fact it looks like it does (analogous to the
above case). While lots of this function is underspecified, the
contract for the return value is well-designed.

The want_century logic may be incomplete for %D and now %F, though. If
so that's a separate issue from lack of %F extension and should be
fixed in a separate patch. I think %F just needs to set want_century
to 0, but %D might have more work to do.

Rich


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

* Re: [PATCH] strptime: Add %F format (glibc extension).
  2018-02-22 23:44 ` Rich Felker
@ 2018-02-23 10:56   ` Natanael Copa
  0 siblings, 0 replies; 3+ messages in thread
From: Natanael Copa @ 2018-02-23 10:56 UTC (permalink / raw)
  To: Rich Felker; +Cc: musl

On Thu, 22 Feb 2018 18:44:41 -0500
Rich Felker <dalias@libc.org> wrote:

> On Thu, Feb 22, 2018 at 10:53:39PM +0100, Przemyslaw Pawelczyk wrote:
> > %F is a shortcut for %Y-%m-%d, the ISO 8601 date format.
> > It's already present in POSIX's strftime(), so it makes sense to support
> > it in a converse function too.
> > ---
> > 
> > I'm not subscribed to ML, so please CC me in case of replying.
> > 
> >  src/time/strptime.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> > 
> > diff --git a/src/time/strptime.c b/src/time/strptime.c
> > index c54a0d8c4c52..2c0d45574819 100644
> > --- a/src/time/strptime.c
> > +++ b/src/time/strptime.c
> > @@ -59,6 +59,10 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
> >  			s = strptime(s, "%m/%d/%y", tm);
> >  			if (!s) return 0;
> >  			break;
> > +		case 'F':
> > +			s = strptime(s, "%Y-%m-%d", tm);
> > +			if (!s) return 0;
> > +			break;
> >  		case 'H':
> >  			dest = &tm->tm_hour;
> >  			min = 0;  
> 
> Not having looked at this function in a while, I was doubtful the
> above would work, but in fact it looks like it does (analogous to the
> above case). While lots of this function is underspecified, the
> contract for the return value is well-designed.
> 
> The want_century logic may be incomplete for %D and now %F, though. If
> so that's a separate issue from lack of %F extension and should be
> fixed in a separate patch. I think %F just needs to set want_century
> to 0, but %D might have more work to do.
> 
> Rich

FWIW, '%F' is mentioned here:
http://austingroupbugs.net/view.php?id=879

<tt>F</tt> This specifier is similar to <tt>%Y-%m-%d</tt> where the
characters up to the first <hyphen-minus> separator shall be converted
as for %Y but with unlimited field width, the characters between the
two <hyphen-minus> separators shall be converted as for %m, and the
characters after the last <hyphen-minus> separator shall be converted
as for %d. If a field width is specified, each of the %Y, %m, and %d
conversions shall not convert any characters past the overall %F field
width.

-nc


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

end of thread, other threads:[~2018-02-23 10:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-22 21:53 [PATCH] strptime: Add %F format (glibc extension) Przemyslaw Pawelczyk
2018-02-22 23:44 ` Rich Felker
2018-02-23 10:56   ` Natanael Copa

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).