10 #include "common/time/Constants.h"
24 Duration() : seconds(0), microseconds(0), months(0) {}
25 Duration(int32_t m, int64_t s, int32_t us) : seconds(s), microseconds(us), months(m) {}
27 int64_t years()
const {
31 int64_t monthsInYear()
const {
35 int64_t days()
const {
36 return seconds / time::kSecondsOfDay;
39 int64_t hours()
const {
40 return seconds % time::kSecondsOfDay / time::kSecondsOfHour;
43 int64_t minutes()
const {
44 return seconds % time::kSecondsOfHour / time::kSecondsOfMinute;
47 int64_t secondsInMinute()
const {
48 return seconds % time::kSecondsOfMinute;
51 int64_t microsecondsInSecond()
const {
56 return Duration(-months, -seconds, -microseconds);
60 return Duration(months + rhs.months, seconds + rhs.seconds, microseconds + rhs.microseconds);
64 return Duration(months - rhs.months, seconds - rhs.seconds, microseconds - rhs.microseconds);
83 seconds += (w * 7 * time::kSecondsOfDay);
88 seconds += d * time::kSecondsOfDay;
93 seconds += h * time::kSecondsOfHour;
97 Duration& addMinutes(int64_t minutes) {
98 seconds += minutes * time::kSecondsOfMinute;
107 Duration& addMilliseconds(int64_t ms) {
108 seconds += ms / 1000;
109 microseconds += ((ms % 1000) * 1000);
113 Duration& addMicroseconds(int32_t us) {
119 bool operator<(
const Duration& rhs)
const =
delete;
121 bool operator==(
const Duration& rhs)
const {
122 return months == rhs.months && seconds == rhs.seconds && microseconds == rhs.microseconds;
125 std::string toString()
const;
134 struct hash<nebula::Duration> {