3 #ifdef USE_DATETIME_DATE 10 static const char *
const TAG =
"datetime.date_entity";
17 if (this->year_ < 1970 || this->
year_ > 3000) {
19 ESP_LOGE(TAG,
"Year must be between 1970 and 3000");
22 if (this->month_ < 1 || this->
month_ > 12) {
24 ESP_LOGE(TAG,
"Month must be between 1 and 12");
40 if (this->
year_.has_value() && (this->
year_ < 1970 || this->
year_ > 3000)) {
41 ESP_LOGE(TAG,
"Year must be between 1970 and 3000");
47 ESP_LOGE(TAG,
"Month must be between 1 and 12");
51 if (this->
day_.has_value()) {
54 if (this->
month_.has_value()) {
57 if (this->parent_->month != 0) {
58 month = this->parent_->month;
60 ESP_LOGE(TAG,
"Month must be set to validate day");
64 if (this->
year_.has_value()) {
67 if (this->parent_->year != 0) {
68 year = this->parent_->year;
70 ESP_LOGE(TAG,
"Year must be set to validate day");
75 ESP_LOGE(TAG,
"Day must be between 1 and %d for month %d",
days_in_month(month, year), month);
83 ESP_LOGD(TAG,
"'%s' - Setting", this->parent_->get_name().c_str());
85 if (this->
year_.has_value()) {
86 ESP_LOGD(TAG,
" Year: %d", *this->
year_);
88 if (this->
month_.has_value()) {
89 ESP_LOGD(TAG,
" Month: %d", *this->
month_);
91 if (this->
day_.has_value()) {
92 ESP_LOGD(TAG,
" Day: %d", *this->
day_);
94 this->parent_->control(*
this);
109 ESP_LOGE(TAG,
"Could not convert the date string to an ESPTime object");
112 return this->set_date(
val);
131 #endif // USE_DATETIME_DATE
A more user-friendly version of struct tm from time.h.
CallbackManager< void()> state_callback_
uint8_t days_in_month(uint8_t month, uint16_t year)
DateCall & set_date(uint16_t year, uint8_t month, uint8_t day)
DateCall to_call(DateEntity *date)
Implementation of SPI Controller mode.
uint8_t month
month; january=1 [1-12]
void apply(DateEntity *date)
uint8_t day_of_month
day of the month [1-31]
const StringRef & get_name() const
static bool strptime(const std::string &time_to_parse, ESPTime &esp_time)
Convert a string to ESPTime struct as specified by the format argument.