strptime: fix am/pm converting to 24-hour system

Fix the issue of parsing 08:00AM, which currently gives a 20:00 representation.
This commit is contained in:
Alexey Lapshin 2024-02-20 18:51:04 +00:00 committed by Corinna Vinschen
parent c90b20192d
commit acf176104f
1 changed files with 6 additions and 5 deletions

View 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);