[PATCH] Fix strptime decode for musl libc

[PATCH] Fix strptime decode for musl libc

From: psykose
Cc: psykose
POSIX does not define a %F for strptime[1], but does define %F for
strftime[2]. Afaik most libc's implement %F for both, but musl is very
standards-compliant and does not have %F on strptime, leading to
unparsed message tag times, which causes all backlog sent from bouncer
on startup to have a timestamp of the current time, instead of the
actual timestamp sent.

[1] https://pubs.opengroup.org/onlinepubs/9699919799/functions/strptime.html
[2] https://pubs.opengroup.org/onlinepubs/9699919799/functions/strftime.html
---
 handle.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/handle.c b/handle.c
index 7b9835f..61b645d 100644
--- a/handle.c
+++ b/handle.c
@@ -91,7 +91,7 @@ static const time_t *tagTime(const struct Message *msg) {
 	static time_t time;
 	struct tm tm;
 	if (!msg->tags[TagTime]) return NULL;
-	if (!strptime(msg->tags[TagTime], "%FT%T", &tm)) return NULL;
+	if (!strptime(msg->tags[TagTime], "%Y-%m-%dT%T", &tm)) return NULL;
 	time = timegm(&tm);
 	return &time;
 }
-- 
2.33.1

Re: [PATCH] Fix strptime decode for musl libc

From: june
To: psykose
> On Oct 26, 2021, at 04:14, psykose <alice@ayaya.dev> wrote:
> 
> POSIX does not define a %F for strptime[1], but does define %F for
> strftime[2]. Afaik most libc's implement %F for both, but musl is very
> standards-compliant and does not have %F on strptime, leading to
> unparsed message tag times, which causes all backlog sent from bouncer
> on startup to have a timestamp of the current time, instead of the
> actual timestamp sent.
> 
> [1] https://pubs.opengroup.org/onlinepubs/9699919799/functions/strptime.html
> [2] https://pubs.opengroup.org/onlinepubs/9699919799/functions/strftime.html

Huh. Seems like an oversight that %T is defined for strptime but
not %F. I would expect neither or both.

Applied.