YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/util/timestamp.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) YugaByte, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4
// in compliance with the License.  You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software distributed under the License
9
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10
// or implied.  See the License for the specific language governing permissions and limitations
11
// under the License.
12
//
13
14
#ifndef YB_UTIL_TIMESTAMP_H_
15
#define YB_UTIL_TIMESTAMP_H_
16
17
#include <inttypes.h>
18
#include <string>
19
#include "yb/util/status_fwd.h"
20
21
namespace yb {
22
23
class Timestamp {
24
 public:
25
  typedef int64_t val_type;
26
34.2M
  explicit Timestamp(int64_t value) : value_(value) {}
27
  Timestamp() : value_(0) {}
28
  int64_t ToInt64() const;
29
  CHECKED_STATUS FromInt64(int64_t value);
30
31
  std::string ToString() const;
32
33
  std::string ToFormattedString() const;
34
35
  // Return date in human readable format (in local time zone).
36
  // For example, 2021-Jan-10 22:29:35.776000.
37
  std::string ToHumanReadableTime() const;
38
39
25.8k
  val_type value() const { return value_; }
40
  void set_value(int64_t value) {value_ = value;}
41
42
1.66M
  bool operator ==(const Timestamp &other) const {
43
1.66M
    return value_ == other.value_;
44
1.66M
  }
45
0
  bool operator !=(const Timestamp &other) const {
46
0
    return value_ != other.value_;
47
0
  }
48
49
  int CompareTo(const Timestamp &other) const;
50
51
641
  bool operator <(const Timestamp& other) const {
52
641
    return CompareTo(other) < 0;
53
641
  }
54
55
0
  bool operator >(const Timestamp& other) const {
56
0
    return CompareTo(other) > 0;
57
0
  }
58
59
0
  bool operator <=(const Timestamp& other) const {
60
0
    return CompareTo(other) <= 0;
61
0
  }
62
63
0
  bool operator >=(const Timestamp& other) const {
64
0
    return CompareTo(other) >= 0;
65
0
  }
66
67
 private:
68
  val_type value_;
69
};
70
71
641
inline int Timestamp::CompareTo(const Timestamp &other) const {
72
641
  if (value_ < other.value_) {
73
298
    return -1;
74
343
  } else if (value_ > other.value_) {
75
149
    return 1;
76
149
  }
77
194
  return 0;
78
641
}
79
80
inline std::ostream &operator <<(std::ostream &o, const Timestamp &timestamp) {
81
  return o << timestamp.ToString();
82
}
83
84
} // namespace yb
85
86
#endif // YB_UTIL_TIMESTAMP_H_