Revision 8db9ba4f src/timestamp.cpp
| src/timestamp.cpp | ||
|---|---|---|
| 1 | 1 |
#include "timestamp.h" |
| 2 |
#include <math.h> |
|
| 2 | 3 |
|
| 3 | 4 |
using namespace std; |
| 4 | 5 |
using namespace humotion; |
| 5 | 6 |
|
| 6 | 7 |
Timestamp::Timestamp(void){
|
| 7 | 8 |
//init of an empty timestamp will be assigned to the current system time |
| 8 |
struct timespec tp; |
|
| 9 |
clock_gettime(CLOCK_REALTIME, &tp); |
|
| 10 |
sec = tp.tv_sec; |
|
| 11 |
nsec = tp.tv_nsec; |
|
| 9 |
set(now()); |
|
| 12 | 10 |
} |
| 13 | 11 |
|
| 14 | 12 |
Timestamp::Timestamp(int32_t _sec, int32_t _nsec){
|
| 15 | 13 |
set(_sec, _nsec); |
| 16 | 14 |
} |
| 17 | 15 |
|
| 16 |
Timestamp::Timestamp(double dsec){
|
|
| 17 |
double fsec, fnsec; |
|
| 18 |
fnsec = modf (dsec , &fsec); |
|
| 19 |
sec = fsec; |
|
| 20 |
nsec = fnsec * 1000000000.0; |
|
| 21 |
} |
|
| 22 |
|
|
| 23 |
Timestamp Timestamp::now(void){
|
|
| 24 |
Timestamp res; |
|
| 25 |
struct timespec tp; |
|
| 26 |
clock_gettime(CLOCK_REALTIME, &tp); |
|
| 27 |
res.set(tp.tv_sec, tp.tv_nsec); |
|
| 28 |
return res; |
|
| 29 |
} |
|
| 30 |
|
|
| 18 | 31 |
void Timestamp::set(int32_t _sec, int32_t _nsec){
|
| 19 | 32 |
sec = _sec; |
| 20 | 33 |
nsec = _nsec; |
| 21 | 34 |
} |
| 22 | 35 |
|
| 36 |
void Timestamp::set(Timestamp a){
|
|
| 37 |
set(a.sec, a.nsec); |
|
| 38 |
} |
|
| 39 |
|
|
| 23 | 40 |
double Timestamp::to_seconds(void){
|
| 24 | 41 |
return sec + ((double)nsec)/1000000000.0; |
| 25 | 42 |
} |
Also available in: Unified diff