iPXE
Data Structures | Functions
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)
 
static __attribute__ ((always_inline)) time_t time(time_t *t)
 Get current time in seconds since the Epoch. More...
 
time_t mktime (struct tm *tm)
 Calculate seconds since the Epoch. More...
 

Detailed Description

Date and time.

Definition in file time.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ __attribute__()

static __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 42 of file time.h.

42  {
43  time_t now;
44 
45  now = ( time_now() + time_offset );
46  if ( t )
47  *t = now;
48  return now;
49 }
signed long time_offset
Current system clock offset.
Definition: time.c:47
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:18

References time_now(), and time_offset.

◆ mktime()

time_t mktime ( struct tm tm)

Calculate seconds since the Epoch.

Parameters
tmBroken-down time
Return values
timeSeconds since the Epoch

Definition at line 117 of file time.c.

117  {
118  int days_since_epoch;
119  int seconds_since_day;
120  time_t seconds;
121 
122  /* Calculate day of year */
123  tm->tm_yday = ( ( tm->tm_mday - 1 ) +
125  if ( ( tm->tm_mon >= 2 ) && is_leap_year ( tm->tm_year ) )
126  tm->tm_yday++;
127 
128  /* Calculate day of week */
130 
131  /* Calculate seconds since the Epoch */
132  days_since_epoch = ( tm->tm_yday + ( 365 * tm->tm_year ) - 25567 +
133  leap_years_to_end ( tm->tm_year - 1 ) );
134  seconds_since_day =
135  ( ( ( ( tm->tm_hour * 60 ) + tm->tm_min ) * 60 ) + tm->tm_sec );
136  seconds = ( ( ( ( time_t ) days_since_epoch ) * ( ( time_t ) 86400 ) ) +
137  seconds_since_day );
138 
139  DBGC ( &weekdays, "TIME %04d-%02d-%02d %02d:%02d:%02d => %lld (%s, "
140  "day %d)\n", ( tm->tm_year + 1900 ), ( tm->tm_mon + 1 ),
142  weekdays[ tm->tm_wday ], tm->tm_yday );
143 
144  return seconds;
145 }
static int day_of_week(int tm_year, int tm_mon, int tm_mday)
Calculate day of week.
Definition: time.c:96
int tm_min
Minutes [0,59].
Definition: time.h:19
int tm_mday
Day of month [1,31].
Definition: time.h:23
#define DBGC(...)
Definition: compiler.h:505
int tm_year
Years since 1900.
Definition: time.h:27
static int is_leap_year(int tm_year)
Determine whether or not year is a leap year.
Definition: time.c:60
int tm_mon
Month of year [0,11].
Definition: time.h:25
Broken-down time.
Definition: time.h:15
int tm_wday
Day of week [0,6] (Sunday=0)
Definition: time.h:29
int tm_yday
Day of year [0,365].
Definition: time.h:31
static const char * weekdays[]
Days of week (for debugging)
Definition: time.c:50
static int leap_years_to_end(int tm_year)
Calculate number of leap years since 1900.
Definition: time.c:79
UINT16_t seconds
Elapsed time.
Definition: pxe_api.h:81
int tm_sec
Seconds [0,60].
Definition: time.h:17
int tm_hour
Hour [0,23].
Definition: time.h:21
static const uint16_t days_to_month_start[]
Days from start of year until start of months (in non-leap years)
Definition: time.c:108
int64_t time_t
Seconds since the Epoch.
Definition: time.h:18

References 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().