cTimestamp

Overview

Provides a struct and a set of function to work with a moment in time. It saves the nano seconds since 00:00:00 UTC on 1 January 1970.

Types and Definitions

cTimestamp

struct cTimestamp
{
   int64_t _v;
};
typedef struct cTimestamp cTimestamp;

A cTimestamp value represents a moment in time.

Generated

cTimestampSlice

struct cTimestampSlice
{
   int64_t s;
   cTimestamp const* v;
};
typedef struct cTimestampSlice cTimestampSlice;

Via the macro SLICES_C_ generated struct.

cVarTimestampSlice

struct cVarTimestampSlice
{
   int64_t s;
   cTimestamp* v;
};
typedef struct cVarTimestampSlice cVarTimestampSlice;

Via the macro SLICES_C_ generated struct.

Functions

init

now_c

cTimestamp now_c( void );

Returns the actual moment in time.

null_timestamp_c

cTimestamp null_timestamp_c( void );

Returns an invalid moment in time.

unix_timestamp_c

cTimestamp unix_timestamp_c( cDuration dur );

Creates a timestamp instance from the duration since 00:00:00 UTC on 1 January 1970.

unix

timestamp_secs_c

int64_t timestamp_secs_c( cTimestamp ts );

Returns the seconds since 00:00:00 UTC on 1 January 1970.

timestamp_msecs_c

int64_t timestamp_msecs_c( cTimestamp ts );

Returns the milliseconds since 00:00:00 UTC on 1 January 1970.

timestamp_usecs_c

int64_t timestamp_usecs_c( cTimestamp ts );

Returns the microseconds since 00:00:00 UTC on 1 January 1970.

timestamp_nsecs_c

int64_t timestamp_nsecs_c( cTimestamp ts );

Returns the nanoseconds since 00:00:00 UTC on 1 January 1970.

cmp

cmp_timestamp_c

int cmp_timestamp_c( cTimestamp a, cTimestamp b );

Compares two timestamps and returns the three possible results:

<0

if a is earlier as b

0

if both dates are equal

>0

if a is later as b

eq_timestamp_c

bool eq_timestamp_c( cTimestamp a, cTimestamp b );

Returns true if both timestamps represent the same moment in time, otherwise false.

timestamp_is_valid_c

bool timestamp_is_valid_c( cTimestamp ts );

Returns true if the timespan represents a valid moment in time.

diff

between_timestamps_c

cDuration between_timestamps_c( cTimestamp a, cTimestamp b );

Returns the duration between two timestamps.

since_c

cDuration since_c( cTimestamp ts );

Returns the duration between the timestamp and now.

until_c

cDuration until_c( cTimestamp ts );

Returns the duration between now and the timestamp.