yumapro  24.10-1
YumaPro SDK
Loading...
Searching...
No Matches
Timestamp Utilities

Timestamp and time format conversion functions. More...

Collaboration diagram for Timestamp Utilities:

Macros

#define TSTAMP_MIN_HEXSIZE   17
 minimum buffer size for hex format
 
#define TSTAMP_MIN_SIZE   29
 normal minimum buffer size for a tstamp buffer More...
 
#define TSTAMP_DATE_SIZE   12
 minimum buffer size for just a date string This value MUST be the minimum size buffer used for the tstamp_datetime and tstamp_local_datetime functions
 
#define TSTAMP_SQL_SIZE   20
 minimum buffer size for SQL date format string
 
#define TSTAMP_HTML_SIZE   50
 minimum buffer size for HTML format string
 

Functions

void tstamp_datetime (xmlChar *buff)
 Set the current date and time in an XML dateTime string format. More...
 
void tstamp_highres_datetime (xmlChar *buff)
 Set the current date and time in an XML dateTime string format using highres format. More...
 
void tstamp_local_datetime (xmlChar *buff)
 Set the current date and time in an XML dateTime string format. More...
 
void tstamp_local_highres_datetime (xmlChar *buff)
 Set the current date and time in an XML dateTime string format using highres format. More...
 
void tstamp_date (xmlChar *buff)
 Set the current date in an XML dateTime string format. More...
 
void tstamp_datetime_sql (xmlChar *buff)
 Set the current date and time in an XML dateTime string format. More...
 
xmlChar * tstamp_convert_to_utctime (const xmlChar *timestr, boolean *isNegative, status_t *res)
 Check if the specified string is a valid dateTime or date-and-time string is valid and if so, convert it to UTC time. More...
 
void tstamp_datetime_dirname (xmlChar *buff)
 Set the current date and time in an XML dateTime string format. More...
 
void tstamp_time2datetime (time_t *timerec, xmlChar *buff)
 Convert the specified time_t to a YANG data-and-time format. More...
 
void tstamp_local_time2datetime (time_t *timerec, xmlChar *buff)
 Convert the specified time_t to a local time YANG date-and-time format. More...
 
status_t tstamp_time2htmltime (time_t *timerec, xmlChar *buff, size_t buffsize)
 Convert the specified time_t to a HTML timestamp string. More...
 
status_t tstamp_htmltime2time (const xmlChar *timestr, time_t *timerec)
 Convert the specified HTML timestamp string to time_t format. More...
 
int32 tstamp_difftime (time_t *time1, time_t *time2)
 Compare 2 time_t structs. More...
 
void tstamp_now (time_t *tim)
 Set the time_t to the current time. More...
 
long int tstamp_diff (struct timeval *start_time, struct timeval *end_time, long int *usec)
 Get the elapsed time between two timeval structs. More...
 
void tstamp_time2hex (time_t *tim, xmlChar *buf)
 Convert the time_t to a string of hex digits. More...
 
status_t tstamp_convert_to_time (const xmlChar *timestr, time_t *rtime)
 Check if the specified string is a valid dateTime or date-and-time string is valid and if so, convert it to time_t. More...
 
time_t tstamp_cvt_TIME (char const *time_str)
 Convert the DATE string to a time_t. More...
 
void tstamp_highres_timenow (struct timespec *ts)
 Get the current time using a high res timestamp. More...
 
void tstamp_set_datetime (xmlChar *buff, bool use_local)
 Set the current date and time in the buffer. More...
 

Detailed Description

Timestamp and time format conversion functions.

NETCONF, YANG, and RESTCONF all use different date and time formats requiring conversions between them. Includes high resolution timers and monotonic clock support.

Macro Definition Documentation

◆ TSTAMP_MIN_SIZE

#define TSTAMP_MIN_SIZE   29

normal minimum buffer size for a tstamp buffer

NOTE: THIS VALUE HAS BEEN INCREASED TO HANDLE MICROSECONDS THE OLD VALUE OF 22 IS TOO SMALL FOR A HIGHRES TIMESTAMP

Function Documentation

◆ tstamp_convert_to_time()

status_t tstamp_convert_to_time ( const xmlChar *  timestr,
time_t *  rtime 
)

Check if the specified string is a valid dateTime or date-and-time string is valid and if so, convert it to time_t.

Parameters
timestrpointer to buffer to check
[out]rtimepointer to return time
Returns
status
Here is the call graph for this function:

◆ tstamp_convert_to_utctime()

xmlChar * tstamp_convert_to_utctime ( const xmlChar *  timestr,
boolean *  isNegative,
status_t res 
)

Check if the specified string is a valid dateTime or date-and-time string is valid and if so, convert it to UTC time.

Parameters
timestrpointer to buffer to check
[out]isNegativeaddress of return negative date flag
  • *isNegative TRUE if a negative dateTime string is given
  • FALSE if no starting '-' sign found
[out]resaddress of return status
  • *res return status
Returns
malloced pointer to converted date time string or NULL if some error
Here is the call graph for this function:

◆ tstamp_cvt_TIME()

time_t tstamp_cvt_TIME ( char const *  time_str)

Convert the DATE string to a time_t.

From StackOverflow https://stackoverflow.com/questions/1765014/convert-string-from-date-into-a-time-t

Parameters
time_strDATE string
Returns
time_t format

◆ tstamp_date()

void tstamp_date ( xmlChar *  buff)

Set the current date in an XML dateTime string format.

Parameters
[in,out]buffpointer to buffer to hold output
  • MUST BE AT LEAST 11 CHARS
  • buff is filled in
Here is the caller graph for this function:

◆ tstamp_datetime()

void tstamp_datetime ( xmlChar *  buff)

Set the current date and time in an XML dateTime string format.

Parameters
[out]buffpointer to buffer to hold output
  • MUST BE AT LEAST 21 CHARS
  • buff is filled in
Here is the caller graph for this function:

◆ tstamp_datetime_dirname()

void tstamp_datetime_dirname ( xmlChar *  buff)

Set the current date and time in an XML dateTime string format.

Parameters
[in,out]buffpointer to buffer to hold output
  • MUST BE AT LEAST 21 CHARS
  • buff is filled in
Here is the caller graph for this function:

◆ tstamp_datetime_sql()

void tstamp_datetime_sql ( xmlChar *  buff)

Set the current date and time in an XML dateTime string format.

Parameters
[in,out]buffpointer to buffer to hold output
  • MUST BE AT LEAST 20 CHARS
  • buff is filled in

◆ tstamp_diff()

long int tstamp_diff ( struct timeval *  start_time,
struct timeval *  end_time,
long int *  usec 
)

Get the elapsed time between two timeval structs.

Parameters
start_timestart timestamp
end_timefinish timestamp
[out]usecaddress of return micro seconds
  • *usec number of micro-seconds of elapsed time
Returns
number of seconds of elapsed time

◆ tstamp_difftime()

int32 tstamp_difftime ( time_t *  time1,
time_t *  time2 
)

Compare 2 time_t structs.

Parameters
time1time struct 1
time2time struct 2
Returns
compare value
    -1 if time1 < time2
     0 if time1 == time2
     1 if time1 > time2
Here is the caller graph for this function:

◆ tstamp_highres_datetime()

void tstamp_highres_datetime ( xmlChar *  buff)

Set the current date and time in an XML dateTime string format using highres format.

Parameters
[in,out]buffpointer to buffer to hold output
  • MUST BE AT LEAST 29 CHARS (TSTAMP_MIN_SIZE)
  • buff is filled in
Here is the call graph for this function:

◆ tstamp_highres_timenow()

void tstamp_highres_timenow ( struct timespec *  ts)

Get the current time using a high res timestamp.

If the make flags and system support it then the CLOCK_MONOTONIC highres clock will be used. If not then the CLOCK_REALTIME clock will be used

Parameters
[out]tstimeres struct to fill in
  • *ts is filled in
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tstamp_htmltime2time()

status_t tstamp_htmltime2time ( const xmlChar *  timestr,
time_t *  timerec 
)

Convert the specified HTML timestamp string to time_t format.

Parameters
timestrtimestamp string to convert
[out]timerecaddress of return time_t struct
  • *timerec struct is filled in if NO_ERR
Returns
status

◆ tstamp_local_datetime()

void tstamp_local_datetime ( xmlChar *  buff)

Set the current date and time in an XML dateTime string format.

Parameters
[in,out]buffpointer to buffer to hold output
  • MUST BE AT LEAST 21 CHARS
  • buff is filled in
Here is the caller graph for this function:

◆ tstamp_local_highres_datetime()

void tstamp_local_highres_datetime ( xmlChar *  buff)

Set the current date and time in an XML dateTime string format using highres format.

Parameters
[in,out]buffpointer to buffer to hold output
  • MUST BE AT LEAST 29 CHARS (TSTAMP_MIN_SIZE)
  • buff is filled in
Here is the call graph for this function:

◆ tstamp_local_time2datetime()

void tstamp_local_time2datetime ( time_t *  timerec,
xmlChar *  buff 
)

Convert the specified time_t to a local time YANG date-and-time format.

Parameters
[in]timerecPointer to time_t to convert.
[in,out]buffPointer to buffer to hold output.
  • MUST BE AT LEAST 21 CHARS
  • buff is filled in
Here is the caller graph for this function:

◆ tstamp_now()

void tstamp_now ( time_t *  tim)

Set the time_t to the current time.

Parameters
[out]timaddress of time_t to set
  • *tim is set
Here is the caller graph for this function:

◆ tstamp_set_datetime()

void tstamp_set_datetime ( xmlChar *  buff,
bool  use_local 
)

Set the current date and time in the buffer.

This function allows choosing between UTC and local time based on the use_local flag.

Parameters
[in,out]buffPointer to the buffer for the date and time string.
  • MUST BE AT LEAST 21 CHARS.
  • buff is filled in
[in]use_localBoolean flag to determine if local time or UTC should be used.
  • TRUE: local time
  • FALSE: UTC time

◆ tstamp_time2datetime()

void tstamp_time2datetime ( time_t *  timerec,
xmlChar *  buff 
)

Convert the specified time_t to a YANG data-and-time format.

Parameters
timerecpointer to time_t to convert
[in,out]buffpointer to buffer to hold output
  • MUST BE AT LEAST 21 CHARS
  • buff is filled in
Here is the caller graph for this function:

◆ tstamp_time2hex()

void tstamp_time2hex ( time_t *  tim,
xmlChar *  buf 
)

Convert the time_t to a string of hex digits.

Parameters
timaddress of time_t to use
[in,out]bufbuffer to fill in
  • (MUST be at least 17 chars long)
  • TSTAMP_MIN_HEXSIZE
  • buf is set to time_t converted to hex string

◆ tstamp_time2htmltime()

status_t tstamp_time2htmltime ( time_t *  timerec,
xmlChar *  buff,
size_t  buffsize 
)

Convert the specified time_t to a HTML timestamp string.

Parameters
timerecpointer to time_t to convert
[in,out]buffpointer to buffer to hold output
  • MUST BE AT LEAST 40 CHARS
  • buff is filled in
buffsizesize of buff
Returns
status