Clk_DateTimeToStr

Converts a date/time structure to an ASCII string.

Files

clk.h/clk.c

Prototype

CPU_BOOLEAN  Clk_DateTimeToStr (CLK_DATE_TIME  *p_date_time,
                                CLK_STR_FMT     fmt,
                                CPU_CHAR       *p_str,
                                CPU_INT32U      str_len);


Arguments

p_date_time

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

fmt

Desired string format:

CLK_STR_FMT_YYYY_MM_DD_HH_MM_SS_UTC
CLK_STR_FMT_YYYY_MM_DD_HH_MM_SS
CLK_STR_FMT_MM_DD_YY_HH_MM_SS
CLK_STR_FMT_YYYY_MM_DD
CLK_STR_FMT_MM_DD_YY
CLK_STR_FMT_DAY_MONTH_DD_YYYY
CLK_STR_FMT_DAY_MONTH_DD_HH_MM_SS_YYYY
CLK_STR_FMT_HH_MM_SS
CLK_STR_FMT_HH_MM_SS_AM_PM

p_str

Pointer to variable that will receive the formated string.

str_len

Maximum number of characters the string can contains.

Returned Values

DEF_OK, if string successfully returned.

DEF_FAIL, otherwise.

Required Configuration

Available only if CLK_CFG_STR_CONV_EN is DEF_ENABLED in clk_cfg.h (see section 3-1-1).

Notes / Warnings

It’s only possible to convert date supported by Clock:

  • Earliest year is the NTP epoch start year, thus Year (yr) must be greater than or equal to CLK_NTP_EPOCH_YR_START.
  • Latest year is the Clock epoch last year, thus Year (yr) must be less than CLK_EPOCH_YR_END.

The size of the string buffer that will receive the returned string address must be greater than or equal to CLK_STR_FMT_MAX_LEN.

Example Usage

Listing - Clk_DateTimeToStr() Example Usage
CLK_DATE_TIME  date_time;
CPU_BOOLEAN    valid;
CPU_CHAR       str[CLK_STR_FMT_YYYY_MM_DD_HH_MM_SS_UTC_LEN];
 
                                  /* 2010/09/18   11:11:11 UTC-05:00  */
valid = Clk_DateTimeMake(&date_time, 2010, 9, 18, 11, 11, 11, -18000);
if (valid == DEF_OK) {
    printf("Date/time successfully created");
} else {
    printf("Clock Date/time error\n\r");
}
 
valid = Clk_DateTimeToStr(&date_time,
                           CLK_STR_FMT_YYYY_MM_DD_HH_MM_SS_UTC,
                           str,
                           CLK_STR_FMT_YYYY_MM_DD_HH_MM_SS_UTC_LEN);
if (valid == DEF_OK) {
    printf("Date/time = %s", str);
} else {
    printf("Clock Date/time to String error\n\r");
}