2 // Copyright (c) 2010-2017 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
21 #include "timestamp.hpp"
23 Timestamp Timestamp::operator-(const Timestamp& other) const
28 if (other.m_nsec <= m_nsec) {
29 nsec = m_nsec - other.m_nsec;
30 sec = m_sec - other.m_sec;
32 nsec = (1000000000 + m_nsec) - other.m_nsec;
33 sec = m_sec - 1 - other.m_sec;
36 return Timestamp(sec, nsec);
39 bool Timestamp::operator>(const Timestamp& other)
41 return m_sec > other.m_sec ||
42 (m_sec == other.m_sec && m_nsec > other.m_nsec);
45 bool Timestamp::operator<(const Timestamp& other)
47 return m_sec < other.m_sec ||
48 (m_sec == other.m_sec && m_nsec < other.m_nsec);
51 ostream& operator<<(ostream& stream, const Timestamp& ts)
53 stream << ts.m_sec << "." << setw(9) << setfill('0') << ts.m_nsec;
57 double operator/(double d, const Timestamp &denominator)
59 return d * 1000000000 / (denominator.m_sec * 1000000000 + denominator.m_nsec);
62 bool Timestamp::operator==(const Timestamp &other) const
64 return m_sec == other.m_sec && m_nsec == other.m_nsec;