Commit Graph
24 Commits
Author SHA1 Message Date
J. Nick Koston 5d93713404 [time] Guard against format string ending with bare % 2026-03-30 22:15:34 -10:00
J. Nick Koston d0d8f2935d [time] Handle %%Z/%%z correctly in strftime format substitution 2026-03-30 21:45:34 -10:00
J. Nick Koston 38e3095e35 [time] Fix strftime %Z and %z returning GMT/+0000 instead of actual timezone
Since the timezone bloat elimination (#13635) removed setenv("TZ")/tzset()
on embedded platforms, libc's ::strftime no longer has access to timezone
state for %Z and %z format specifiers. The time values (hour, minute, etc.)
are correct since they come from our custom timezone parser via struct tm
fields, but %Z and %z read from libc's internal _tzname/_timezone which
are stuck at GMT/+0000.

Fix by substituting %Z and %z in the format string with the correct
"+HHMM"/"-HHMM" designation computed from our parsed timezone offset
before passing to ::strftime. The substitution only runs when %Z or %z
are present in the format string, so there is no overhead for the common
case.

Also refactors strftime_to() to delegate to strftime() instead of
duplicating the ::strftime call, ensuring both code paths get the fix.
2026-03-30 21:26:23 -10:00
J. Nick Koston f457b995f7 [datetime] Fix state_as_esptime() returning invalid timestamp (#15128) 2026-03-24 14:03:56 -10:00
J. Nick Koston a9a8f4cb3b [time] Fix timezone_offset() and recalc_timestamp_local() always returning UTC (#14996) 2026-03-20 13:58:14 -10:00
J. Nick KostonandClaude Opus 4.6 1ccfcfc8d8 [time] Eliminate libc timezone bloat (~9.5KB flash ESP32, ~2% RAM on ESP8266) (#13635)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 15:12:44 -10:00
ede8235aae [core] more accurate check for leap year and valid day_of_month (#14197)
Co-authored-by: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-02-25 16:46:28 +00:00
J. Nick Koston cd4cb8b3ec [datetime] Add const char * overloads for string parsing to avoid heap allocation (#13363) 2026-01-20 17:50:01 -10:00
J. Nick Koston 20927674da [sun] Eliminate heap allocation in text sensor (#13037) 2026-01-07 08:24:09 -10:00
J. Nick Koston 3377080272 [core] Simplify ESPTime::strftime() and save 20 bytes flash (#11539) 2025-10-28 11:16:09 +13:00
J. Nick Koston 24dcc1843e [time] Fix clang-tidy sign comparison errors (#11080) 2025-10-06 14:34:40 -05:00
Eyal f286bc57f3 [core] Fix timezone offset calculation (#10426) 2025-09-02 16:45:25 +12:00
Adrian Freund b0f8922056 Mark ESPTime comparison operators as const (#9335) 2025-07-05 22:00:39 +00:00
Quentin Raynaud 83e090cc7e [time] fix recalc_timestamp_local (#8239) 2025-03-07 00:34:04 -08:00
Krzysztof Zdulski 30477c764d Fix recalc_timestamp_utc (#7894) 2024-11-29 13:05:00 -08:00
Samuel SiebandSamuel Sieb a70cee1dc1 fix local time timestamp calculation (#7807)
Co-authored-by: Samuel Sieb <samuel@sieb.net>
2024-11-26 13:15:01 +13:00
RFDarter d77ea46157 [datetime] datetime-datetime strptime support value string without seconds (#6867) 2024-06-08 08:29:10 +12:00
Jesse Hills 8ef7b41c91 Add datetime entities (#6513) 2024-04-26 09:19:54 +12:00
Jesse Hills 0148ebcaa6 Replace std::regex with sscanf calls (#6468)
* Replace std::regex with sscanf calls

* Fix CI

* Use regular formatting placeholders

* Fix
2024-04-03 19:41:41 -05:00
Gábor Poczkodi 7cb8f99884 Don't compile strptime unless its required (#6424) 2024-03-26 11:34:47 +13:00
RFDarterandJesse Hills 1e96a19d09 Add datetime date entities (#6191)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
2024-03-11 07:52:22 +13:00
Kevin P. Fleming deb34c9473 time: Make std::string version of strftime() avoid runaway memory allocations (#5348) 2023-09-12 08:02:07 +12:00
Samuel Sieb fc0e1a3cb9 remove unused static declarations (#4993) 2023-06-23 13:03:31 +12:00
Jesse Hills 302dea4169 Move ESPTime into core esphome namespace (#4926)
* Prep-work for datetime entities

* Fix some includes and remove some restrictions on printing time on displays

* format

* format

* More formatting

* Move function contents

* Ignore clang-tidy
2023-06-08 17:24:44 -05:00