From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: [musl] strptime(s, "%Y-%j", &tm) does not update month and day
Date: Mon, 13 May 2024 08:18:04 -0400 [thread overview]
Message-ID: <20240513121802.GX10433@brightrain.aerifal.cx> (raw)
In-Reply-To: <ZkB1pX8wTRe-4lhV@album.bayer.uni.cx>
On Sun, May 12, 2024 at 09:54:13AM +0200, Petr Pisar wrote:
> V Sat, May 11, 2024 at 05:28:54PM -0400, Rich Felker napsal(a):
> > On Sat, May 11, 2024 at 05:24:59PM +0200, Petr Pisar wrote:
> > > Hello,
> > >
> > > When debugging a libisds test failure with musl-1.2.5
> > > <https://bugs.gentoo.org/show_bug.cgi?id=928107>, I found that musl's
> > > strptime() does not handle "%Y-%j" properly. It accepts the format, it parses
> > > the input string, it returns a correct pointer past the input string, but it
> > > does not update tm.tm_mon and tm.tm_mday fileds of the third argument.
> >
> > This is behaving as specified. Previously, the behavior was
> > unspecified. POSIX has amended it for future issues as the resolution
> > of https://austingroupbugs.net/view.php?id=1727 to read:
> >
> > The tm_yday member of the tm structure pointed to by tm shall be
> > set to this number minus 1.
> >
> > strptime generally does not behave like mktime, doing
> > normalizations/conversions.
> >
> I see. I thought that strptime() does the normalization. Reading
> mktime() specification reveals it has a side effect of normalizing tm_yday
> from tm_year, tm_mon, and tm_mday.
>
> However, I need the oposite and I cannot find any standard library function
> for that. I will probaly resort to my own implementation with the drawback
> of assumption that rules for leap years in Gregorian calendar won't change.
That's certainly an option. I think you can also use mktime, though,
if you want. Starting from a valid struct tm for Jan 1, then adding
the tm_yday number to tm_mday, should get you most of the way there,
short of timezone/dst mess. You could avoid that by using timegm, or
if you assume POSIX-compatible time_t, just adding 86400*tm_yday to
the time_t.
Rich
next prev parent reply other threads:[~2024-05-13 12:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-11 15:24 Petr Pisar
2024-05-11 21:28 ` Rich Felker
2024-05-12 7:54 ` Petr Pisar
2024-05-13 12:18 ` Rich Felker [this message]
2024-05-13 21:18 ` Thorsten Glaser
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=20240513121802.GX10433@brightrain.aerifal.cx \
--to=dalias@libc.org \
--cc=musl@lists.openwall.com \
/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).