| 1 | // -------------------------------------------------------------------------- |
|---|
| 2 | // |
|---|
| 3 | // File |
|---|
| 4 | // Name: BoxTime.h |
|---|
| 5 | // Purpose: How time is represented |
|---|
| 6 | // Created: 2003/10/08 |
|---|
| 7 | // |
|---|
| 8 | // -------------------------------------------------------------------------- |
|---|
| 9 | |
|---|
| 10 | #ifndef BOXTIME__H |
|---|
| 11 | #define BOXTIME__H |
|---|
| 12 | |
|---|
| 13 | // Time is presented as an unsigned 64 bit integer, in microseconds |
|---|
| 14 | typedef int64_t box_time_t; |
|---|
| 15 | |
|---|
| 16 | #define NANO_SEC_IN_SEC (1000000000LL) |
|---|
| 17 | #define NANO_SEC_IN_USEC (1000) |
|---|
| 18 | #define NANO_SEC_IN_USEC_LL (1000LL) |
|---|
| 19 | #define MICRO_SEC_IN_SEC (1000000) |
|---|
| 20 | #define MICRO_SEC_IN_SEC_LL (1000000LL) |
|---|
| 21 | #define MILLI_SEC_IN_SEC (1000) |
|---|
| 22 | #define MILLI_SEC_IN_SEC_LL (1000LL) |
|---|
| 23 | |
|---|
| 24 | box_time_t GetCurrentBoxTime(); |
|---|
| 25 | |
|---|
| 26 | inline box_time_t SecondsToBoxTime(time_t Seconds) |
|---|
| 27 | { |
|---|
| 28 | return ((box_time_t)Seconds * MICRO_SEC_IN_SEC_LL); |
|---|
| 29 | } |
|---|
| 30 | inline uint64_t MilliSecondsToBoxTime(int64_t milliseconds) |
|---|
| 31 | { |
|---|
| 32 | return ((box_time_t)milliseconds * 1000); |
|---|
| 33 | } |
|---|
| 34 | inline time_t BoxTimeToSeconds(box_time_t Time) |
|---|
| 35 | { |
|---|
| 36 | return Time / MICRO_SEC_IN_SEC_LL; |
|---|
| 37 | } |
|---|
| 38 | inline uint64_t BoxTimeToMilliSeconds(box_time_t Time) |
|---|
| 39 | { |
|---|
| 40 | return Time / MILLI_SEC_IN_SEC_LL; |
|---|
| 41 | } |
|---|
| 42 | inline uint64_t BoxTimeToMicroSeconds(box_time_t Time) |
|---|
| 43 | { |
|---|
| 44 | return Time; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | std::string FormatTime(box_time_t time, bool includeDate, |
|---|
| 48 | bool showMicros = false); |
|---|
| 49 | |
|---|
| 50 | void ShortSleep(box_time_t duration, bool logDuration); |
|---|
| 51 | |
|---|
| 52 | #endif // BOXTIME__H |
|---|