[datetime] datetime-datetime strptime support value string without seconds (#6867)

This commit is contained in:
RFDarter 2024-06-07 22:29:10 +02:00 committed by GitHub
parent 8718e15a6a
commit d77ea46157
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -84,6 +84,16 @@ bool ESPTime::strptime(const std::string &time_to_parse, ESPTime &esp_time) {
esp_time.hour = hour; esp_time.hour = hour;
esp_time.minute = minute; esp_time.minute = minute;
esp_time.second = second; esp_time.second = second;
} else if (sscanf(time_to_parse.c_str(), "%04hu-%02hhu-%02hhu %02hhu:%02hhu %n", &year, &month, &day, // NOLINT
&hour, // NOLINT
&minute, &num) == 5 && // NOLINT
num == time_to_parse.size()) {
esp_time.year = year;
esp_time.month = month;
esp_time.day_of_month = day;
esp_time.hour = hour;
esp_time.minute = minute;
esp_time.second = 0;
} else if (sscanf(time_to_parse.c_str(), "%02hhu:%02hhu:%02hhu %n", &hour, &minute, &second, &num) == 3 && // NOLINT } else if (sscanf(time_to_parse.c_str(), "%02hhu:%02hhu:%02hhu %n", &hour, &minute, &second, &num) == 3 && // NOLINT
num == time_to_parse.size()) { num == time_to_parse.size()) {
esp_time.hour = hour; esp_time.hour = hour;