mirror of
https://github.com/esphome/esphome.git
synced 2026-02-08 00:31:58 +00:00
aioesphomeapi and esphome both always have M format, it was overkill
This commit is contained in:
@@ -342,41 +342,6 @@ bool __attribute__((noinline)) is_in_dst(time_t utc_epoch, const ParsedTimezone
|
||||
}
|
||||
}
|
||||
|
||||
size_t format_dst_rule(const DSTRule &rule, std::span<char, DST_RULE_BUF_SIZE> buf) {
|
||||
// Format rule part
|
||||
int pos = 0;
|
||||
switch (rule.type) {
|
||||
case DSTRuleType::MONTH_WEEK_DAY:
|
||||
pos = snprintf(buf.data(), buf.size(), "M%d.%d.%d", rule.month, rule.week, rule.day_of_week);
|
||||
break;
|
||||
case DSTRuleType::JULIAN_NO_LEAP:
|
||||
pos = snprintf(buf.data(), buf.size(), "J%d", rule.day);
|
||||
break;
|
||||
case DSTRuleType::DAY_OF_YEAR:
|
||||
pos = snprintf(buf.data(), buf.size(), "%d", rule.day);
|
||||
break;
|
||||
}
|
||||
|
||||
// Format time part
|
||||
int32_t time_secs = rule.time_seconds;
|
||||
char sign = time_secs < 0 ? '-' : '/';
|
||||
if (time_secs < 0)
|
||||
time_secs = -time_secs;
|
||||
int hours = time_secs / 3600;
|
||||
int mins = (time_secs % 3600) / 60;
|
||||
int secs = time_secs % 60;
|
||||
|
||||
if (secs != 0) {
|
||||
pos += snprintf(buf.data() + pos, buf.size() - pos, "%c%d:%02d:%02d", sign, hours, mins, secs);
|
||||
} else if (mins != 0) {
|
||||
pos += snprintf(buf.data() + pos, buf.size() - pos, "%c%d:%02d", sign, hours, mins);
|
||||
} else {
|
||||
pos += snprintf(buf.data() + pos, buf.size() - pos, "%c%d", sign, hours);
|
||||
}
|
||||
|
||||
return static_cast<size_t>(pos);
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
bool parse_posix_tz(const char *tz_string, ParsedTimezone &result) {
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#include <cstdint>
|
||||
#include <ctime>
|
||||
#include <span>
|
||||
|
||||
namespace esphome::time {
|
||||
|
||||
@@ -113,15 +112,6 @@ time_t calculate_dst_transition(int year, const DSTRule &rule, int32_t base_offs
|
||||
/// @return true if DST is in effect at the given time
|
||||
bool is_in_dst(time_t utc_epoch, const ParsedTimezone &tz);
|
||||
|
||||
/// Buffer size for format_dst_rule output
|
||||
static constexpr size_t DST_RULE_BUF_SIZE = 24;
|
||||
|
||||
/// Format a DST rule for logging/display
|
||||
/// @param rule The DST rule to format
|
||||
/// @param buf Output buffer
|
||||
/// @return Number of characters written (excluding null terminator)
|
||||
size_t format_dst_rule(const DSTRule &rule, std::span<char, DST_RULE_BUF_SIZE> buf);
|
||||
|
||||
} // namespace internal
|
||||
|
||||
} // namespace esphome::time
|
||||
|
||||
@@ -30,10 +30,11 @@ void RealTimeClock::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "Timezone: UTC%+d:%02d", std_hours, std_mins);
|
||||
if (this->parsed_tz_.has_dst) {
|
||||
int dst_hours = -this->parsed_tz_.dst_offset_seconds / 3600;
|
||||
char start_buf[internal::DST_RULE_BUF_SIZE], end_buf[internal::DST_RULE_BUF_SIZE];
|
||||
internal::format_dst_rule(this->parsed_tz_.dst_start, start_buf);
|
||||
internal::format_dst_rule(this->parsed_tz_.dst_end, end_buf);
|
||||
ESP_LOGCONFIG(TAG, " DST: UTC%+d, %s - %s", dst_hours, start_buf, end_buf);
|
||||
ESP_LOGCONFIG(TAG, " DST: UTC%+d, M%d.%d.%d/%" PRId32 " - M%d.%d.%d/%" PRId32, dst_hours,
|
||||
this->parsed_tz_.dst_start.month, this->parsed_tz_.dst_start.week,
|
||||
this->parsed_tz_.dst_start.day_of_week, this->parsed_tz_.dst_start.time_seconds / 3600,
|
||||
this->parsed_tz_.dst_end.month, this->parsed_tz_.dst_end.week, this->parsed_tz_.dst_end.day_of_week,
|
||||
this->parsed_tz_.dst_end.time_seconds / 3600);
|
||||
}
|
||||
#endif
|
||||
auto time = this->now();
|
||||
|
||||
Reference in New Issue
Block a user