]> sourceware.org Git - newlib-cygwin.git/commitdiff
strptime: fix am/pm converting to 24-hour system
authorAlexey Lapshin <alexey.lapshin@espressif.com>
Tue, 20 Feb 2024 18:51:04 +0000 (18:51 +0000)
committerCorinna Vinschen <corinna@vinschen.de>
Wed, 21 Feb 2024 14:52:14 +0000 (15:52 +0100)
Fix the issue of parsing 08:00AM, which currently gives a 20:00 representation.

newlib/libc/time/strptime.c

index 6220ff73ad27bc17e6bc0313a57643da02bb57c3..188218059a36269fa79be3a35238a2c8c7b2447f 100644 (file)
@@ -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);
This page took 0.037565 seconds and 5 git commands to generate.