1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-31 23:21:54 +00:00

[core] Simplify ESPTime::strftime() and save 20 bytes flash

This commit is contained in:
J. Nick Koston
2025-10-25 11:21:22 -07:00
parent 5861cf37f9
commit 960c80b202

View File

@@ -44,32 +44,14 @@ struct ESPTime {
size_t strftime(char *buffer, size_t buffer_len, const char *format);
/** Convert this ESPTime struct to a string as specified by the format argument.
* @see https://www.gnu.org/software/libc/manual/html_node/Formatting-Calendar-Time.html#index-strftime
* @see https://en.cppreference.com/w/c/chrono/strftime
*
* @warning This method uses dynamically allocated strings which can cause heap fragmentation with some
* microcontrollers.
*
* @warning This method can return "ERROR" when the underlying strftime() call fails, e.g. when the
* format string contains unsupported specifiers or when the format string doesn't produce any
* output.
* @warning This method can return "ERROR" when the underlying strftime() call fails or when the
* output exceeds 128 bytes.
*/
std::string strftime(const std::string &format);
/** Convert this ESPTime struct to a string as specified by the format argument.
* @see https://www.gnu.org/software/libc/manual/html_node/Formatting-Calendar-Time.html#index-strftime
*
* This overload is optimized for string literals and avoids std::string parameter overhead.
*
* @param format The format string (null-terminated C string)
* @param format_len Optional length of the format string. If 0 (default), strlen() will be called.
*
* @warning This method uses dynamically allocated strings which can cause heap fragmentation with some
* microcontrollers.
*
* @warning This method can return "ERROR" when the underlying strftime() call fails, e.g. when the
* format string contains unsupported specifiers or when the format string doesn't produce any
* output.
*/
/// @copydoc strftime(const std::string &format)
std::string strftime(const char *format, size_t format_len = 0);
/// Check if this ESPTime is valid (all fields in range and year is greater than 2018)