1#include "timestamp.hpp"
2#include "vanetza/common/byte_order.hpp"
3#include <boost/date_time/gregorian/gregorian.hpp>
13Timestamp::unit_type Timestamp::millisecond()
15 return Timestamp::unit_type();
18boost::posix_time::ptime Timestamp::start_time()
20 static const boost::posix_time::ptime start {
21 boost::gregorian::date(2004, 1, 1),
22 boost::posix_time::milliseconds(0)
27Timestamp::Timestamp(
const Clock::time_point& time)
29 using namespace std::chrono;
30 const auto since_epoch = time.time_since_epoch();
31 const auto since_epoch_ms = duration_cast<milliseconds>(since_epoch);
32 m_timestamp = since_epoch_ms.count() * absolute_unit_type();
35Timestamp::Timestamp(
const boost::posix_time::ptime& time)
37 assert(time >= start_time());
38 const value_type since_start_ms = (time - start_time()).total_milliseconds();
39 m_timestamp = since_start_ms * absolute_unit_type();
42Timestamp& Timestamp::operator+=(duration_type rhs)
48Timestamp& Timestamp::operator-=(duration_type rhs)
68 return lhs.quantity() - rhs.quantity();
83 const auto max = std::numeric_limits<Timestamp::value_type>::max();
84 const Timestamp::value_type lhs_raw = lhs.raw();
85 const Timestamp::value_type rhs_raw = rhs.raw();
87 if ((lhs_raw > rhs_raw && lhs_raw - rhs_raw <= max/2) ||
88 (rhs_raw > lhs_raw && rhs_raw - lhs_raw > max/2)) {
97 return (!is_greater(lhs, rhs) && lhs != rhs);
102 return lhs.raw() == rhs.raw();
107 serialize(host_cast(ts.raw()), ar);
112 Timestamp::value_type tmp;
113 deserialize(tmp, ar);
114 ts =
Timestamp { Timestamp::time_type::from_value(tmp) };
bool after(const Timestamp &other) const
bool before(const Timestamp &other) const