mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Bartosz Brachaczek <b.brachaczek@gmail.com>
Cc: musl@lists.openwall.com, rafal@milecki.pl
Subject: Re: Re: [PATCH libc-test] add strptime basic test
Date: Fri, 16 Nov 2018 16:34:53 -0500	[thread overview]
Message-ID: <20181116213453.GK5150@brightrain.aerifal.cx> (raw)
In-Reply-To: <CAGxPR-88phE1yeA3nhje15kbgt9csVShCMvqdS7p7DmJtEoMmg@mail.gmail.com>

On Fri, Nov 16, 2018 at 10:21:01PM +0100, Bartosz Brachaczek wrote:
> On Thu, Nov 15, 2018 at 11:12 AM Rafał Miłecki <zajec5@gmail.com> wrote:
> 
> > On 15.11.2018 08:34, Rafał Miłecki wrote:
> > > From: Rafał Miłecki <rafal@milecki.pl>
> > >
> > > Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
> >
> > I've just tried it with musl (I should have done that before sending a
> > patch) and noticed is fails with:
> >
> > "%Y-%m-%d": for "1991-08-25" expected 1991-08-25T00:00:00 (day 237: Sun)
> > but got 1991-08-25T00:00:00 (day 001: Sun)
> > "%d.%m.%y": for "25.08.91" expected 1991-08-25T00:00:00 (day 237: Sun) but
> > got 1991-08-25T00:00:00 (day 001: Sun)
> > "%D": for "08/25/91" expected 1991-08-25T00:00:00 (day 237: Sun) but got
> > 1991-08-25T00:00:00 (day 001: Sun)
> > "%d.%m.%y": for "21.10.15" expected 2015-10-21T00:00:00 (day 294: Wed) but
> > got 2015-10-21T00:00:00 (day 001: Sun)
> > "%d.%m.%y in %C th": for "10.7.56 in 18th" expected 1856-07-10T00:00:00
> > (day 192: Thu) but got 1856-07-10T00:00:00 (day 001: Sun)
> >
> > which I didn't expect.
> >
> > It's because I assumed glibc behavior which sets tm_wday and tm_yday.
> >
> > The man says:
> > "In principle, this function does not initialize tm but stores only the
> > values specified."
> >
> > There is a glibc behavior however:
> > "Details differ a bit between different UNIX sys-tems.  The glibc
> > implementation does not touch those fields which are not explicitly
> > specified, except that it recomputes the tm_wday and tm_yday field if
> > any of the year, month,  or  day  elements changed."
> >
> > I guess a correct test should allow any behavior and don't test tm_wday
> > and tm_yday fields.
> >
> >
> > It also fails with:
> >
> > "%F": failed to parse "1856-07-10"
> > "%s": failed to parse "683078400"
> > "%z": failed to parse "+0200"
> > "%z": failed to parse "-0530"
> > "%z": failed to parse "-06"
> >
> > but that's expected due to unimplemented %F %s and %z.
> >
> 
> I cannot find anything in the normative text that would suggest that
> recomputing tm_wday and/or tm_yday is required, but interestingly enough,
> the strptime example that is used in POSIX seems to rely on that. See:
> https://pubs.opengroup.org/onlinepubs/9699919799/functions/strptime.html.
> That example does not produce expected output using musl.
> 
> Possibly something that should be clarified in POSIX?

Yes, I think this calls for a defect report/request for
interpretation. Even if one intends that tm_[wy]day be updated, there
is no canonical correct way to do it. Certainly it can't happen
without sufficiently many constraints to determine the value, and it's
not clear what would happen when %a, %w, etc. are also present.
Overall, strptime is severely under-specified, and musl tends to err
on the side of not doing anything it's not specified to do, since it
could turn out that such action is contrary to intended interpretation
or future changes to the standard, in which case applications
depending on the behavior could be broken by fixing musl to conform.

Rich


      reply	other threads:[~2018-11-16 21:34 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-15  7:34 Rafał Miłecki
2018-11-15 10:12 ` Rafał Miłecki
2018-11-15 21:26   ` Szabolcs Nagy
2018-11-15 21:31     ` Rafał Miłecki
2018-11-16 21:36     ` Rich Felker
2018-11-16 21:21   ` Bartosz Brachaczek
2018-11-16 21:34     ` Rich Felker [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181116213453.GK5150@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=b.brachaczek@gmail.com \
    --cc=musl@lists.openwall.com \
    --cc=rafal@milecki.pl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).