Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strptime doesn't parse AM/PM (%p) #9184

Closed
1 task done
chconnor opened this issue Jan 28, 2024 · 4 comments
Closed
1 task done

strptime doesn't parse AM/PM (%p) #9184

chconnor opened this issue Jan 28, 2024 · 4 comments

Comments

@chconnor
Copy link

chconnor commented Jan 28, 2024

Board

ESP32

Device Description

ESP32-DevKitC-VIE

Hardware Configuration

many things

Version

v2.0.11

IDE Name

vscode + Platform IO

Operating System

Linux

Flash frequency

default?

PSRAM enabled

yes

Upload speed

default?

Description

Hopefully this is the proper place to post this -- if not please let me know:

strptime() does not seem to parse AM/PM correctly (using the %p token). You will see in the demo code that it fails to detect AM and always makes the time PM. On my desktop, that demo code will print "hour is 8" but on the ESP32 it will print "hour is 20".

My understanding is that the parsing of %p depends on the locale, which may not use AM/PM, but I don't see a way to configure things in a way that makes %p work.

Edit to add: %p does change how the parsing works, however. Parsing "8:00AM" or "8:00PM" comes back as 20:00 with %p present, or always 08:00 without %p.

Sketch

#include <Arduino.h>
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <time.h>

void setup()
{
  Serial.begin(115200);
  while (!Serial) delay(10);

  char timestr[7] = "8:00AM";
  static struct tm temptm;
  static time_t temptime;
  temptime = time(NULL);
  temptm = *localtime(&temptime);
  strptime(timestr, "%I:%M%p", &temptm);
  Serial.printf("hour is %d\n", temptm.tm_hour);
}

void loop()
{
    delay(100);
}

Debug Message

n/a

Other Steps to Reproduce

See also this user report: https://esp32.com/viewtopic.php?t=36652

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@chconnor chconnor added the Status: Awaiting triage Issue is waiting for triage label Jan 28, 2024
@P-R-O-C-H-Y
Copy link
Member

Hello @chconnor, I can confirm the issue and I have reported it to the related team to take a look at this as it cannot be fixed in Arduino project. Tested also with ESP-IDF with same results. When I know any news I will post an update here.

@P-R-O-C-H-Y P-R-O-C-H-Y added Type: Bug 🐛 All bugs Area: ESP-IDF related ESP-IDF related issues and removed Status: Awaiting triage Issue is waiting for triage labels Jan 29, 2024
@Lapshin
Copy link

Lapshin commented Feb 20, 2024

Looks like there is a bug in newlib library. Sent a fix https://sourceware.org/pipermail/newlib/2024/021031.html

Next IDF's toolchain release will have the fix

@VojtechBartoska
Copy link
Contributor

this was fixed in esp-4.3.0 of newlib, closing as solved.

@codegrue
Copy link

codegrue commented May 3, 2024

When will this fix be in the released espressif32 Arduino library? I am seeing 6.5.0 as the latest currently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

5 participants