iPXE
time.h File Reference

Date and time. More...

#include <sys/time.h>
#include <ipxe/time.h>

Go to the source code of this file.

Data Structures

struct  tm
 Broken-down time. More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
static __attribute__ ((always_inline)) time_t time(time_t *t)
 Get current time in seconds since the Epoch.
time_t mktime (struct tm *tm)
 Calculate seconds since the Epoch.

Detailed Description

Date and time.

Definition in file time.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ __attribute__()

__attribute__ ( (always_inline) )
inlinestatic

Get current time in seconds since the Epoch.

Parameters
tTime to fill in, or NULL
Return values
timeCurrent time

Definition at line 43 of file time.h.

43 {
44 time_t now;
45
46 now = ( time_now() + time_offset );
47 if ( t )
48 *t = now;
49 return now;
50}
time_t time_now(void)
Get current time in seconds (ignoring system clock offset).
int64_t time_t
Seconds since the Epoch.
Definition time.h:19
signed long time_offset
Current system clock offset.
Definition time.c:49

References time_now(), and time_offset.

◆ mktime()

time_t mktime ( struct tm * tm)
extern

Calculate seconds since the Epoch.

Parameters
tmBroken-down time
Return values
timeSeconds since the Epoch

Definition at line 119 of file time.c.

119 {
120 int tm_year = tm->tm_year;
121 int tm_mon = tm->tm_mon;
122 int tm_mday = tm->tm_mday;
123 int tm_hour = tm->tm_hour;
124 int tm_min = tm->tm_min;
125 int tm_sec = tm->tm_sec;
126 int tm_yday;
127 int tm_wday;
128 int days_since_epoch;
129 int seconds_since_day;
131
132 /* Normalize month for use as an array index */
133 tm_year += ( tm_mon / 12 );
134 tm_mon = ( tm_mon % 12 );
135 if ( tm_mon < 0 ) {
136 tm_year--;
137 tm_mon += 12;
138 }
139 assert ( tm_mon >= 0 );
140 assert ( tm_mon < 12 );
141
142 /* Calculate day of year */
143 tm_yday = ( ( tm_mday - 1 ) + days_to_month_start[tm_mon] );
144 if ( ( tm_mon >= 2 ) && is_leap_year ( tm_year ) )
145 tm_yday++;
146 tm->tm_yday = tm_yday;
147
148 /* Calculate day of week */
149 tm_wday = day_of_week ( tm_year, tm_mon, tm_mday );
150 tm->tm_wday = tm_wday;
151
152 /* Calculate seconds since the Epoch */
153 days_since_epoch = ( tm_yday + ( 365 * tm_year ) - 25567 +
154 leap_years_to_end ( tm_year - 1 ) );
155 seconds_since_day =
156 ( ( ( ( tm_hour * 60 ) + tm_min ) * 60 ) + tm_sec );
157 seconds = ( ( ( ( time_t ) days_since_epoch ) * ( ( time_t ) 86400 ) )
158 + seconds_since_day );
159
160 DBGC ( &weekdays, "TIME %04d-%02d-%02d %02d:%02d:%02d => %lld (%s, "
161 "day %d)\n", ( tm->tm_year + 1900 ), ( tm->tm_mon + 1 ),
163 weekdays[ tm->tm_wday ], tm->tm_yday );
164
165 return seconds;
166}
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:61
#define DBGC(...)
Definition compiler.h:530
UINT16_t seconds
Elapsed time.
Definition pxe_api.h:24
Broken-down time.
Definition time.h:16
int tm_mon
Month of year [0,11].
Definition time.h:26
int tm_year
Years since 1900.
Definition time.h:28
int tm_hour
Hour [0,23].
Definition time.h:22
int tm_sec
Seconds [0,60].
Definition time.h:18
int tm_yday
Day of year [0,365].
Definition time.h:32
int tm_mday
Day of month [1,31].
Definition time.h:24
int tm_min
Minutes [0,59].
Definition time.h:20
int tm_wday
Day of week [0,6] (Sunday=0).
Definition time.h:30
static const uint16_t days_to_month_start[]
Days from start of year until start of months (in non-leap years).
Definition time.c:110
static int day_of_week(int tm_year, int tm_mon, int tm_mday)
Calculate day of week.
Definition time.c:98
static int leap_years_to_end(int tm_year)
Calculate number of leap years since 1900.
Definition time.c:81
static int is_leap_year(int tm_year)
Determine whether or not year is a leap year.
Definition time.c:62
static const char * weekdays[]
Days of week (for debugging).
Definition time.c:52

References assert, day_of_week(), days_to_month_start, DBGC, is_leap_year(), leap_years_to_end(), seconds, tm::tm_hour, tm::tm_mday, tm::tm_min, tm::tm_mon, tm::tm_sec, tm::tm_wday, tm::tm_yday, tm::tm_year, and weekdays.

Referenced by asn1_generalized_time(), efi_get_time(), and rtc_read_time().