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

Functions

bool is_leap_year (int year)
 Check if a year is a leap year.
 
int days_in_month (int year, int month)
 Get the number of days in a month.
 
int __attribute__ ((noinline)) day_of_week(int year
 
 return ((h+6) % 7)
 
 if (remaining_secs< 0)
 
 while (days >=(dim=days_in_month(year, month)))
 
bool skip_tz_name (const char *&p)
 Skip a timezone name (letters or <...> quoted format)
 
 while (out_month<=12)
 
bool parse_dst_rule (const char *&p, DSTRule &rule)
 Parse a DST rule in format Mm.w.d[/time], Jn[/time], or n[/time].
 
 for (int m=1;m< month;m++)
 
 switch (rule.type)
 
int32_t parse_offset (const char *&p)
 Parse an offset in format [-]hh[:mm[:ss]].
 
void julian_to_month_day (int julian_day, int &month, int &day)
 Convert Julian day (J format, 1-365 not counting Feb 29) to month/day.
 
void day_of_year_to_month_day (int day_of_year, int year, int &month, int &day)
 Convert day of year (plain format, 0-365 counting Feb 29) to month/day.
 
int day_of_week (int year, int month, int day)
 Calculate day of week for any date (0 = Sunday) Uses a simplified algorithm that works for years 1970-2099.
 
void epoch_to_tm_utc (time_t epoch, struct tm *out_tm)
 Convert epoch to year/month/day/hour/min/sec (UTC)
 
time_t calculate_dst_transition (int year, const DSTRule &rule, int32_t base_offset_seconds)
 Calculate the epoch timestamp for a DST transition in a given year.
 

Variables

int int month = 1
 
int int int day
 
int j = year / 100
 
int h = (day + (13 * (month + 1)) / 5 + k + k / 4 + j / 4 - 2 * j) % 7
 
void struct tm * out_tm
 
int32_t remaining_secs = epoch % 86400
 
out_tm tm_sec = remaining_secs % 60
 
out_tm tm_min = remaining_secs % 60
 
out_tm tm_hour = remaining_secs / 60
 
out_tm tm_wday = static_cast<int>((days + 4) % 7)
 
int year = days_to_year(days)
 
out_tm tm_year = year - 1900
 
out_tm tm_yday = static_cast<int>(days)
 
int dim
 
out_tm tm_mon = month - 1
 
out_tm tm_mday = static_cast<int>(days) + 1
 
out_tm tm_isdst = 0
 
void int & out_month = 1
 
void int int & out_day
 
return days = days_to_year_start(year) + days_from_year_start(year, month, day)
 
time_t const DSTRulerule
 
time_t const DSTRule int32_t base_offset_seconds
 

Function Documentation

◆ __attribute__()

time_t esphome::time::internal::__attribute__ ( (noinline) )

Definition at line 285 of file posix_tz.cpp.

◆ calculate_dst_transition()

time_t esphome::time::internal::calculate_dst_transition ( int year,
const DSTRule & rule,
int32_t base_offset_seconds )

Calculate the epoch timestamp for a DST transition in a given year.

Parameters
yearThe year (e.g., 2026)
ruleThe DST rule (month, week, day_of_week, time)
base_offset_secondsThe timezone offset to apply (std or dst depending on context)
Returns
Unix epoch timestamp of the transition

◆ day_of_week()

int esphome::time::internal::day_of_week ( int year,
int month,
int day )

Calculate day of week for any date (0 = Sunday) Uses a simplified algorithm that works for years 1970-2099.

◆ day_of_year_to_month_day()

void esphome::time::internal::day_of_year_to_month_day ( int day_of_year,
int year,
int & month,
int & day )

Convert day of year (plain format, 0-365 counting Feb 29) to month/day.

Parameters
day_of_yearDay number 0-365
yearThe year (for leap year calculation)
[out]monthOutput: month 1-12
[out]dayOutput: day of month

◆ days_in_month()

int esphome::time::internal::days_in_month ( int year,
int month )

Get the number of days in a month.

Definition at line 59 of file posix_tz.cpp.

◆ epoch_to_tm_utc()

void esphome::time::internal::epoch_to_tm_utc ( time_t epoch,
struct tm * out_tm )

Convert epoch to year/month/day/hour/min/sec (UTC)

◆ for()

esphome::time::internal::for ( )

Definition at line 276 of file posix_tz.cpp.

◆ if()

esphome::time::internal::if ( )

Definition at line 91 of file posix_tz.cpp.

◆ is_leap_year()

bool esphome::time::internal::is_leap_year ( int year)

Check if a year is a leap year.

Definition at line 31 of file posix_tz.cpp.

◆ julian_to_month_day()

void esphome::time::internal::julian_to_month_day ( int julian_day,
int & month,
int & day )

Convert Julian day (J format, 1-365 not counting Feb 29) to month/day.

Parameters
julian_dayDay number 1-365
[out]monthOutput: month 1-12
[out]dayOutput: day of month

◆ parse_dst_rule()

bool esphome::time::internal::parse_dst_rule ( const char *& p,
DSTRule & rule )

Parse a DST rule in format Mm.w.d[/time], Jn[/time], or n[/time].

Parameters
pPointer to current position, updated on return
ruleOutput: the parsed rule
Returns
true if parsing succeeded

Definition at line 220 of file posix_tz.cpp.

◆ parse_offset()

int32_t esphome::time::internal::parse_offset ( const char *& p)

Parse an offset in format [-]hh[:mm[:ss]].

Parameters
pPointer to current position, updated on return
Returns
Offset in seconds

◆ return()

esphome::time::internal::return ( (h+6) % 7)

◆ skip_tz_name()

bool esphome::time::internal::skip_tz_name ( const char *& p)

Skip a timezone name (letters or <...> quoted format)

Parameters
pPointer to current position, updated on return
Returns
true if a valid name was found

Definition at line 124 of file posix_tz.cpp.

◆ switch()

esphome::time::internal::switch ( rule. type)

Definition at line 296 of file posix_tz.cpp.

◆ while() [1/2]

esphome::time::internal::while ( days >= dim=days_in_month(year, month))

Definition at line 114 of file posix_tz.cpp.

◆ while() [2/2]

esphome::time::internal::while ( out_month<= 12)

Definition at line 186 of file posix_tz.cpp.

Variable Documentation

◆ base_offset_seconds

return days *rule time_seconds esphome::time::internal::base_offset_seconds
Initial value:
{
int month, day
uint8_t month
Definition date_entity.h:1
uint8_t day
Definition date_entity.h:2

Definition at line 293 of file posix_tz.cpp.

◆ day

static int int int esphome::time::internal::day
Initial value:
{
if (month < 3) {
month += 12;
year--;
}
int k = year % 100
uint16_t year
Definition date_entity.h:0

Definition at line 74 of file posix_tz.cpp.

◆ days

int64_t esphome::time::internal::days = days_to_year_start(year) + days_from_year_start(year, month, day)

Definition at line 279 of file posix_tz.cpp.

◆ dim

int esphome::time::internal::dim

Definition at line 113 of file posix_tz.cpp.

◆ h

int esphome::time::internal::h = (day + (13 * (month + 1)) / 5 + k + k / 4 + j / 4 - 2 * j) % 7

Definition at line 82 of file posix_tz.cpp.

◆ j

int esphome::time::internal::j = year / 100

Definition at line 81 of file posix_tz.cpp.

◆ month

static int int esphome::time::internal::month = 1

Definition at line 74 of file posix_tz.cpp.

◆ out_day

void int int int & esphome::time::internal::out_day
Initial value:
{
int remaining = julian_day

Definition at line 180 of file posix_tz.cpp.

◆ out_month

void int int & esphome::time::internal::out_month = 1

Definition at line 180 of file posix_tz.cpp.

◆ out_tm

void struct tm* esphome::time::internal::out_tm
Initial value:
{
int64_t days = epoch / 86400

Definition at line 87 of file posix_tz.cpp.

◆ remaining_secs

esphome::time::internal::remaining_secs = epoch % 86400

Definition at line 90 of file posix_tz.cpp.

◆ rule

time_t const DSTRule& esphome::time::internal::rule

Definition at line 293 of file posix_tz.cpp.

◆ tm_hour

out_tm esphome::time::internal::tm_hour = remaining_secs / 60

Definition at line 99 of file posix_tz.cpp.

◆ tm_isdst

out_tm esphome::time::internal::tm_isdst = 0

Definition at line 121 of file posix_tz.cpp.

◆ tm_mday

out_tm esphome::time::internal::tm_mday = static_cast<int>(days) + 1

Definition at line 120 of file posix_tz.cpp.

◆ tm_min

out_tm esphome::time::internal::tm_min = remaining_secs % 60

Definition at line 98 of file posix_tz.cpp.

◆ tm_mon

out_tm esphome::time::internal::tm_mon = month - 1

Definition at line 119 of file posix_tz.cpp.

◆ tm_sec

out_tm esphome::time::internal::tm_sec = remaining_secs % 60

Definition at line 96 of file posix_tz.cpp.

◆ tm_wday

out_tm esphome::time::internal::tm_wday = static_cast<int>((days + 4) % 7)

Definition at line 102 of file posix_tz.cpp.

◆ tm_yday

out_tm esphome::time::internal::tm_yday = static_cast<int>(days)

Definition at line 109 of file posix_tz.cpp.

◆ tm_year

out_tm esphome::time::internal::tm_year = year - 1900

Definition at line 108 of file posix_tz.cpp.

◆ year

void int esphome::time::internal::year = days_to_year(days)

Definition at line 107 of file posix_tz.cpp.