DDraceNetwork Documentation
Loading...
Searching...
No Matches
Timestamps

Functions

int64_t time_timestamp ()
void str_timestamp (char *buffer, int buffer_size)
void str_timestamp_format (char *buffer, int buffer_size, const char *format)
void str_timestamp_ex (time_t time, char *buffer, int buffer_size, const char *format)
bool timestamp_from_str (const char *string, const char *format, time_t *timestamp)
int str_time (int64_t centisecs, int format, char *buffer, int buffer_size)
int str_time_float (float secs, int format, char *buffer, int buffer_size)

Detailed Description

Timestamp related functions.

Time

Function Documentation

◆ str_time()

int str_time ( int64_t centisecs,
int format,
char * buffer,
int buffer_size )

Formats a time string.

Parameters
centisecsTime in centiseconds.
formatFormat of the time string, see enum above, for example TIME_DAYS.
bufferPointer to a buffer that shall receive the timestamp string.
buffer_sizeSize of the buffer.
Returns
Number of bytes written, -1 on invalid format or buffer_size <= 0.

◆ str_time_float()

int str_time_float ( float secs,
int format,
char * buffer,
int buffer_size )

Formats a time string.

Parameters
secsTime in seconds.
formatFormat of the time string, see enum above, for example TIME_DAYS.
bufferPointer to a buffer that shall receive the timestamp string.
buffer_sizeSize of the buffer.
Remarks
The time is rounded to the nearest centisecond.
Returns
Number of bytes written, -1 on invalid format or buffer_size <= 0.

◆ str_timestamp()

void str_timestamp ( char * buffer,
int buffer_size )

Copies a timestamp of the current time in the format year-month-day_hour-minute-second to the string.

Parameters
bufferPointer to a buffer that shall receive the timestamp string.
buffer_sizeSize of the buffer.
Remarks
Guarantees that buffer string will contain null-termination.

◆ str_timestamp_ex()

void str_timestamp_ex ( time_t time,
char * buffer,
int buffer_size,
const char * format )

Copies a timestamp of the given time in the given format to the string.

Parameters
timeThe time value to represent as a string.
bufferPointer to a buffer that shall receive the timestamp string.
buffer_sizeSize of the buffer.
formatTime formatting string. See https://cppreference.com/w/c/chrono/strftime.html for format description.
Remarks
Guarantees that buffer string will contain null-termination.

◆ str_timestamp_format()

void str_timestamp_format ( char * buffer,
int buffer_size,
const char * format )

Copies a timestamp of the current time in the given format to the string.

Parameters
bufferPointer to a buffer that shall receive the timestamp string.
buffer_sizeSize of the buffer.
formatTime formatting string. See https://cppreference.com/w/c/chrono/strftime.html for format description.
Remarks
Guarantees that buffer string will contain null-termination.

◆ time_timestamp()

int64_t time_timestamp ( )

Retrieves the current time as a UNIX timestamp.

Returns
The time as a UNIX timestamp.

◆ timestamp_from_str()

bool timestamp_from_str ( const char * string,
const char * format,
time_t * timestamp )

Parses a string into a timestamp following a specified format.

Parameters
stringPointer to the string to parse.
formatThe time format to use (for example FORMAT_NOSPACE below).
timestampPointer to the timestamp result.
Returns
true on success, false if the string could not be parsed with the specified format.