From: Alexey Lapshin <alexey.lapshin@espressif.com>
To: "newlib@sourceware.org" <newlib@sourceware.org>
Cc: Alexey Gerenkov <alexey.gerenkov@espressif.com>,
Ivan Grokhotkov <ivan@espressif.com>
Subject: [PATCH] strptime: fix am/pm converting to 24-hour system
Date: Tue, 20 Feb 2024 18:51:04 +0000 [thread overview]
Message-ID: <47c4248d8449aa6efa9ef3839ba2a9f329fcea9b.camel@espressif.com> (raw)
Fix the issue of parsing 08:00AM, which currently gives a 20:00 representation.
---
newlib/libc/time/strptime.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/newlib/libc/time/strptime.c b/newlib/libc/time/strptime.c
index 6220ff73a..188218059 100644
--- a/newlib/libc/time/strptime.c
+++ b/newlib/libc/time/strptime.c
@@ -292,11 +292,12 @@ strptime_l (const char *buf, const char *format, struct tm *timeptr,
ret = match_string (&buf, _ctloc (am_pm), locale);
if (ret < 0)
return NULL;
- if (timeptr->tm_hour == 0) {
- if (ret == 1)
- timeptr->tm_hour = 12;
- } else
- timeptr->tm_hour += 12;
+ if (timeptr->tm_hour > 12)
+ return NULL;
+ else if (timeptr->tm_hour == 12)
+ timeptr->tm_hour = ret * 12;
+ else
+ timeptr->tm_hour += ret * 12;
break;
case 'q' : /* quarter year - GNU extension */
ret = strtol_l (buf, &s, 10, locale);
--
2.34.1
next reply other threads:[~2024-02-20 18:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-20 18:51 Alexey Lapshin [this message]
2024-02-21 14:53 ` Corinna Vinschen
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=47c4248d8449aa6efa9ef3839ba2a9f329fcea9b.camel@espressif.com \
--to=alexey.lapshin@espressif.com \
--cc=alexey.gerenkov@espressif.com \
--cc=ivan@espressif.com \
--cc=newlib@sourceware.org \
/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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).