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.
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 ( GPL2_OR_LATER_OR_UBDL  )
static __attribute__ ( (always_inline)  ) [inline, static]

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.

References time_now(), and time_offset.

                                                                          {
        time_t now;

        now = ( time_now() + time_offset );
        if ( t )
                *t = now;
        return now;
}
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.

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

                                {
        int days_since_epoch;
        int seconds_since_day;
        time_t seconds;

        /* Calculate day of year */
        tm->tm_yday = ( ( tm->tm_mday - 1 ) +
                        days_to_month_start[ tm->tm_mon ] );
        if ( ( tm->tm_mon >= 2 ) && is_leap_year ( tm->tm_year ) )
                tm->tm_yday++;

        /* Calculate day of week */
        tm->tm_wday = day_of_week ( tm->tm_year, tm->tm_mon, tm->tm_mday );

        /* Calculate seconds since the Epoch */
        days_since_epoch = ( tm->tm_yday + ( 365 * tm->tm_year ) - 25567 +
                             leap_years_to_end ( tm->tm_year - 1 ) );
        seconds_since_day =
                ( ( ( ( tm->tm_hour * 60 ) + tm->tm_min ) * 60 ) + tm->tm_sec );
        seconds = ( ( ( ( time_t ) days_since_epoch ) * ( ( time_t ) 86400 ) ) +
                    seconds_since_day );

        DBGC ( &weekdays, "TIME %04d-%02d-%02d %02d:%02d:%02d => %lld (%s, "
               "day %d)\n", ( tm->tm_year + 1900 ), ( tm->tm_mon + 1 ),
               tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, seconds,
               weekdays[ tm->tm_wday ], tm->tm_yday );

        return seconds;
}