diff options
author | Abseil Team <absl-team@google.com> | 2019-12-14 08:24:07 -0800 |
---|---|---|
committer | CJ Johnson <johnsoncj@google.com> | 2019-12-16 15:25:20 -0500 |
commit | bf86cfe165ef7d70dfe68f0b8fc0c018bc79a577 (patch) | |
tree | 2b1ec2a8f3464f3e1ea0e2c2296c5752428f1024 /absl/time/internal/cctz/include | |
parent | 12bc53e0318d80569270a5b26ccbc62b52022b89 (diff) |
Export of internal Abseil changes
--
20b3acaff75d05315f272747956b01405adccafb by Greg Falcon <gfalcon@google.com>:
Re-import of CCTZ from GitHub, with new ABSL_NAMESPACE_ transform applied.
PiperOrigin-RevId: 285564474
--
4d9e3fcabcea33c8b0b69f094ad2eddc0fa19557 by Derek Mauro <dmauro@google.com>:
Moves the disabling of a warning to before the function begins.
MSVC apparently requires this for warnings in the range 4700-4999.
https://docs.microsoft.com/en-us/cpp/preprocessor/warning?redirectedfrom=MSDN&view=vs-2019
PiperOrigin-RevId: 285516232
--
4a060cbeda76e89693c50276ae5b62cbf0fff39a by Derek Mauro <dmauro@google.com>:
MSVC: Fixes uniform_real_distribution_test in opt mode
Disables a constant arithmetic overflow warning in a test that tests
the behavior on overflow. This should be tested because a user might
have this warning disabled.
PiperOrigin-RevId: 285452242
--
548ab2f4cbe59bd6f6bf493af4f9ea765c4fa949 by Andy Soffer <asoffer@google.com>:
Release absl::bind_front, a C++11-compliant work-alike type for the C++20
std::bind_front.
PiperOrigin-RevId: 285247872
GitOrigin-RevId: 20b3acaff75d05315f272747956b01405adccafb
Change-Id: I00fe45939246cba9bfc7be375d67787d2eb57cd3
Diffstat (limited to 'absl/time/internal/cctz/include')
4 files changed, 52 insertions, 46 deletions
diff --git a/absl/time/internal/cctz/include/cctz/civil_time.h b/absl/time/internal/cctz/include/cctz/civil_time.h index 19b311bb..d47ff86f 100644 --- a/absl/time/internal/cctz/include/cctz/civil_time.h +++ b/absl/time/internal/cctz/include/cctz/civil_time.h @@ -15,9 +15,11 @@ #ifndef ABSL_TIME_INTERNAL_CCTZ_CIVIL_TIME_H_ #define ABSL_TIME_INTERNAL_CCTZ_CIVIL_TIME_H_ +#include "absl/base/config.h" #include "absl/time/internal/cctz/include/cctz/civil_time_detail.h" namespace absl { +ABSL_NAMESPACE_BEGIN namespace time_internal { namespace cctz { @@ -324,6 +326,7 @@ using detail::get_yearday; } // namespace cctz } // namespace time_internal +ABSL_NAMESPACE_END } // namespace absl #endif // ABSL_TIME_INTERNAL_CCTZ_CIVIL_TIME_H_ 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 433078a7..4cde96f1 100644 --- a/absl/time/internal/cctz/include/cctz/civil_time_detail.h +++ b/absl/time/internal/cctz/include/cctz/civil_time_detail.h @@ -20,6 +20,8 @@ #include <ostream> #include <type_traits> +#include "absl/base/config.h" + // Disable constexpr support unless we are in C++14 mode. #if __cpp_constexpr >= 201304 || (defined(_MSC_VER) && _MSC_VER >= 1910) #define CONSTEXPR_D constexpr // data @@ -32,6 +34,7 @@ #endif namespace absl { +ABSL_NAMESPACE_BEGIN namespace time_internal { namespace cctz { @@ -53,8 +56,8 @@ using second_t = std::int_fast8_t; // [0:59] // Normalized civil-time fields: Y-M-D HH:MM:SS. struct fields { - CONSTEXPR_M fields(year_t year, month_t month, day_t day, - hour_t hour, minute_t minute, second_t second) + CONSTEXPR_M fields(year_t year, month_t month, day_t day, hour_t hour, + minute_t minute, second_t second) : y(year), m(month), d(day), hh(hour), mm(minute), ss(second) {} std::int_least64_t y; std::int_least8_t m; @@ -101,8 +104,8 @@ CONSTEXPR_F int days_per_month(year_t y, month_t m) noexcept { return k_days_per_month[m] + (m == 2 && is_leap_year(y)); } -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 { +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; cd %= 146097; if (cd < 0) { @@ -152,8 +155,8 @@ CONSTEXPR_F fields n_day(year_t y, month_t m, diff_t d, diff_t cd, } return fields(y, 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 { +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 { if (m != 12) { y += m / 12; m %= 12; @@ -164,8 +167,8 @@ CONSTEXPR_F fields n_mon(year_t y, diff_t m, diff_t d, diff_t cd, } return n_day(y, static_cast<month_t>(m), d, cd, hh, mm, ss); } -CONSTEXPR_F fields n_hour(year_t y, diff_t m, diff_t d, diff_t cd, - diff_t hh, minute_t mm, second_t ss) noexcept { +CONSTEXPR_F fields n_hour(year_t y, diff_t m, diff_t d, diff_t cd, diff_t hh, + minute_t mm, second_t ss) noexcept { cd += hh / 24; hh %= 24; if (hh < 0) { @@ -264,8 +267,8 @@ CONSTEXPR_F diff_t ymd_ord(year_t y, month_t m, day_t d) noexcept { // yet the difference between two such extreme values may actually be // small, so we take a little care to avoid overflow when possible by // exploiting the 146097-day cycle. -CONSTEXPR_F diff_t day_difference(year_t y1, month_t m1, day_t d1, - year_t y2, month_t m2, day_t d2) noexcept { +CONSTEXPR_F diff_t day_difference(year_t y1, month_t m1, day_t d1, year_t y2, + month_t m2, day_t d2) noexcept { const diff_t a_c4_off = y1 % 400; const diff_t b_c4_off = y2 % 400; diff_t c4_diff = (y1 - a_c4_off) - (y2 - b_c4_off); @@ -305,9 +308,7 @@ CONSTEXPR_F diff_t difference(second_tag, fields f1, fields f2) noexcept { //////////////////////////////////////////////////////////////////////// // Aligns the (normalized) fields struct to the indicated field. -CONSTEXPR_F fields align(second_tag, fields f) noexcept { - return f; -} +CONSTEXPR_F fields align(second_tag, fields f) noexcept { return f; } CONSTEXPR_F fields align(minute_tag, fields f) noexcept { return fields{f.y, f.m, f.d, f.hh, f.mm, 0}; } @@ -386,11 +387,11 @@ class civil_time { : civil_time(ct.f_) {} // Factories for the maximum/minimum representable civil_time. - static CONSTEXPR_F civil_time (max)() { + static CONSTEXPR_F civil_time(max)() { const auto max_year = (std::numeric_limits<std::int_least64_t>::max)(); return civil_time(max_year, 12, 31, 23, 59, 59); } - static CONSTEXPR_F civil_time (min)() { + static CONSTEXPR_F civil_time(min)() { const auto min_year = (std::numeric_limits<std::int_least64_t>::min)(); return civil_time(min_year, 1, 1, 0, 0, 0); } @@ -416,17 +417,13 @@ class civil_time { } return *this; } - CONSTEXPR_M civil_time& operator++() noexcept { - return *this += 1; - } + CONSTEXPR_M civil_time& operator++() noexcept { return *this += 1; } CONSTEXPR_M civil_time operator++(int) noexcept { const civil_time a = *this; ++*this; return a; } - CONSTEXPR_M civil_time& operator--() noexcept { - return *this -= 1; - } + CONSTEXPR_M civil_time& operator--() noexcept { return *this -= 1; } CONSTEXPR_M civil_time operator--(int) noexcept { const civil_time a = *this; --*this; @@ -483,17 +480,17 @@ using civil_second = civil_time<second_tag>; template <typename T1, typename T2> CONSTEXPR_F bool operator<(const civil_time<T1>& lhs, const civil_time<T2>& rhs) noexcept { - return (lhs.year() < rhs.year() || - (lhs.year() == rhs.year() && - (lhs.month() < rhs.month() || - (lhs.month() == rhs.month() && - (lhs.day() < rhs.day() || - (lhs.day() == rhs.day() && - (lhs.hour() < rhs.hour() || - (lhs.hour() == rhs.hour() && - (lhs.minute() < rhs.minute() || - (lhs.minute() == rhs.minute() && - (lhs.second() < rhs.second()))))))))))); + return ( + lhs.year() < rhs.year() || + (lhs.year() == rhs.year() && + (lhs.month() < rhs.month() || + (lhs.month() == rhs.month() && + (lhs.day() < rhs.day() || (lhs.day() == rhs.day() && + (lhs.hour() < rhs.hour() || + (lhs.hour() == rhs.hour() && + (lhs.minute() < rhs.minute() || + (lhs.minute() == rhs.minute() && + (lhs.second() < rhs.second()))))))))))); } template <typename T1, typename T2> CONSTEXPR_F bool operator<=(const civil_time<T1>& lhs, @@ -615,6 +612,7 @@ std::ostream& operator<<(std::ostream& os, weekday wd); } // namespace detail } // namespace cctz } // namespace time_internal +ABSL_NAMESPACE_END } // namespace absl #undef CONSTEXPR_M diff --git a/absl/time/internal/cctz/include/cctz/time_zone.h b/absl/time/internal/cctz/include/cctz/time_zone.h index ef6c4ba1..d05147a1 100644 --- a/absl/time/internal/cctz/include/cctz/time_zone.h +++ b/absl/time/internal/cctz/include/cctz/time_zone.h @@ -25,9 +25,11 @@ #include <string> #include <utility> +#include "absl/base/config.h" #include "absl/time/internal/cctz/include/cctz/civil_time.h" namespace absl { +ABSL_NAMESPACE_BEGIN namespace time_internal { namespace cctz { @@ -39,8 +41,8 @@ using sys_seconds = seconds; // Deprecated. Use cctz::seconds instead. namespace detail { template <typename D> -inline std::pair<time_point<seconds>, D> -split_seconds(const time_point<D>& tp) { +inline std::pair<time_point<seconds>, D> split_seconds( + const time_point<D>& tp) { auto sec = std::chrono::time_point_cast<seconds>(tp); auto sub = tp - sec; if (sub.count() < 0) { @@ -49,8 +51,8 @@ split_seconds(const time_point<D>& tp) { } return {sec, std::chrono::duration_cast<D>(sub)}; } -inline std::pair<time_point<seconds>, seconds> -split_seconds(const time_point<seconds>& tp) { +inline std::pair<time_point<seconds>, seconds> split_seconds( + const time_point<seconds>& tp) { return {tp, seconds::zero()}; } } // namespace detail @@ -194,15 +196,13 @@ class time_zone { bool next_transition(const time_point<seconds>& tp, civil_transition* trans) const; template <typename D> - bool next_transition(const time_point<D>& tp, - civil_transition* trans) const { + bool next_transition(const time_point<D>& tp, civil_transition* trans) const { return next_transition(detail::split_seconds(tp).first, trans); } bool prev_transition(const time_point<seconds>& tp, civil_transition* trans) const; template <typename D> - bool prev_transition(const time_point<D>& tp, - civil_transition* trans) const { + bool prev_transition(const time_point<D>& tp, civil_transition* trans) const { return prev_transition(detail::split_seconds(tp).first, trans); } @@ -220,9 +220,7 @@ class time_zone { friend bool operator==(time_zone lhs, time_zone rhs) { return &lhs.effective_impl() == &rhs.effective_impl(); } - friend bool operator!=(time_zone lhs, time_zone rhs) { - return !(lhs == rhs); - } + friend bool operator!=(time_zone lhs, time_zone rhs) { return !(lhs == rhs); } template <typename H> friend H AbslHashValue(H h, time_zone tz) { @@ -380,6 +378,7 @@ inline bool parse(const std::string& fmt, const std::string& input, } // namespace cctz } // namespace time_internal +ABSL_NAMESPACE_END } // namespace absl #endif // ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_H_ diff --git a/absl/time/internal/cctz/include/cctz/zone_info_source.h b/absl/time/internal/cctz/include/cctz/zone_info_source.h index 2b898d18..912b44ba 100644 --- a/absl/time/internal/cctz/include/cctz/zone_info_source.h +++ b/absl/time/internal/cctz/include/cctz/zone_info_source.h @@ -20,7 +20,10 @@ #include <memory> #include <string> +#include "absl/base/config.h" + namespace absl { +ABSL_NAMESPACE_BEGIN namespace time_internal { namespace cctz { @@ -30,7 +33,7 @@ class ZoneInfoSource { virtual ~ZoneInfoSource(); virtual std::size_t Read(void* ptr, std::size_t size) = 0; // like fread() - virtual int Skip(std::size_t offset) = 0; // like fseek() + virtual int Skip(std::size_t offset) = 0; // like fseek() // Until the zoneinfo data supports versioning information, we provide // a way for a ZoneInfoSource to indicate it out-of-band. The default @@ -40,9 +43,11 @@ class ZoneInfoSource { } // namespace cctz } // namespace time_internal +ABSL_NAMESPACE_END } // namespace absl namespace absl { +ABSL_NAMESPACE_BEGIN namespace time_internal { namespace cctz_extension { @@ -52,8 +57,8 @@ namespace cctz_extension { using ZoneInfoSourceFactory = std::unique_ptr<absl::time_internal::cctz::ZoneInfoSource> (*)( const std::string&, - const std::function<std::unique_ptr<absl::time_internal::cctz::ZoneInfoSource>( - const std::string&)>&); + const std::function<std::unique_ptr< + absl::time_internal::cctz::ZoneInfoSource>(const std::string&)>&); // The user can control the mapping of zone names to zoneinfo data by // providing a definition for cctz_extension::zone_info_source_factory. @@ -91,6 +96,7 @@ extern ZoneInfoSourceFactory zone_info_source_factory; } // namespace cctz_extension } // namespace time_internal +ABSL_NAMESPACE_END } // namespace absl #endif // ABSL_TIME_INTERNAL_CCTZ_ZONE_INFO_SOURCE_H_ |