Types and Functions for Time Handling in Cognitive Automobiles. More...
Defines | |
#define | _const |
constant argument, but irrelevant in C | |
#define | KOGMO_TIMESTAMP_TICKSPERSECOND 1000000000 |
Ticks per Second. Value, by which the result from kogmo_timestamp_now() will be incremented every second. | |
#define | KOGMO_TIMESTAMP_NANOSECONDSPERTICK (1000000000/KOGMO_TIMESTAMP_TICKSPERSECOND) |
#define | KOGMO_TIMESTAMP_STRINGLENGTH 30 |
Length of the Output of kogmo_timestamp_to_string(). | |
Typedefs | |
typedef int64_t | kogmo_timestamp_t |
Absolute Timestamp (in Ticks since the "Epoch"). | |
typedef char | kogmo_timestamp_string_t [KOGMO_TIMESTAMP_STRINGLENGTH] |
Type of a pre-allocated String to receive the Output of kogmo_timestamp_to_string(). | |
Functions | |
kogmo_timestamp_t | kogmo_timestamp_now (void) |
Get absolute Timestamp for current Time. | |
int64_t | kogmo_timestamp_diff_ns (kogmo_timestamp_t ts_begin, kogmo_timestamp_t ts_end) |
Calcute difference between two Timestamps (in Nanoseconds). | |
double | kogmo_timestamp_diff_secs (kogmo_timestamp_t ts_begin, kogmo_timestamp_t ts_end) |
Calcute difference between two Timestamps (in Seconds, floating point). | |
kogmo_timestamp_t | kogmo_timestamp_add_ns (kogmo_timestamp_t ts, int64_t ns) |
Add time offset to Timestamps (in Nanoseconds). | |
kogmo_timestamp_t | kogmo_timestamp_add_secs (kogmo_timestamp_t ts, double secs) |
Add time offset to Timestamps (in Seconds, floating point). | |
int | kogmo_timestamp_to_string (kogmo_timestamp_t ts, kogmo_timestamp_string_t str) |
Convert an Absolute Timestamp to a String, formated according to the ISO-Standard. | |
kogmo_timestamp_t | kogmo_timestamp_from_string (_const char *str) |
Convert an ISO-Time-String to an Absolute Timestamp. |
Types and Functions for Time Handling in Cognitive Automobiles.
#define _const |
constant argument, but irrelevant in C
Definition at line 29 of file kogmo_time.h.
#define KOGMO_TIMESTAMP_NANOSECONDSPERTICK (1000000000/KOGMO_TIMESTAMP_TICKSPERSECOND) |
Definition at line 90 of file kogmo_time.h.
#define KOGMO_TIMESTAMP_STRINGLENGTH 30 |
Length of the Output of kogmo_timestamp_to_string().
Definition at line 147 of file kogmo_time.h.
#define KOGMO_TIMESTAMP_TICKSPERSECOND 1000000000 |
Ticks per Second. Value, by which the result from kogmo_timestamp_now() will be incremented every second.
As we use Nanoseconds, its equal to 1000000000.
But *PLEASE* dont hardcode 1000000000 anywere, use this constant if necessary!
Better use the following functions to handle timestamps.
Definition at line 89 of file kogmo_time.h.
typedef char kogmo_timestamp_string_t[KOGMO_TIMESTAMP_STRINGLENGTH] |
Type of a pre-allocated String to receive the Output of kogmo_timestamp_to_string().
Definition at line 152 of file kogmo_time.h.
typedef int64_t kogmo_timestamp_t |
Absolute Timestamp (in Ticks since the "Epoch").
This is the reference type that to be used for all timestamps.
It can represent points in time from the year 1970 until 2262 with a nanosecond resolution.
Background:
The Epoch starts 00:00:00 UTC, January 1, 1970, see also (POSIX.1 and time(2), http://de.wikipedia.org/wiki/Epoch).
This is a signed 64-Bit value that will overflow in the year 2262.
( 2^63/1000000000/60/60/24/365 = 292.471.. )
Why a 64-Bit value value? Aren't 32 Bits enough?
A 32-Bit (unsigned) value would overflow after
So only a millisecond granularity would be usefull, but
So please
There are convenience functions with float-times in seconds, these can also be used in calculations.
For exchanging times you should use kogmo_time_t.
For any questions, please contact me! Matthias Goebl <matthias.goebl*goebl.net>
Definition at line 78 of file kogmo_time.h.
kogmo_timestamp_t kogmo_timestamp_add_ns | ( | kogmo_timestamp_t | ts, | |
int64_t | ns | |||
) |
Add time offset to Timestamps (in Nanoseconds).
ts | Timestamp | |
ns | Nanoseconds to add, can be negative (64-Bit integer value) |
kogmo_timestamp_t kogmo_timestamp_add_secs | ( | kogmo_timestamp_t | ts, | |
double | secs | |||
) |
Add time offset to Timestamps (in Seconds, floating point).
ts | Timestamp | |
secs | Seconds to add, can be negative (floating point value) |
int64_t kogmo_timestamp_diff_ns | ( | kogmo_timestamp_t | ts_begin, | |
kogmo_timestamp_t | ts_end | |||
) |
Calcute difference between two Timestamps (in Nanoseconds).
ts_begin | First Timestamp, begin of the interval | |
ts_end | Second Timestamp, end of the interval |
double kogmo_timestamp_diff_secs | ( | kogmo_timestamp_t | ts_begin, | |
kogmo_timestamp_t | ts_end | |||
) |
Calcute difference between two Timestamps (in Seconds, floating point).
This may simplify your calculations.
For exchanging timestamps you should use kogmo_timestamp_t instead.
ts_begin | First Timestamp, begin of the interval | |
ts_end | Second Timestamp, end of the interval |
kogmo_timestamp_t kogmo_timestamp_from_string | ( | _const char * | str | ) |
Convert an ISO-Time-String to an Absolute Timestamp.
str | Time as String, see kogmo_timestamp_to_string() for format |
For a incomplete ISO8601-Time the missing elements will be assumed to 0.
For your comfort, str can also be a numeric timestamp in a string (>9999).
kogmo_timestamp_t kogmo_timestamp_now | ( | void | ) |
Get absolute Timestamp for current Time.
int kogmo_timestamp_to_string | ( | kogmo_timestamp_t | ts, | |
kogmo_timestamp_string_t | str | |||
) |
Convert an Absolute Timestamp to a String, formated according to the ISO-Standard.
Format: 2006-04-26 23:54:27.832241000 (YYYY-MM-DD hh:mm:ss.sssssssss)
ts | Timestamp | |
str | Pre-Allocated String for the Output |
The format follows ISO 8601 "Data elements and interchange formats,
Information interchange, Representation of dates and times", with the addition of subseconds as ".sssssssss".
See http://en.wikipedia.org/wiki/ISO_8601 and http://hydracen.com/dx/iso8601.htm.