Clk_TS_ToDateTime

Convert Clock timestamp to date/time structure.

Files

clk.h/clk.c

Prototype

CPU_BOOLEAN  Clk_TS_ToDateTime (CLK_TS_SEC      ts_sec,
                                CLK_TZ_SEC      tz_sec,
                                CLK_DATE_TIME  *p_date_time);


Arguments

ts_sec

Timestamp to convert (in seconds, UTC+00).

tz_sec

Time zone offset (in seconds, ± from UTC).

p_date_time

Pointer to variable that will receive the date/time structure.

Returned Values

DEF_OK, if date/time structure successfully returned.

DEF_FAIL, otherwise.

Required Configuration

None.

Notes / Warnings

Timestamp (ts_sec) must be set for UTC+00 and should not include the time zone offset (tz_sec) since Clk_TS_ToDateTime() includes the time zone offset in its date/time calculation. Thus the time zone offset should not be applied before or after calling Clk_TS_ToDateTime().

Time zone field of the date/time structure (p_date_time->TZ_sec) is set to the value of the time zone argument (tz_sec).

Example Usage

Listing - Clk_TS_ToDateTime() Example Usage
CLK_TS_SEC     ts_sec;
CLK_TZ_SEC     tz_sec;
CLK_DATE_TIME  date_time;
CPU_BOOLEAN    valid;
 
ts_sec = 1025630;
tz_sec = 0;
valid  = Clk_TS_ToDateTime(ts_sec, tz_sec, &date_time);
if (valid == DEF_OK) {
    printf("Date = %u/%u/%u\n\r", date_time.Yr, date_time.Month, date_time.Day);
    printf("Time = %u:%u:%u\n\r", date_time.Hr, date_time.Min,   date_time.Sec);
} else {
    printf("Clock Get Date/time error\n\r");
}