DDNet documentation
Loading...
Searching...
No Matches
Timestamps

Namespaces

namespace  TimestampFormat

Enumerations

enum class  ETimeFormat {
  ETimeFormat::DAYS , ETimeFormat::HOURS , ETimeFormat::MINS , ETimeFormat::HOURS_CENTISECS ,
  ETimeFormat::MINS_CENTISECS , ETimeFormat::SECS_CENTISECS
}

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)
int64_t time_milliseconds_from_seconds (float seconds)
int str_time (int64_t centisecs, ETimeFormat format, char *buffer, int buffer_size)
int str_time_float (float secs, ETimeFormat format, char *buffer, int buffer_size)

Detailed Description

Timestamp related functions.

Time

Enumeration Type Documentation

◆ ETimeFormat

enum class ETimeFormat
strong

Time formats for the str_time and str_time_float functions.

See also
str_time
str_time_float
Enumerator
DAYS 
HOURS 
MINS 
HOURS_CENTISECS 
MINS_CENTISECS 
SECS_CENTISECS 

Function Documentation

◆ str_time()

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

Formats a time string.

Parameters
centisecsTime in centiseconds.
formatFormat of the time string, see ETimeFormat.
bufferPointer to a buffer that shall receive the timestamp string.
buffer_sizeSize of the buffer.
Returns
Number of bytes written.

◆ str_time_float()

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

Formats a time string.

Parameters
secsTime in seconds.
formatFormat of the time string, see ETimeFormat.
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.

◆ 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. See TimestampFormat for common formats.
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. See TimestampFormat for common formats.
Remarks
Guarantees that buffer string will contain null-termination.

◆ time_milliseconds_from_seconds()

int64_t time_milliseconds_from_seconds ( float seconds)

Returns the number of milliseconds from a time float.

Takes care to not introduce more rounding issues, which is what a naive std::roundf(seconds * 1000.0) would do.

Parameters
secondsTime in seconds.
Returns
Number of milliseconds.

◆ 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. See TimestampFormat for common formats.
timestampPointer to the timestamp result.
Returns
true on success, false if the string could not be parsed with the specified format.