Clk_DateTimeToTS

Convert date/time structure to Clock timestamp.

Files

clk.h/clk.c

Prototype

CPU_BOOLEAN  Clk_DateTimeToTS (CLK_TS_SEC     *p_ts_sec,
                               CLK_DATE_TIME  *p_date_time);


Arguments

p_ts_sec

Pointer to variable that will receive the Clock timestamp:

In seconds UTC+00, if no errors;
CLK_TS_SEC_NONE, otherwise.

p_date_time

Pointer to variable that contains date/time structure to convert.

Returned Values

DEF_OK, if timestamp successfully returned.

DEF_FAIL, otherwise.

Required Configuration

None.

Notes / Warnings

Date/time structure (p_date_time) must be representable in Clock timestamp. Thus date to convert must be greater than or equal to CLK_EPOCH_YR_START and less than CLK_EPOCH_YR_END. Date/time should be set to local time with correct time zone offset (p_date_time->TZ_sec). Clk_DateTimeToTS() removes the time zone offset from the date/time to calculate and return a Clock timestamp at UTC+00.

Example Usage

Listing - Clk_DateTimeToTS() Example Usage
CLK_TS_SEC     ts_sec;
CLK_DATE_TIME  date_time;
CPU_BOOLEAN    valid;
 
date_time.Yr      =   2010;     /* 2010/09/18  11:11:11 UTC-05:00  */
date_time.Month   =      9;
date_time.Day     =     18;
date_time.Hr      =     11;
date_time.Min     =     11;
date_time.Sec     =     11;
date_time.DayOfWk =      2;
date_time.DayOfYr =    291;
date_time.TZ_sec  = -18000;
 
valid = Clk_DateTimeToTS(&ts_sec, &date_time);
if (valid == DEF_OK) {
    printf("Clock timestamp = %u", ts_sec);
} else {
    printf("Clock Date/time to timestamp error\n\r");
}