From fb462224c058487763f263b7995d70efd0242c17 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Wed, 5 Sep 2018 10:20:22 -0700 Subject: Export of internal Abseil changes. -- 86b1c997fac1f77b0eacfab788659b5a89a6096e by Abseil Team : Import of CCTZ from GitHub. PiperOrigin-RevId: 211654320 -- 299b70e1247df768454a76eb957a184de9706f61 by Chris Kennelly : Avoid creating a misaligned reference to int. PiperOrigin-RevId: 211505883 -- c8fad4357ad0bfb3c5ad197c505509bc087072c9 by Abseil Team : Import of CCTZ from GitHub. PiperOrigin-RevId: 211458539 -- 0613feffcd36466c3e53a50758d7e8f17c001dce by Greg Falcon : Refactor a string unit test into a template function for internal purposes. PiperOrigin-RevId: 211100748 GitOrigin-RevId: 86b1c997fac1f77b0eacfab788659b5a89a6096e Change-Id: Ic6a932b6c27c6762dcdb3b0127f1e2be782418c1 --- .../internal/cctz/include/cctz/civil_time_detail.h | 8 +--- absl/time/internal/cctz/src/cctz_benchmark.cc | 50 +++++++++++----------- absl/time/internal/cctz/src/time_zone_format.cc | 2 +- .../internal/cctz/src/time_zone_format_test.cc | 8 ++-- 4 files changed, 32 insertions(+), 36 deletions(-) (limited to 'absl/time/internal') 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 f831258f20e2..5fe0967f5b24 100644 --- a/absl/time/internal/cctz/include/cctz/civil_time_detail.h +++ b/absl/time/internal/cctz/include/cctz/civil_time_detail.h @@ -508,12 +508,8 @@ CONSTEXPR_F weekday get_weekday(const civil_day& cd) noexcept { CONSTEXPR_D int k_weekday_offsets[1 + 12] = { -1, 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4, }; - year_t wd = cd.year() - (cd.month() < 3); - if (wd >= 0) { - wd += wd / 4 - wd / 100 + wd / 400; - } else { - wd += (wd - 3) / 4 - (wd - 99) / 100 + (wd - 399) / 400; - } + year_t wd = 2400 + (cd.year() % 400) - (cd.month() < 3); + wd += wd / 4 - wd / 100 + wd / 400; wd += k_weekday_offsets[cd.month()] + cd.day(); return k_weekday_by_sun_off[(wd % 7 + 7) % 7]; } diff --git a/absl/time/internal/cctz/src/cctz_benchmark.cc b/absl/time/internal/cctz/src/cctz_benchmark.cc index c97df78c09c8..4498d7d0b6b7 100644 --- a/absl/time/internal/cctz/src/cctz_benchmark.cc +++ b/absl/time/internal/cctz/src/cctz_benchmark.cc @@ -778,13 +778,13 @@ void BM_Zone_UTCTimeZone(benchmark::State& state) { } BENCHMARK(BM_Zone_UTCTimeZone); -// In each "ToDateTime" benchmark we switch between two instants -// separated by at least one transition in order to defeat any -// internal caching of previous results (e.g., see local_time_hint_). +// In each "ToCivil" benchmark we switch between two instants separated +// by at least one transition in order to defeat any internal caching of +// previous results (e.g., see local_time_hint_). // // The "UTC" variants use UTC instead of the Google/local time zone. -void BM_Time_ToDateTime_CCTZ(benchmark::State& state) { +void BM_Time_ToCivil_CCTZ(benchmark::State& state) { const cctz::time_zone tz = TestTimeZone(); std::chrono::system_clock::time_point tp = std::chrono::system_clock::from_time_t(1384569027); @@ -796,9 +796,9 @@ void BM_Time_ToDateTime_CCTZ(benchmark::State& state) { benchmark::DoNotOptimize(cctz::convert(tp, tz)); } } -BENCHMARK(BM_Time_ToDateTime_CCTZ); +BENCHMARK(BM_Time_ToCivil_CCTZ); -void BM_Time_ToDateTime_Libc(benchmark::State& state) { +void BM_Time_ToCivil_Libc(benchmark::State& state) { // No timezone support, so just use localtime. time_t t = 1384569027; time_t t2 = 1418962578; @@ -813,9 +813,9 @@ void BM_Time_ToDateTime_Libc(benchmark::State& state) { #endif } } -BENCHMARK(BM_Time_ToDateTime_Libc); +BENCHMARK(BM_Time_ToCivil_Libc); -void BM_Time_ToDateTimeUTC_CCTZ(benchmark::State& state) { +void BM_Time_ToCivilUTC_CCTZ(benchmark::State& state) { const cctz::time_zone tz = cctz::utc_time_zone(); std::chrono::system_clock::time_point tp = std::chrono::system_clock::from_time_t(1384569027); @@ -824,9 +824,9 @@ void BM_Time_ToDateTimeUTC_CCTZ(benchmark::State& state) { benchmark::DoNotOptimize(cctz::convert(tp, tz)); } } -BENCHMARK(BM_Time_ToDateTimeUTC_CCTZ); +BENCHMARK(BM_Time_ToCivilUTC_CCTZ); -void BM_Time_ToDateTimeUTC_Libc(benchmark::State& state) { +void BM_Time_ToCivilUTC_Libc(benchmark::State& state) { time_t t = 1384569027; struct tm tm; while (state.KeepRunning()) { @@ -838,16 +838,16 @@ void BM_Time_ToDateTimeUTC_Libc(benchmark::State& state) { #endif } } -BENCHMARK(BM_Time_ToDateTimeUTC_Libc); +BENCHMARK(BM_Time_ToCivilUTC_Libc); -// In each "FromDateTime" benchmark we switch between two YMDhms -// values separated by at least one transition in order to defeat any -// internal caching of previous results (e.g., see time_local_hint_). +// In each "FromCivil" benchmark we switch between two YMDhms values +// separated by at least one transition in order to defeat any internal +// caching of previous results (e.g., see time_local_hint_). // // The "UTC" variants use UTC instead of the Google/local time zone. // The "Day0" variants require normalization of the day of month. -void BM_Time_FromDateTime_CCTZ(benchmark::State& state) { +void BM_Time_FromCivil_CCTZ(benchmark::State& state) { const cctz::time_zone tz = TestTimeZone(); int i = 0; while (state.KeepRunning()) { @@ -860,9 +860,9 @@ void BM_Time_FromDateTime_CCTZ(benchmark::State& state) { } } } -BENCHMARK(BM_Time_FromDateTime_CCTZ); +BENCHMARK(BM_Time_FromCivil_CCTZ); -void BM_Time_FromDateTime_Libc(benchmark::State& state) { +void BM_Time_FromCivil_Libc(benchmark::State& state) { // No timezone support, so just use localtime. int i = 0; while (state.KeepRunning()) { @@ -886,20 +886,20 @@ void BM_Time_FromDateTime_Libc(benchmark::State& state) { benchmark::DoNotOptimize(mktime(&tm)); } } -BENCHMARK(BM_Time_FromDateTime_Libc); +BENCHMARK(BM_Time_FromCivil_Libc); -void BM_Time_FromDateTimeUTC_CCTZ(benchmark::State& state) { +void BM_Time_FromCivilUTC_CCTZ(benchmark::State& state) { const cctz::time_zone tz = cctz::utc_time_zone(); while (state.KeepRunning()) { benchmark::DoNotOptimize( cctz::convert(cctz::civil_second(2014, 12, 18, 20, 16, 18), tz)); } } -BENCHMARK(BM_Time_FromDateTimeUTC_CCTZ); +BENCHMARK(BM_Time_FromCivilUTC_CCTZ); -// There is no BM_Time_FromDateTimeUTC_Libc. +// There is no BM_Time_FromCivilUTC_Libc. -void BM_Time_FromDateTimeDay0_CCTZ(benchmark::State& state) { +void BM_Time_FromCivilDay0_CCTZ(benchmark::State& state) { const cctz::time_zone tz = TestTimeZone(); int i = 0; while (state.KeepRunning()) { @@ -912,9 +912,9 @@ void BM_Time_FromDateTimeDay0_CCTZ(benchmark::State& state) { } } } -BENCHMARK(BM_Time_FromDateTimeDay0_CCTZ); +BENCHMARK(BM_Time_FromCivilDay0_CCTZ); -void BM_Time_FromDateTimeDay0_Libc(benchmark::State& state) { +void BM_Time_FromCivilDay0_Libc(benchmark::State& state) { // No timezone support, so just use localtime. int i = 0; while (state.KeepRunning()) { @@ -938,7 +938,7 @@ void BM_Time_FromDateTimeDay0_Libc(benchmark::State& state) { benchmark::DoNotOptimize(mktime(&tm)); } } -BENCHMARK(BM_Time_FromDateTimeDay0_Libc); +BENCHMARK(BM_Time_FromCivilDay0_Libc); const char* const kFormats[] = { RFC1123_full, // 0 diff --git a/absl/time/internal/cctz/src/time_zone_format.cc b/absl/time/internal/cctz/src/time_zone_format.cc index d9714092466a..a02b1e341ac0 100644 --- a/absl/time/internal/cctz/src/time_zone_format.cc +++ b/absl/time/internal/cctz/src/time_zone_format.cc @@ -743,7 +743,7 @@ bool parse(const std::string& format, const std::string& input, data = ParseTM(data, spec.c_str(), &tm); // If we successfully parsed %p we need to remember whether the result - // was AM or PM so that we can adjust tm_hour before ConvertDateTime(). + // was AM or PM so that we can adjust tm_hour before time_zone::lookup(). // So reparse the input with a known AM hour, and check if it is shifted // to a PM hour. if (spec == "%p" && data != nullptr) { diff --git a/absl/time/internal/cctz/src/time_zone_format_test.cc b/absl/time/internal/cctz/src/time_zone_format_test.cc index a90dda7603a8..6b9928ed32f4 100644 --- a/absl/time/internal/cctz/src/time_zone_format_test.cc +++ b/absl/time/internal/cctz/src/time_zone_format_test.cc @@ -669,13 +669,13 @@ TEST(Parse, WithTimeZone) { utc_time_zone(), &tp)); ExpectTime(tp, tz, 2013, 6, 28, 19 - 8 - 7, 8, 9, -7 * 60 * 60, true, "PDT"); - // Check a skipped time (a Spring DST transition). parse() returns - // the preferred-offset result, as defined for ConvertDateTime(). + // Check a skipped time (a Spring DST transition). parse() uses the + // pre-transition offset. EXPECT_TRUE(parse("%Y-%m-%d %H:%M:%S", "2011-03-13 02:15:00", tz, &tp)); ExpectTime(tp, tz, 2011, 3, 13, 3, 15, 0, -7 * 60 * 60, true, "PDT"); - // Check a repeated time (a Fall DST transition). parse() returns - // the preferred-offset result, as defined for ConvertDateTime(). + // Check a repeated time (a Fall DST transition). parse() uses the + // pre-transition offset. EXPECT_TRUE(parse("%Y-%m-%d %H:%M:%S", "2011-11-06 01:15:00", tz, &tp)); ExpectTime(tp, tz, 2011, 11, 6, 1, 15, 0, -7 * 60 * 60, true, "PDT"); } -- cgit 1.4.1