diff options
author | Alexey Lapshin <alexey.lapshin@espressif.com> | 2024-02-20 18:51:04 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2024-02-21 15:52:14 +0100 |
commit | acf176104fc5410bfec0635ed2c5a21971b9c938 (patch) | |
tree | f6b9583a2ff7425d07efca9e54b865b294bd4048 /newlib/libc | |
parent | c90b20192dda446542a49578b9a74d8ee47f032c (diff) | |
download | newlib-acf176104fc5410bfec0635ed2c5a21971b9c938.zip newlib-acf176104fc5410bfec0635ed2c5a21971b9c938.tar.gz newlib-acf176104fc5410bfec0635ed2c5a21971b9c938.tar.bz2 |
strptime: fix am/pm converting to 24-hour system
Fix the issue of parsing 08:00AM, which currently gives a 20:00 representation.
Diffstat (limited to 'newlib/libc')
-rw-r--r-- | newlib/libc/time/strptime.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/newlib/libc/time/strptime.c b/newlib/libc/time/strptime.c index 6220ff7..1882180 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); |