mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 21:44:55 +01:00
Don't compile strptime unless its required (#6424)
This commit is contained in:
parent
f5ac1bd905
commit
7cb8f99884
2 changed files with 10 additions and 0 deletions
|
@ -1,4 +1,6 @@
|
||||||
|
#ifdef USE_DATETIME
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "time.h" // NOLINT
|
#include "time.h" // NOLINT
|
||||||
|
@ -64,6 +66,8 @@ std::string ESPTime::strftime(const std::string &format) {
|
||||||
return timestr;
|
return timestr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_DATETIME
|
||||||
|
|
||||||
bool ESPTime::strptime(const std::string &time_to_parse, ESPTime &esp_time) {
|
bool ESPTime::strptime(const std::string &time_to_parse, ESPTime &esp_time) {
|
||||||
// clang-format off
|
// clang-format off
|
||||||
std::regex dt_regex(R"(^
|
std::regex dt_regex(R"(^
|
||||||
|
@ -102,6 +106,8 @@ bool ESPTime::strptime(const std::string &time_to_parse, ESPTime &esp_time) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
void ESPTime::increment_second() {
|
void ESPTime::increment_second() {
|
||||||
this->timestamp++;
|
this->timestamp++;
|
||||||
if (!increment_time_value(this->second, 0, 60))
|
if (!increment_time_value(this->second, 0, 60))
|
||||||
|
|
|
@ -67,6 +67,8 @@ struct ESPTime {
|
||||||
this->day_of_year < 367 && this->month > 0 && this->month < 13;
|
this->day_of_year < 367 && this->month > 0 && this->month < 13;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_DATETIME
|
||||||
|
|
||||||
/** Convert a string to ESPTime struct as specified by the format argument.
|
/** Convert a string to ESPTime struct as specified by the format argument.
|
||||||
* @param time_to_parse null-terminated c string formatet like this: 2020-08-25 05:30:00.
|
* @param time_to_parse null-terminated c string formatet like this: 2020-08-25 05:30:00.
|
||||||
* @param esp_time an instance of a ESPTime struct
|
* @param esp_time an instance of a ESPTime struct
|
||||||
|
@ -74,6 +76,8 @@ struct ESPTime {
|
||||||
*/
|
*/
|
||||||
static bool strptime(const std::string &time_to_parse, ESPTime &esp_time);
|
static bool strptime(const std::string &time_to_parse, ESPTime &esp_time);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/// Convert a C tm struct instance with a C unix epoch timestamp to an ESPTime instance.
|
/// Convert a C tm struct instance with a C unix epoch timestamp to an ESPTime instance.
|
||||||
static ESPTime from_c_tm(struct tm *c_tm, time_t c_time);
|
static ESPTime from_c_tm(struct tm *c_tm, time_t c_time);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue