mirror of
https://github.com/esphome/esphome.git
synced 2026-03-23 05:13:03 +08:00
[time] Fix timezone_offset() and recalc_timestamp_local() always returning UTC (#14996)
This commit is contained in:
@@ -283,19 +283,15 @@ void ESPTime::recalc_timestamp_local() {
|
||||
bool dst_valid = time::is_in_dst(utc_if_dst, tz);
|
||||
bool std_valid = !time::is_in_dst(utc_if_std, tz);
|
||||
|
||||
if (dst_valid && std_valid) {
|
||||
// Ambiguous time (repeated hour during fall-back) - prefer standard time
|
||||
this->timestamp = utc_if_std;
|
||||
} else if (dst_valid) {
|
||||
if (dst_valid && !std_valid) {
|
||||
// Only DST interpretation is valid
|
||||
this->timestamp = utc_if_dst;
|
||||
} else if (std_valid) {
|
||||
// Only standard interpretation is valid
|
||||
this->timestamp = utc_if_std;
|
||||
} else {
|
||||
// Invalid time (skipped hour during spring-forward)
|
||||
// libc normalizes forward: 02:30 CST -> 08:30 UTC -> 03:30 CDT
|
||||
// Using std offset achieves this since the UTC result falls during DST
|
||||
// All other cases use standard offset:
|
||||
// - Both valid (ambiguous fall-back repeated hour): prefer standard time
|
||||
// - Only standard valid: straightforward
|
||||
// - Neither valid (spring-forward skipped hour): std offset normalizes
|
||||
// forward to match libc mktime(), e.g. 02:30 CST -> 03:30 CDT
|
||||
this->timestamp = utc_if_std;
|
||||
}
|
||||
#else
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/defines.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
Reference in New Issue
Block a user