ESPHome 2026.3.0-dev
Loading...
Searching...
No Matches
esphome::time Namespace Reference

Namespaces

namespace  internal
 

Data Structures

class  CronTrigger
 
struct  DSTRule
 Rule for DST transition (packed for 32-bit: 12 bytes) More...
 
struct  ParsedTimezone
 Parsed POSIX timezone information (packed for 32-bit: 32 bytes) More...
 
class  RealTimeClock
 The RealTimeClock class exposes common timekeeping functions via the device's local real-time clock. More...
 
class  SyncTrigger
 
class  TimeHasTimeCondition
 

Enumerations

enum class  DSTRuleType : uint8_t { NONE = 0 , MONTH_WEEK_DAY , JULIAN_NO_LEAP , DAY_OF_YEAR }
 Type of DST transition rule. More...
 

Functions

void set_global_tz (const ParsedTimezone &tz)
 Set the global timezone used by epoch_to_local_tm() when called without a timezone.
 
const ParsedTimezoneget_global_tz ()
 Get the global timezone.
 
 if (dst_start< dst_end)
 
bool parse_posix_tz (const char *tz_string, ParsedTimezone &result)
 Parse a POSIX TZ string into a ParsedTimezone struct.
 
bool epoch_to_local_tm (time_t utc_epoch, const ParsedTimezone &tz, struct tm *out_tm)
 Convert a UTC epoch to local time using the parsed timezone.
 
bool is_in_dst (time_t utc_epoch, const ParsedTimezone &tz)
 Check if a given UTC epoch falls within DST for the parsed timezone.
 

Variables

bool const ParsedTimezonetz
 
time_t dst_start = internal::calculate_dst_transition(year, tz.dst_start, tz.std_offset_seconds)
 
time_t dst_end = internal::calculate_dst_transition(year, tz.dst_end, tz.dst_offset_seconds)
 
 else
 
ESPTime __attribute__ ((noinline)) RealTimeClock
 

Enumeration Type Documentation

◆ DSTRuleType

enum class esphome::time::DSTRuleType : uint8_t
strong

Type of DST transition rule.

Enumerator
NONE 

No DST rule (used to indicate no DST)

MONTH_WEEK_DAY 

M format: Mm.w.d (e.g., M3.2.0 = 2nd Sunday of March)

JULIAN_NO_LEAP 

J format: Jn (day 1-365, Feb 29 not counted)

DAY_OF_YEAR 

Plain number: n (day 0-365, Feb 29 counted in leap years)

Definition at line 11 of file posix_tz.h.

Function Documentation

◆ epoch_to_local_tm()

bool esphome::time::epoch_to_local_tm ( time_t utc_epoch,
const ParsedTimezone & tz,
struct tm * out_tm )

Convert a UTC epoch to local time using the parsed timezone.

This replaces libc's localtime() to avoid scanf dependency.

Parameters
utc_epochUnix timestamp in UTC
tzThe parsed timezone
[out]out_tmOutput tm struct with local time
Returns
true on success

Definition at line 445 of file posix_tz.cpp.

◆ get_global_tz()

const ParsedTimezone & esphome::time::get_global_tz ( )

Get the global timezone.

Definition at line 16 of file posix_tz.cpp.

◆ if()

esphome::time::if ( )

Definition at line 359 of file posix_tz.cpp.

◆ is_in_dst()

bool esphome::time::is_in_dst ( time_t utc_epoch,
const ParsedTimezone & tz )

Check if a given UTC epoch falls within DST for the parsed timezone.

Parameters
utc_epochUnix timestamp in UTC
tzThe parsed timezone
Returns
true if DST is in effect at the given time

◆ parse_posix_tz()

bool esphome::time::parse_posix_tz ( const char * tz_string,
ParsedTimezone & result )

Parse a POSIX TZ string into a ParsedTimezone struct.

Supports formats like:

  • "EST5" (simple offset, no DST)
  • "EST5EDT,M3.2.0,M11.1.0" (with DST, M-format rules)
  • "CST6CDT,M3.2.0/2,M11.1.0/2" (with transition times)
  • "<+07>-7" (angle-bracket notation for special names)
  • "IST-5:30" (half-hour offsets)
  • "EST5EDT,J60,J300" (J-format: Julian day without leap day)
  • "EST5EDT,60,300" (plain day number: day of year with leap day)
    Parameters
    tz_stringThe POSIX TZ string to parse
    resultOutput: the parsed timezone data
    Returns
    true if parsing succeeded, false on error

Definition at line 374 of file posix_tz.cpp.

◆ set_global_tz()

void esphome::time::set_global_tz ( const ParsedTimezone & tz)

Set the global timezone used by epoch_to_local_tm() when called without a timezone.

This is called by RealTimeClock::apply_timezone_() to enable ESPTime::from_epoch_local() to work without libc's localtime().

Definition at line 14 of file posix_tz.cpp.

Variable Documentation

◆ __attribute__

bool esphome::time::__attribute__ ( (noinline) )

Definition at line 26 of file real_time_clock.cpp.

◆ dst_end

time_t esphome::time::dst_end = internal::calculate_dst_transition(year, tz.dst_end, tz.dst_offset_seconds)

Definition at line 357 of file posix_tz.cpp.

◆ dst_start

time_t esphome::time::dst_start = internal::calculate_dst_transition(year, tz.dst_start, tz.std_offset_seconds)

Definition at line 355 of file posix_tz.cpp.

◆ else

esphome::time::else
Initial value:
{
return (utc_epoch >= dst_start || utc_epoch < dst_end)

Definition at line 362 of file posix_tz.cpp.

◆ tz

bool const ParsedTimezone& esphome::time::tz
Initial value:
{
if (!tz.has_dst()) {
return false;
}
int year = internal::epoch_to_year(utc_epoch)
uint16_t year
Definition date_entity.h:0
bool const ParsedTimezone & tz
Definition posix_tz.cpp:346
bool has_dst() const
Check if this timezone has DST rules.
Definition posix_tz.h:36

Definition at line 346 of file posix_tz.cpp.