|
|
Message-ID: <20261120150142.GJ5716@brightrain.aerifal.cx>
Date: Fri, 20 Nov 2026 10:01:42 -0500
From: Rich Felker <dalias@...c.org>
To: Bruno Haible <bruno@...sp.org>
Cc: musl@...ts.openwall.com
Subject: Re: getdate() returns invalid date
On Fri, Nov 20, 2026 at 03:46:25PM +0100, Bruno Haible wrote:
> Hi,
>
> POSIX:2024 specifies getdate() in
> https://pubs.opengroup.org/onlinepubs/9799919799/functions/getdate.html
>
> Among others, in the 4th example, last line of the table, it has an example
> where
> Line in template = %H:%M
>
> Here's my test case:
>
> $ cat datemsk
> %m
> %A %B %d, %Y, %H:%M:%S
> %A
> %B
> %m/%d/%y %I %p
> %d,%m,%Y %H:%M
> %m/%d/%y
> %d.%m.%y
> %y-%m-%d
> %A %H:%M:%S
> %a
> %b %a
> %b %a %Y
> %a %H
> %b %H:%S
> %H:%M
>
> $ cat foo.c
> #define _GNU_SOURCE 1
> #include <time.h>
> #include <stdio.h>
>
> int
> main ()
> {
> struct tm *t = getdate ("13:30");
> if (t == NULL)
> printf ("getdate failed\n");
> else
> {
> char buf[100];
> strftime (buf, sizeof (buf), "getdate returned %Y-%m-%d %H:%M:%S", t);
> puts (buf);
> }
> }
>
> Build and run it:
> $ gcc -Wall foo.c
> $ DATEMSK=`pwd`/datemsk ./a.out
>
> Expected output:
> getdate returned 2026-11-21 13:30:00
>
> Actual output:
> getdate returned 1900-14-13 13:30:00
>
> Not only the year and the day field are wrong; also the month field is
> out-of-range.
>
> If I reduce 'datemsk' to a single line "%H:%M":
>
> Expected output:
> getdate returned 2026-11-21 13:30:00
>
> Actual output:
> getdate returned 1900-01-00 13:30:00
>
> In this case the day field is out-of-range.
>
> Seen in Alpine Linux 3.24 (i.e. musl 1.2.6-r3, according to [1]).
Thanks! This seems to be a matter of misinterpreting the specification
as basically just a frontend around strptime, when getdate also has to
do more, including:
- initialize the broken-down time based on current time and timezone
- interpret certain conversion specifications forward relative to
current time
I'm not sure how involved fixing this will be and whether it makes
sense to use strptime still or whether it needs to do its own thing.
Rich
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.