diff options
author | Abseil Team <absl-team@google.com> | 2019-05-08T21·20-0700 |
---|---|---|
committer | Eric Fiselier <eric@efcs.ca> | 2019-05-08T22·40-0400 |
commit | 27c2f6e2f3b5929fbd322b0f0ca392eb02efd9f8 (patch) | |
tree | da69e1d0f4cddb3b56f6d7af4ef28414641dbe0a /absl/time/internal/cctz/include | |
parent | aa468ad75539619b47979911297efbb629c52e44 (diff) |
Export of internal Abseil changes.
-- 9fa04b5fb4b6aeb47226b9095b3bc36a53669c39 by Abseil Team <absl-team@google.com>: Release types/compare.h, which contains stand ins for three-way comparison result types from C++20. Use absl::weak_ordering for a three-way comparator in test-instance-tracker.h. PiperOrigin-RevId: 247290078 -- 70a762f4eb35ea1d5a5fcb3274a8086824a0b82c by Derek Mauro <dmauro@google.com>: Upgrade linux_clang-latest builds to LLVM r356814 and Bazel 0.25.0 PiperOrigin-RevId: 247250176 -- f305cd5c36561e4dbb69eb87568553ae5badcb15 by CJ Johnson <johnsoncj@google.com>: Remove argument deduction based on template template argument in InlinedVector/Storage PiperOrigin-RevId: 247232334 -- 2cab8e426838baceb7d08edb313416480d26aa5b by Eric Fiselier <ericwf@google.com>: Import of CCTZ from GitHub. PiperOrigin-RevId: 247140132 GitOrigin-RevId: 9fa04b5fb4b6aeb47226b9095b3bc36a53669c39 Change-Id: I373a7d9bc90befa2a9f06555cb8703610c0313b9
Diffstat (limited to 'absl/time/internal/cctz/include')
-rw-r--r-- | absl/time/internal/cctz/include/cctz/civil_time_detail.h | 38 |
1 files changed, 34 insertions, 4 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 bb191b3faee5..3e2434033935 100644 --- a/absl/time/internal/cctz/include/cctz/civil_time_detail.h +++ b/absl/time/internal/cctz/include/cctz/civil_time_detail.h @@ -555,13 +555,43 @@ CONSTEXPR_F weekday get_weekday(const civil_day& cd) noexcept { //////////////////////////////////////////////////////////////////////// CONSTEXPR_F civil_day next_weekday(civil_day cd, weekday wd) noexcept { - do { cd += 1; } while (get_weekday(cd) != wd); - return cd; + CONSTEXPR_D weekday k_weekdays_forw[14] = { + weekday::monday, weekday::tuesday, weekday::wednesday, + weekday::thursday, weekday::friday, weekday::saturday, + weekday::sunday, weekday::monday, weekday::tuesday, + weekday::wednesday, weekday::thursday, weekday::friday, + weekday::saturday, weekday::sunday, + }; + weekday base = get_weekday(cd); + for (int i = 0;; ++i) { + if (base == k_weekdays_forw[i]) { + for (int j = i + 1;; ++j) { + if (wd == k_weekdays_forw[j]) { + return cd + (j - i); + } + } + } + } } CONSTEXPR_F civil_day prev_weekday(civil_day cd, weekday wd) noexcept { - do { cd -= 1; } while (get_weekday(cd) != wd); - return cd; + CONSTEXPR_D weekday k_weekdays_back[14] = { + weekday::sunday, weekday::saturday, weekday::friday, + weekday::thursday, weekday::wednesday, weekday::tuesday, + weekday::monday, weekday::sunday, weekday::saturday, + weekday::friday, weekday::thursday, weekday::wednesday, + weekday::tuesday, weekday::monday, + }; + weekday base = get_weekday(cd); + for (int i = 0;; ++i) { + if (base == k_weekdays_back[i]) { + for (int j = i + 1;; ++j) { + if (wd == k_weekdays_back[j]) { + return cd - (j - i); + } + } + } + } } CONSTEXPR_F int get_yearday(const civil_day& cd) noexcept { |