diff options
author | Abseil Team <absl-team@google.com> | 2020-06-10 15:35:34 -0700 |
---|---|---|
committer | vslashg <gfalcon@google.com> | 2020-06-10 18:59:53 -0400 |
commit | e7ebf9803746b9a115d96164bdf5e915be8f223b (patch) | |
tree | 2ccafec5290edd068ee47751efb56f2eb51134b2 /absl/time/internal | |
parent | 2eba343b51e0923cd3fb919a6abd6120590fc059 (diff) |
Export of internal Abseil changes
--
44b312da54263fc7491b5f1e115e49e0c1e2dc10 by Greg Falcon <gfalcon@google.com>:
Import of CCTZ from GitHub.
PiperOrigin-RevId: 315782632
--
27618a3b195f75384ba44e9712ae0b0b7d85937e by Greg Falcon <gfalcon@google.com>:
Update Abseil's internal Invoke() implementation to follow C++17 semantics.
Starting in C++17, when invoke'ing a pointer-to-member, if the object representing the class is a reference_wrapper, that wrapper is unpacked. Because we implement a number of functional APIs that closely match C++ standard proposals, it is better if we follow the standard's notion of what "invoking" means.
This also makes `absl::base_internal::Invoke()` match `std::invoke()` in C++17. I intend to make this an alias in a follow-up CL.
PiperOrigin-RevId: 315750659
--
059519ea402cd55b1b716403bb680504c6ff5808 by Xiaoyi Zhang <zhangxy@google.com>:
Internal change
PiperOrigin-RevId: 315597064
--
5e2042c8520576b2508e2bfb1020a97c7db591da by Titus Winters <titus@google.com>:
Update notes on the delta between absl::Span vs. std::span.
PiperOrigin-RevId: 315518942
--
9d3875527b93124f5de5d6a1d575c42199fbf323 by Abseil Team <absl-team@google.com>:
Internal cleanup
PiperOrigin-RevId: 315497633
GitOrigin-RevId: 44b312da54263fc7491b5f1e115e49e0c1e2dc10
Change-Id: I24573f317c8388bd693c0fdab395a7dd419b33b0
Diffstat (limited to 'absl/time/internal')
-rw-r--r-- | absl/time/internal/cctz/include/cctz/civil_time_detail.h | 42 | ||||
-rw-r--r-- | absl/time/internal/cctz/src/civil_time_test.cc | 10 |
2 files changed, 36 insertions, 16 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 4cde96f1..d1b4222b 100644 --- a/absl/time/internal/cctz/include/cctz/civil_time_detail.h +++ b/absl/time/internal/cctz/include/cctz/civil_time_detail.h @@ -106,54 +106,64 @@ CONSTEXPR_F int days_per_month(year_t y, month_t m) noexcept { CONSTEXPR_F fields n_day(year_t y, month_t m, diff_t d, diff_t cd, hour_t hh, minute_t mm, second_t ss) noexcept { - y += (cd / 146097) * 400; + year_t ey = y % 400; + const year_t oey = ey; + ey += (cd / 146097) * 400; cd %= 146097; if (cd < 0) { - y -= 400; + ey -= 400; cd += 146097; } - y += (d / 146097) * 400; + ey += (d / 146097) * 400; d = d % 146097 + cd; if (d > 0) { if (d > 146097) { - y += 400; + ey += 400; d -= 146097; } } else { if (d > -365) { // We often hit the previous year when stepping a civil time backwards, // so special case it to avoid counting up by 100/4/1-year chunks. - y -= 1; - d += days_per_year(y, m); + ey -= 1; + d += days_per_year(ey, m); } else { - y -= 400; + ey -= 400; d += 146097; } } if (d > 365) { - for (int n = days_per_century(y, m); d > n; n = days_per_century(y, m)) { + for (;;) { + int n = days_per_century(ey, m); + if (d <= n) break; d -= n; - y += 100; + ey += 100; } - for (int n = days_per_4years(y, m); d > n; n = days_per_4years(y, m)) { + for (;;) { + int n = days_per_4years(ey, m); + if (d <= n) break; d -= n; - y += 4; + ey += 4; } - for (int n = days_per_year(y, m); d > n; n = days_per_year(y, m)) { + for (;;) { + int n = days_per_year(ey, m); + if (d <= n) break; d -= n; - ++y; + ++ey; } } if (d > 28) { - for (int n = days_per_month(y, m); d > n; n = days_per_month(y, m)) { + for (;;) { + int n = days_per_month(ey, m); + if (d <= n) break; d -= n; if (++m > 12) { - ++y; + ++ey; m = 1; } } } - return fields(y, m, static_cast<day_t>(d), hh, mm, ss); + return fields(y + (ey - oey), m, static_cast<day_t>(d), hh, mm, ss); } CONSTEXPR_F fields n_mon(year_t y, diff_t m, diff_t d, diff_t cd, hour_t hh, minute_t mm, second_t ss) noexcept { diff --git a/absl/time/internal/cctz/src/civil_time_test.cc b/absl/time/internal/cctz/src/civil_time_test.cc index be894d70..a5a71230 100644 --- a/absl/time/internal/cctz/src/civil_time_test.cc +++ b/absl/time/internal/cctz/src/civil_time_test.cc @@ -235,6 +235,16 @@ TEST(CivilTime, Difference) { } // NOTE: Run this with --copt=-ftrapv to detect overflow problems. +TEST(CivilTime, ConstructionWithHugeYear) { + constexpr civil_hour h(-9223372036854775807, 1, 1, -1); + static_assert(h.year() == -9223372036854775807 - 1, + "ConstructionWithHugeYear"); + static_assert(h.month() == 12, "ConstructionWithHugeYear"); + static_assert(h.day() == 31, "ConstructionWithHugeYear"); + static_assert(h.hour() == 23, "ConstructionWithHugeYear"); +} + +// NOTE: Run this with --copt=-ftrapv to detect overflow problems. TEST(CivilTime, DifferenceWithHugeYear) { { constexpr civil_day d1(9223372036854775807, 1, 1); |