summaryrefslogtreecommitdiff
path: root/absl/time/internal/cctz/include/cctz/civil_time_detail.h
diff options
context:
space:
mode:
Diffstat (limited to 'absl/time/internal/cctz/include/cctz/civil_time_detail.h')
-rw-r--r--absl/time/internal/cctz/include/cctz/civil_time_detail.h18
1 files changed, 7 insertions, 11 deletions
diff --git a/absl/time/internal/cctz/include/cctz/civil_time_detail.h b/absl/time/internal/cctz/include/cctz/civil_time_detail.h
index d1b4222b..8aadde57 100644
--- a/absl/time/internal/cctz/include/cctz/civil_time_detail.h
+++ b/absl/time/internal/cctz/include/cctz/civil_time_detail.h
@@ -416,16 +416,10 @@ class civil_time {
// Assigning arithmetic.
CONSTEXPR_M civil_time& operator+=(diff_t n) noexcept {
- f_ = step(T{}, f_, n);
- return *this;
+ return *this = *this + n;
}
CONSTEXPR_M civil_time& operator-=(diff_t n) noexcept {
- if (n != (std::numeric_limits<diff_t>::min)()) {
- f_ = step(T{}, f_, -n);
- } else {
- f_ = step(T{}, step(T{}, f_, -(n + 1)), 1);
- }
- return *this;
+ return *this = *this - n;
}
CONSTEXPR_M civil_time& operator++() noexcept { return *this += 1; }
CONSTEXPR_M civil_time operator++(int) noexcept {
@@ -442,13 +436,15 @@ class civil_time {
// Binary arithmetic operators.
friend CONSTEXPR_F civil_time operator+(civil_time a, diff_t n) noexcept {
- return a += n;
+ return civil_time(step(T{}, a.f_, n));
}
friend CONSTEXPR_F civil_time operator+(diff_t n, civil_time a) noexcept {
- return a += n;
+ return a + n;
}
friend CONSTEXPR_F civil_time operator-(civil_time a, diff_t n) noexcept {
- return a -= n;
+ return n != (std::numeric_limits<diff_t>::min)()
+ ? civil_time(step(T{}, a.f_, -n))
+ : civil_time(step(T{}, step(T{}, a.f_, -(n + 1)), 1));
}
friend CONSTEXPR_F diff_t operator-(civil_time lhs, civil_time rhs) noexcept {
return difference(T{}, lhs.f_, rhs.f_);