Qpid Proton C++ API  0.37.0
timestamp.hpp
Go to the documentation of this file.
1 #ifndef PROTON_TIMESTAMP_HPP
2 #define PROTON_TIMESTAMP_HPP
3 
4 /*
5  * Licensed to the Apache Software Foundation (ASF) under one
6  * or more contributor license agreements. See the NOTICE file
7  * distributed with this work for additional information
8  * regarding copyright ownership. The ASF licenses this file
9  * to you under the Apache License, Version 2.0 (the
10  * "License"); you may not use this file except in compliance
11  * with the License. You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing,
16  * software distributed under the License is distributed on an
17  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18  * KIND, either express or implied. See the License for the
19  * specific language governing permissions and limitations
20  * under the License.
21  */
22 
23 #include "./duration.hpp"
24 
25 #include <proton/type_compat.h>
26 
29 
30 namespace proton {
31 
35 class timestamp : private internal::comparable<timestamp> {
36  public:
38  typedef int64_t numeric_type;
39 
41  PN_CPP_EXTERN static timestamp now();
42 
44  explicit timestamp(numeric_type ms = 0) : ms_(ms) {}
45 
47  timestamp& operator=(numeric_type ms) { ms_ = ms; return *this; }
48 
50  numeric_type milliseconds() const { return ms_; }
51 
52  private:
53  numeric_type ms_;
54 };
55 
58 inline bool operator==(timestamp x, timestamp y) { return x.milliseconds() == y.milliseconds(); }
59 inline bool operator<(timestamp x, timestamp y) { return x.milliseconds() < y.milliseconds(); }
60 
61 inline timestamp operator+(timestamp ts, duration d) { return timestamp(ts.milliseconds() + d.milliseconds()); }
62 inline timestamp operator-(timestamp ts, duration d) { return timestamp(ts.milliseconds() - d.milliseconds()); }
63 inline duration operator-(timestamp t0, timestamp t1) { return duration(t0.milliseconds() - t1.milliseconds()); }
64 inline timestamp operator+(duration d, timestamp ts) { return ts + d; }
66 
68 PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, timestamp);
69 
70 } // proton
71 
72 #endif // PROTON_TIMESTAMP_HPP
A 64-bit timestamp in milliseconds since the Unix epoch.
Definition: timestamp.hpp:35
int64_t numeric_type
A numeric type holding a value in milliseconds.
Definition: timestamp.hpp:38
timestamp(numeric_type ms=0)
Construct from a value in milliseconds.
Definition: timestamp.hpp:44
static timestamp now()
The current wall-clock time.
timestamp & operator=(numeric_type ms)
Assign a value in milliseconds.
Definition: timestamp.hpp:47
numeric_type milliseconds() const
Get the value in milliseconds.
Definition: timestamp.hpp:50
A span of time in milliseconds.
The main Proton namespace.
Definition: annotation_key.hpp:33
std::ostream & operator<<(std::ostream &, const binary &)
Print a binary value.