Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
dcdb
dcdb
Commits
0093452f
Commit
0093452f
authored
Feb 10, 2017
by
Michael Ott
Browse files
Add new timestamp.h
parent
9493ece6
Changes
1
Hide whitespace changes
Inline
Side-by-side
include/timestamp.h
0 → 100644
View file @
0093452f
/*
* timestamp.h
*
* Created on: 10 Feb 2017
* Author: ottmi
*/
#ifndef INCLUDE_TIMESTAMP_H_
#define INCLUDE_TIMESTAMP_H_
#include <boost/date_time/posix_time/posix_time.hpp>
#include <string>
#include <sstream>
#define S_TO_NS(x) x*1000000000ll
#define MS_TO_NS(x) x*1000000ll
#define US_TO_NS(x) x*1000ll
static
uint64_t
getTimestamp
()
{
boost
::
posix_time
::
ptime
epoch
(
boost
::
gregorian
::
date
(
1970
,
1
,
1
));
boost
::
posix_time
::
ptime
now
=
boost
::
posix_time
::
microsec_clock
::
universal_time
();
boost
::
posix_time
::
time_duration
diff
=
now
-
epoch
;
return
diff
.
total_nanoseconds
();
}
static
uint64_t
ptime2Timestamp
(
const
boost
::
posix_time
::
ptime
t
)
{
boost
::
posix_time
::
ptime
epoch
(
boost
::
gregorian
::
date
(
1970
,
1
,
1
));
boost
::
posix_time
::
time_duration
diff
=
t
-
epoch
;
return
diff
.
total_nanoseconds
();
}
static
boost
::
posix_time
::
ptime
timestamp2ptime
(
const
uint64_t
ts
)
{
return
boost
::
posix_time
::
ptime
(
boost
::
gregorian
::
date
(
1970
,
1
,
1
),
boost
::
posix_time
::
nanoseconds
(
ts
));
}
static
std
::
string
prettyPrintTimestamp
(
const
uint64_t
ts
)
{
std
::
stringstream
ss
;
ss
<<
ts
/
1000000000
<<
"."
<<
std
::
setw
(
9
)
<<
std
::
setfill
(
'0'
)
<<
ts
%
1000000000
;
return
ss
.
str
();
}
#endif
/* INCLUDE_TIMESTAMP_H_ */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment