diff options
Diffstat (limited to 'absl/time')
27 files changed, 341 insertions, 179 deletions
diff --git a/absl/time/BUILD.bazel b/absl/time/BUILD.bazel index e3fe705b..05f1f2f2 100644 --- a/absl/time/BUILD.bazel +++ b/absl/time/BUILD.bazel @@ -65,7 +65,7 @@ cc_library( cc_library( name = "test_util", - testonly = 1, + testonly = True, srcs = ["internal/test_util.cc"], hdrs = ["internal/test_util.h"], copts = ABSL_DEFAULT_COPTS, diff --git a/absl/time/CMakeLists.txt b/absl/time/CMakeLists.txt index e1ade7a3..fe625f28 100644 --- a/absl/time/CMakeLists.txt +++ b/absl/time/CMakeLists.txt @@ -83,7 +83,7 @@ absl_cc_library( Threads::Threads # TODO(#1495): Use $<LINK_LIBRARY:FRAMEWORK,CoreFoundation> once our # minimum CMake version >= 3.24 - $<$<PLATFORM_ID:Darwin>:-Wl,-framework,CoreFoundation> + $<$<PLATFORM_ID:Darwin,iOS,tvOS,visionOS,watchOS>:-Wl,-framework,CoreFoundation> ) # Internal-only target, do not depend on directly. diff --git a/absl/time/civil_time.h b/absl/time/civil_time.h index 3e904a11..d198ebae 100644 --- a/absl/time/civil_time.h +++ b/absl/time/civil_time.h @@ -55,7 +55,7 @@ // Example: // // // Construct a civil-time object for a specific day -// const absl::CivilDay cd(1969, 07, 20); +// const absl::CivilDay cd(1969, 7, 20); // // // Construct a civil-time object for a specific second // const absl::CivilSecond cd(2018, 8, 1, 12, 0, 1); @@ -65,7 +65,7 @@ // Example: // // // Valid in C++14 -// constexpr absl::CivilDay cd(1969, 07, 20); +// constexpr absl::CivilDay cd(1969, 7, 20); #ifndef ABSL_TIME_CIVIL_TIME_H_ #define ABSL_TIME_CIVIL_TIME_H_ diff --git a/absl/time/clock.cc b/absl/time/clock.cc index aa74367b..ecd539e5 100644 --- a/absl/time/clock.cc +++ b/absl/time/clock.cc @@ -88,11 +88,25 @@ ABSL_NAMESPACE_END namespace absl { ABSL_NAMESPACE_BEGIN namespace time_internal { + +// On some processors, consecutive reads of the cycle counter may yield the +// same value (weakly-increasing). In debug mode, clear the least significant +// bits to discourage depending on a strictly-increasing Now() value. +// In x86-64's debug mode, discourage depending on a strictly-increasing Now() +// value. +#if !defined(NDEBUG) && defined(__x86_64__) +constexpr int64_t kCycleClockNowMask = ~int64_t{0xff}; +#else +constexpr int64_t kCycleClockNowMask = ~int64_t{0}; +#endif + // This is a friend wrapper around UnscaledCycleClock::Now() // (needed to access UnscaledCycleClock). class UnscaledCycleClockWrapperForGetCurrentTime { public: - static int64_t Now() { return base_internal::UnscaledCycleClock::Now(); } + static int64_t Now() { + return base_internal::UnscaledCycleClock::Now() & kCycleClockNowMask; + } }; } // namespace time_internal diff --git a/absl/time/duration.cc b/absl/time/duration.cc index bdb16e21..8d0b66f8 100644 --- a/absl/time/duration.cc +++ b/absl/time/duration.cc @@ -219,7 +219,7 @@ struct SafeMultiply { ? static_cast<uint128>(Uint128Low64(a) * Uint128Low64(b)) : a * b; } - return b == 0 ? b : (a > kuint128max / b) ? kuint128max : a * b; + return b == 0 ? b : (a > Uint128Max() / b) ? Uint128Max() : a * b; } }; @@ -280,33 +280,35 @@ inline bool IDivFastPath(const Duration num, const Duration den, int64_t* q, int64_t den_hi = time_internal::GetRepHi(den); uint32_t den_lo = time_internal::GetRepLo(den); - if (den_hi == 0 && den_lo == kTicksPerNanosecond) { - // Dividing by 1ns - if (num_hi >= 0 && num_hi < (kint64max - kTicksPerSecond) / 1000000000) { - *q = num_hi * 1000000000 + num_lo / kTicksPerNanosecond; - *rem = time_internal::MakeDuration(0, num_lo % den_lo); - return true; - } - } else if (den_hi == 0 && den_lo == 100 * kTicksPerNanosecond) { - // Dividing by 100ns (common when converting to Universal time) - if (num_hi >= 0 && num_hi < (kint64max - kTicksPerSecond) / 10000000) { - *q = num_hi * 10000000 + num_lo / (100 * kTicksPerNanosecond); - *rem = time_internal::MakeDuration(0, num_lo % den_lo); - return true; - } - } else if (den_hi == 0 && den_lo == 1000 * kTicksPerNanosecond) { - // Dividing by 1us - if (num_hi >= 0 && num_hi < (kint64max - kTicksPerSecond) / 1000000) { - *q = num_hi * 1000000 + num_lo / (1000 * kTicksPerNanosecond); - *rem = time_internal::MakeDuration(0, num_lo % den_lo); - return true; - } - } else if (den_hi == 0 && den_lo == 1000000 * kTicksPerNanosecond) { - // Dividing by 1ms - if (num_hi >= 0 && num_hi < (kint64max - kTicksPerSecond) / 1000) { - *q = num_hi * 1000 + num_lo / (1000000 * kTicksPerNanosecond); - *rem = time_internal::MakeDuration(0, num_lo % den_lo); - return true; + if (den_hi == 0) { + if (den_lo == kTicksPerNanosecond) { + // Dividing by 1ns + if (num_hi >= 0 && num_hi < (kint64max - kTicksPerSecond) / 1000000000) { + *q = num_hi * 1000000000 + num_lo / kTicksPerNanosecond; + *rem = time_internal::MakeDuration(0, num_lo % den_lo); + return true; + } + } else if (den_lo == 100 * kTicksPerNanosecond) { + // Dividing by 100ns (common when converting to Universal time) + if (num_hi >= 0 && num_hi < (kint64max - kTicksPerSecond) / 10000000) { + *q = num_hi * 10000000 + num_lo / (100 * kTicksPerNanosecond); + *rem = time_internal::MakeDuration(0, num_lo % den_lo); + return true; + } + } else if (den_lo == 1000 * kTicksPerNanosecond) { + // Dividing by 1us + if (num_hi >= 0 && num_hi < (kint64max - kTicksPerSecond) / 1000000) { + *q = num_hi * 1000000 + num_lo / (1000 * kTicksPerNanosecond); + *rem = time_internal::MakeDuration(0, num_lo % den_lo); + return true; + } + } else if (den_lo == 1000000 * kTicksPerNanosecond) { + // Dividing by 1ms + if (num_hi >= 0 && num_hi < (kint64max - kTicksPerSecond) / 1000) { + *q = num_hi * 1000 + num_lo / (1000000 * kTicksPerNanosecond); + *rem = time_internal::MakeDuration(0, num_lo % den_lo); + return true; + } } } else if (den_hi > 0 && den_lo == 0) { // Dividing by positive multiple of 1s @@ -342,19 +344,10 @@ inline bool IDivFastPath(const Duration num, const Duration den, int64_t* q, } // namespace -namespace time_internal { +namespace { -// The 'satq' argument indicates whether the quotient should saturate at the -// bounds of int64_t. If it does saturate, the difference will spill over to -// the remainder. If it does not saturate, the remainder remain accurate, -// but the returned quotient will over/underflow int64_t and should not be used. -int64_t IDivDuration(bool satq, const Duration num, const Duration den, +int64_t IDivSlowPath(bool satq, const Duration num, const Duration den, Duration* rem) { - int64_t q = 0; - if (IDivFastPath(num, den, &q, rem)) { - return q; - } - const bool num_neg = num < ZeroDuration(); const bool den_neg = den < ZeroDuration(); const bool quotient_neg = num_neg != den_neg; @@ -391,7 +384,27 @@ int64_t IDivDuration(bool satq, const Duration num, const Duration den, return -static_cast<int64_t>(Uint128Low64(quotient128 - 1) & kint64max) - 1; } -} // namespace time_internal +// The 'satq' argument indicates whether the quotient should saturate at the +// bounds of int64_t. If it does saturate, the difference will spill over to +// the remainder. If it does not saturate, the remainder remain accurate, +// but the returned quotient will over/underflow int64_t and should not be used. +ABSL_ATTRIBUTE_ALWAYS_INLINE inline int64_t IDivDurationImpl(bool satq, + const Duration num, + const Duration den, + Duration* rem) { + int64_t q = 0; + if (IDivFastPath(num, den, &q, rem)) { + return q; + } + return IDivSlowPath(satq, num, den, rem); +} + +} // namespace + +int64_t IDivDuration(Duration num, Duration den, Duration* rem) { + return IDivDurationImpl(true, num, den, + rem); // trunc towards zero +} // // Additive operators. @@ -475,7 +488,7 @@ Duration& Duration::operator/=(double r) { } Duration& Duration::operator%=(Duration rhs) { - time_internal::IDivDuration(false, *this, rhs, this); + IDivDurationImpl(false, *this, rhs, this); return *this; } @@ -501,9 +514,7 @@ double FDivDuration(Duration num, Duration den) { // Trunc/Floor/Ceil. // -Duration Trunc(Duration d, Duration unit) { - return d - (d % unit); -} +Duration Trunc(Duration d, Duration unit) { return d - (d % unit); } Duration Floor(const Duration d, const Duration unit) { const absl::Duration td = Trunc(d, unit); @@ -591,15 +602,9 @@ double ToDoubleMicroseconds(Duration d) { double ToDoubleMilliseconds(Duration d) { return FDivDuration(d, Milliseconds(1)); } -double ToDoubleSeconds(Duration d) { - return FDivDuration(d, Seconds(1)); -} -double ToDoubleMinutes(Duration d) { - return FDivDuration(d, Minutes(1)); -} -double ToDoubleHours(Duration d) { - return FDivDuration(d, Hours(1)); -} +double ToDoubleSeconds(Duration d) { return FDivDuration(d, Seconds(1)); } +double ToDoubleMinutes(Duration d) { return FDivDuration(d, Minutes(1)); } +double ToDoubleHours(Duration d) { return FDivDuration(d, Hours(1)); } timespec ToTimespec(Duration d) { timespec ts; diff --git a/absl/time/duration_benchmark.cc b/absl/time/duration_benchmark.cc index 56820f37..fdb26bb3 100644 --- a/absl/time/duration_benchmark.cc +++ b/absl/time/duration_benchmark.cc @@ -290,6 +290,26 @@ void BM_Duration_IDivDuration_Hours(benchmark::State& state) { } BENCHMARK(BM_Duration_IDivDuration_Hours); +void BM_Duration_Modulo(benchmark::State& state) { + int i = 0; + while (state.KeepRunning()) { + auto mod = absl::Seconds(i) % absl::Nanoseconds(12345); + benchmark::DoNotOptimize(mod); + ++i; + } +} +BENCHMARK(BM_Duration_Modulo); + +void BM_Duration_Modulo_FastPath(benchmark::State& state) { + int i = 0; + while (state.KeepRunning()) { + auto mod = absl::Seconds(i) % absl::Milliseconds(1); + benchmark::DoNotOptimize(mod); + ++i; + } +} +BENCHMARK(BM_Duration_Modulo_FastPath); + void BM_Duration_ToInt64Nanoseconds(benchmark::State& state) { absl::Duration d = absl::Seconds(100000); while (state.KeepRunning()) { diff --git a/absl/time/duration_test.cc b/absl/time/duration_test.cc index dcf7aad6..4c801a8d 100644 --- a/absl/time/duration_test.cc +++ b/absl/time/duration_test.cc @@ -19,6 +19,11 @@ #include <array> #include <cfloat> #include <chrono> // NOLINT(build/c++11) + +#ifdef __cpp_impl_three_way_comparison +#include <compare> +#endif // __cpp_impl_three_way_comparison + #include <cmath> #include <cstdint> #include <ctime> @@ -431,6 +436,15 @@ TEST(Duration, InfinityComparison) { EXPECT_LT(-inf, any_dur); EXPECT_LT(-inf, inf); EXPECT_GT(inf, -inf); + +#ifdef __cpp_impl_three_way_comparison + EXPECT_EQ(inf <=> inf, std::strong_ordering::equal); + EXPECT_EQ(-inf <=> -inf, std::strong_ordering::equal); + EXPECT_EQ(-inf <=> inf, std::strong_ordering::less); + EXPECT_EQ(inf <=> -inf, std::strong_ordering::greater); + EXPECT_EQ(any_dur <=> inf, std::strong_ordering::less); + EXPECT_EQ(any_dur <=> -inf, std::strong_ordering::greater); +#endif // __cpp_impl_three_way_comparison } TEST(Duration, InfinityAddition) { @@ -496,9 +510,20 @@ TEST(Duration, InfinitySubtraction) { // Interesting case absl::Duration almost_neg_inf = sec_min; EXPECT_LT(-inf, almost_neg_inf); + +#ifdef __cpp_impl_three_way_comparison + EXPECT_EQ(-inf <=> almost_neg_inf, std::strong_ordering::less); + EXPECT_EQ(almost_neg_inf <=> -inf, std::strong_ordering::greater); +#endif // __cpp_impl_three_way_comparison + almost_neg_inf -= -absl::Nanoseconds(1); EXPECT_LT(-inf, almost_neg_inf); +#ifdef __cpp_impl_three_way_comparison + EXPECT_EQ(-inf <=> almost_neg_inf, std::strong_ordering::less); + EXPECT_EQ(almost_neg_inf <=> -inf, std::strong_ordering::greater); +#endif // __cpp_impl_three_way_comparison + // For reference: IEEE 754 behavior const double dbl_inf = std::numeric_limits<double>::infinity(); EXPECT_TRUE(std::isnan(dbl_inf - dbl_inf)); // We return inf @@ -857,6 +882,21 @@ TEST(Duration, Range) { EXPECT_LT(neg_full_range, full_range); EXPECT_EQ(neg_full_range, -full_range); + +#ifdef __cpp_impl_three_way_comparison + EXPECT_EQ(range_future <=> absl::InfiniteDuration(), + std::strong_ordering::less); + EXPECT_EQ(range_past <=> -absl::InfiniteDuration(), + std::strong_ordering::greater); + EXPECT_EQ(full_range <=> absl::ZeroDuration(), // + std::strong_ordering::greater); + EXPECT_EQ(full_range <=> -absl::InfiniteDuration(), + std::strong_ordering::greater); + EXPECT_EQ(neg_full_range <=> -absl::InfiniteDuration(), + std::strong_ordering::greater); + EXPECT_EQ(neg_full_range <=> full_range, std::strong_ordering::less); + EXPECT_EQ(neg_full_range <=> -full_range, std::strong_ordering::equal); +#endif // __cpp_impl_three_way_comparison } TEST(Duration, RelationalOperators) { @@ -880,6 +920,27 @@ TEST(Duration, RelationalOperators) { #undef TEST_REL_OPS } + +#ifdef __cpp_impl_three_way_comparison + +TEST(Duration, SpaceshipOperators) { +#define TEST_REL_OPS(UNIT) \ + static_assert(UNIT(2) <=> UNIT(2) == std::strong_ordering::equal, ""); \ + static_assert(UNIT(1) <=> UNIT(2) == std::strong_ordering::less, ""); \ + static_assert(UNIT(3) <=> UNIT(2) == std::strong_ordering::greater, ""); + + TEST_REL_OPS(absl::Nanoseconds); + TEST_REL_OPS(absl::Microseconds); + TEST_REL_OPS(absl::Milliseconds); + TEST_REL_OPS(absl::Seconds); + TEST_REL_OPS(absl::Minutes); + TEST_REL_OPS(absl::Hours); + +#undef TEST_REL_OPS +} + +#endif // __cpp_impl_three_way_comparison + TEST(Duration, Addition) { #define TEST_ADD_OPS(UNIT) \ do { \ diff --git a/absl/time/format.cc b/absl/time/format.cc index 15a26b14..bd06f8fb 100644 --- a/absl/time/format.cc +++ b/absl/time/format.cc @@ -16,6 +16,7 @@ #include <cctype> #include <cstdint> +#include <utility> #include "absl/strings/match.h" #include "absl/strings/string_view.h" @@ -136,7 +137,7 @@ bool ParseTime(absl::string_view format, absl::string_view input, if (b) { *time = Join(parts); } else if (err != nullptr) { - *err = error; + *err = std::move(error); } return b; } diff --git a/absl/time/internal/cctz/src/time_zone_libc.cc b/absl/time/internal/cctz/src/time_zone_libc.cc index d0146122..b5094027 100644 --- a/absl/time/internal/cctz/src/time_zone_libc.cc +++ b/absl/time/internal/cctz/src/time_zone_libc.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#if defined(_WIN32) || defined(_WIN64) +#if !defined(_CRT_SECURE_NO_WARNINGS) && defined(_WIN32) #define _CRT_SECURE_NO_WARNINGS 1 #endif diff --git a/absl/time/internal/cctz/src/time_zone_lookup.cc b/absl/time/internal/cctz/src/time_zone_lookup.cc index d22691bd..89791745 100644 --- a/absl/time/internal/cctz/src/time_zone_lookup.cc +++ b/absl/time/internal/cctz/src/time_zone_lookup.cc @@ -17,9 +17,6 @@ #if defined(__ANDROID__) #include <sys/system_properties.h> -#if defined(__ANDROID_API__) && __ANDROID_API__ >= 21 -#include <dlfcn.h> -#endif #endif #if defined(__APPLE__) @@ -66,32 +63,6 @@ namespace time_internal { namespace cctz { namespace { -#if defined(__ANDROID__) && defined(__ANDROID_API__) && __ANDROID_API__ >= 21 -// Android 'L' removes __system_property_get() from the NDK, however -// it is still a hidden symbol in libc so we use dlsym() to access it. -// See Chromium's base/sys_info_android.cc for a similar example. - -using property_get_func = int (*)(const char*, char*); - -property_get_func LoadSystemPropertyGet() { - int flag = RTLD_LAZY | RTLD_GLOBAL; -#if defined(RTLD_NOLOAD) - flag |= RTLD_NOLOAD; // libc.so should already be resident -#endif - if (void* handle = dlopen("libc.so", flag)) { - void* sym = dlsym(handle, "__system_property_get"); - dlclose(handle); - return reinterpret_cast<property_get_func>(sym); - } - return nullptr; -} - -int __system_property_get(const char* name, char* value) { - static property_get_func system_property_get = LoadSystemPropertyGet(); - return system_property_get ? system_property_get(name, value) : -1; -} -#endif - #if defined(USE_WIN32_LOCAL_TIME_ZONE) // Calls the WinRT Calendar.GetTimeZone method to obtain the IANA ID of the // local time zone. Returns an empty vector in case of an error. diff --git a/absl/time/internal/cctz/src/tzfile.h b/absl/time/internal/cctz/src/tzfile.h index 114026d0..2be3bb8d 100644 --- a/absl/time/internal/cctz/src/tzfile.h +++ b/absl/time/internal/cctz/src/tzfile.h @@ -77,11 +77,11 @@ struct tzhead { ** time uses 8 rather than 4 chars, ** then a POSIX-TZ-environment-variable-style string for use in handling ** instants after the last transition time stored in the file -** (with nothing between the newlines if there is no POSIX representation for -** such instants). +** (with nothing between the newlines if there is no POSIX.1-2017 +** representation for such instants). ** ** If tz_version is '3' or greater, the above is extended as follows. -** First, the POSIX TZ string's hour offset may range from -167 +** First, the TZ string's hour offset may range from -167 ** through 167 as compared to the POSIX-required 0 through 24. ** Second, its DST start time may be January 1 at 00:00 and its stop ** time December 31 at 24:00 plus the difference between DST and diff --git a/absl/time/internal/cctz/testdata/version b/absl/time/internal/cctz/testdata/version index cd9c3f6d..04fe6744 100644 --- a/absl/time/internal/cctz/testdata/version +++ b/absl/time/internal/cctz/testdata/version @@ -1 +1 @@ -2023d +2024a diff --git a/absl/time/internal/cctz/testdata/zoneinfo/America/Miquelon b/absl/time/internal/cctz/testdata/zoneinfo/America/Miquelon Binary files differindex 3b62585d..ba95cb0b 100644 --- a/absl/time/internal/cctz/testdata/zoneinfo/America/Miquelon +++ b/absl/time/internal/cctz/testdata/zoneinfo/America/Miquelon diff --git a/absl/time/internal/cctz/testdata/zoneinfo/America/Montreal b/absl/time/internal/cctz/testdata/zoneinfo/America/Montreal Binary files differindex fe6be8ea..668e70d7 100644 --- a/absl/time/internal/cctz/testdata/zoneinfo/America/Montreal +++ b/absl/time/internal/cctz/testdata/zoneinfo/America/Montreal diff --git a/absl/time/internal/cctz/testdata/zoneinfo/America/Nipigon b/absl/time/internal/cctz/testdata/zoneinfo/America/Nipigon Binary files differindex fe6be8ea..668e70d7 100644 --- a/absl/time/internal/cctz/testdata/zoneinfo/America/Nipigon +++ b/absl/time/internal/cctz/testdata/zoneinfo/America/Nipigon diff --git a/absl/time/internal/cctz/testdata/zoneinfo/America/Thunder_Bay b/absl/time/internal/cctz/testdata/zoneinfo/America/Thunder_Bay Binary files differindex fe6be8ea..668e70d7 100644 --- a/absl/time/internal/cctz/testdata/zoneinfo/America/Thunder_Bay +++ b/absl/time/internal/cctz/testdata/zoneinfo/America/Thunder_Bay diff --git a/absl/time/internal/cctz/testdata/zoneinfo/America/Toronto b/absl/time/internal/cctz/testdata/zoneinfo/America/Toronto Binary files differindex fe6be8ea..668e70d7 100644 --- a/absl/time/internal/cctz/testdata/zoneinfo/America/Toronto +++ b/absl/time/internal/cctz/testdata/zoneinfo/America/Toronto diff --git a/absl/time/internal/cctz/testdata/zoneinfo/Asia/Almaty b/absl/time/internal/cctz/testdata/zoneinfo/Asia/Almaty Binary files differindex 3ec4fc89..02f047d7 100644 --- a/absl/time/internal/cctz/testdata/zoneinfo/Asia/Almaty +++ b/absl/time/internal/cctz/testdata/zoneinfo/Asia/Almaty diff --git a/absl/time/internal/cctz/testdata/zoneinfo/Asia/Gaza b/absl/time/internal/cctz/testdata/zoneinfo/Asia/Gaza Binary files differindex 6241b4e7..0d796627 100644 --- a/absl/time/internal/cctz/testdata/zoneinfo/Asia/Gaza +++ b/absl/time/internal/cctz/testdata/zoneinfo/Asia/Gaza diff --git a/absl/time/internal/cctz/testdata/zoneinfo/Asia/Hebron b/absl/time/internal/cctz/testdata/zoneinfo/Asia/Hebron Binary files differindex 5267de96..53a3c143 100644 --- a/absl/time/internal/cctz/testdata/zoneinfo/Asia/Hebron +++ b/absl/time/internal/cctz/testdata/zoneinfo/Asia/Hebron diff --git a/absl/time/internal/cctz/testdata/zoneinfo/Asia/Ho_Chi_Minh b/absl/time/internal/cctz/testdata/zoneinfo/Asia/Ho_Chi_Minh Binary files differindex de53596d..86e21b0f 100644 --- a/absl/time/internal/cctz/testdata/zoneinfo/Asia/Ho_Chi_Minh +++ b/absl/time/internal/cctz/testdata/zoneinfo/Asia/Ho_Chi_Minh diff --git a/absl/time/internal/cctz/testdata/zoneinfo/Asia/Qostanay b/absl/time/internal/cctz/testdata/zoneinfo/Asia/Qostanay Binary files differindex ff6fe61d..109fe415 100644 --- a/absl/time/internal/cctz/testdata/zoneinfo/Asia/Qostanay +++ b/absl/time/internal/cctz/testdata/zoneinfo/Asia/Qostanay diff --git a/absl/time/internal/cctz/testdata/zoneinfo/Asia/Saigon b/absl/time/internal/cctz/testdata/zoneinfo/Asia/Saigon Binary files differindex de53596d..86e21b0f 100644 --- a/absl/time/internal/cctz/testdata/zoneinfo/Asia/Saigon +++ b/absl/time/internal/cctz/testdata/zoneinfo/Asia/Saigon diff --git a/absl/time/internal/cctz/testdata/zoneinfo/Canada/Eastern b/absl/time/internal/cctz/testdata/zoneinfo/Canada/Eastern Binary files differindex fe6be8ea..668e70d7 100644 --- a/absl/time/internal/cctz/testdata/zoneinfo/Canada/Eastern +++ b/absl/time/internal/cctz/testdata/zoneinfo/Canada/Eastern diff --git a/absl/time/internal/cctz/testdata/zoneinfo/zonenow.tab b/absl/time/internal/cctz/testdata/zoneinfo/zonenow.tab index 2dbe8f00..b6f29109 100644 --- a/absl/time/internal/cctz/testdata/zoneinfo/zonenow.tab +++ b/absl/time/internal/cctz/testdata/zoneinfo/zonenow.tab @@ -199,7 +199,7 @@ XX +2518+05518 Asia/Dubai Russia; Caucasus; Persian Gulf; Seychelles; RĂ©union XX +3431+06912 Asia/Kabul Afghanistan # # +05 -XX +4120+06918 Asia/Tashkent Russia; Tajikistan; Turkmenistan; Uzbekistan; Maldives +XX +4120+06918 Asia/Tashkent Russia; west Kazakhstan; Tajikistan; Turkmenistan; Uzbekistan; Maldives # # +05 - PKT XX +2452+06703 Asia/Karachi Pakistan ("PKT") @@ -215,6 +215,8 @@ XX +2743+08519 Asia/Kathmandu Nepal # # +06 XX +2343+09025 Asia/Dhaka Russia; Kyrgyzstan; Bhutan; Bangladesh; Chagos +# +06 until 2024-03-01; then +05 +XX +4315+07657 Asia/Almaty Kazakhstan (except western areas) # # +06:30 XX +1647+09610 Asia/Yangon Myanmar; Cocos diff --git a/absl/time/time.h b/absl/time/time.h index 37580805..f133c2d2 100644 --- a/absl/time/time.h +++ b/absl/time/time.h @@ -75,15 +75,22 @@ struct timeval; #endif #include <chrono> // NOLINT(build/c++11) + +#ifdef __cpp_impl_three_way_comparison +#include <compare> +#endif // __cpp_impl_three_way_comparison + #include <cmath> #include <cstdint> #include <ctime> #include <limits> #include <ostream> +#include <ratio> // NOLINT(build/c++11) #include <string> #include <type_traits> #include <utility> +#include "absl/base/attributes.h" #include "absl/base/config.h" #include "absl/base/macros.h" #include "absl/strings/string_view.h" @@ -98,7 +105,6 @@ class Time; // Defined below class TimeZone; // Defined below namespace time_internal { -int64_t IDivDuration(bool satq, Duration num, Duration den, Duration* rem); ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Time FromUnixDuration(Duration d); ABSL_ATTRIBUTE_CONST_FUNCTION constexpr Duration ToUnixDuration(Time t); ABSL_ATTRIBUTE_CONST_FUNCTION constexpr int64_t GetRepHi(Duration d); @@ -306,6 +312,14 @@ class Duration { }; // Relational Operators + +#ifdef __cpp_impl_three_way_comparison + +ABSL_ATTRIBUTE_CONST_FUNCTION constexpr std::strong_ordering operator<=>( + Duration lhs, Duration rhs); + +#endif // __cpp_impl_three_way_comparison + ABSL_ATTRIBUTE_CONST_FUNCTION constexpr bool operator<(Duration lhs, Duration rhs); ABSL_ATTRIBUTE_CONST_FUNCTION constexpr bool operator>(Duration lhs, @@ -338,30 +352,6 @@ ABSL_ATTRIBUTE_CONST_FUNCTION inline Duration operator-(Duration lhs, return lhs -= rhs; } -// Multiplicative Operators -// Integer operands must be representable as int64_t. -template <typename T> -ABSL_ATTRIBUTE_CONST_FUNCTION Duration operator*(Duration lhs, T rhs) { - return lhs *= rhs; -} -template <typename T> -ABSL_ATTRIBUTE_CONST_FUNCTION Duration operator*(T lhs, Duration rhs) { - return rhs *= lhs; -} -template <typename T> -ABSL_ATTRIBUTE_CONST_FUNCTION Duration operator/(Duration lhs, T rhs) { - return lhs /= rhs; -} -ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t operator/(Duration lhs, - Duration rhs) { - return time_internal::IDivDuration(true, lhs, rhs, - &lhs); // trunc towards zero -} -ABSL_ATTRIBUTE_CONST_FUNCTION inline Duration operator%(Duration lhs, - Duration rhs) { - return lhs %= rhs; -} - // IDivDuration() // // Divides a numerator `Duration` by a denominator `Duration`, returning the @@ -390,10 +380,7 @@ ABSL_ATTRIBUTE_CONST_FUNCTION inline Duration operator%(Duration lhs, // // Here, q would overflow int64_t, so rem accounts for the difference. // int64_t q = absl::IDivDuration(a, b, &rem); // // q == std::numeric_limits<int64_t>::max(), rem == a - b * q -inline int64_t IDivDuration(Duration num, Duration den, Duration* rem) { - return time_internal::IDivDuration(true, num, den, - rem); // trunc towards zero -} +int64_t IDivDuration(Duration num, Duration den, Duration* rem); // FDivDuration() // @@ -409,6 +396,30 @@ inline int64_t IDivDuration(Duration num, Duration den, Duration* rem) { // // d == 1.5 ABSL_ATTRIBUTE_CONST_FUNCTION double FDivDuration(Duration num, Duration den); +// Multiplicative Operators +// Integer operands must be representable as int64_t. +template <typename T> +ABSL_ATTRIBUTE_CONST_FUNCTION Duration operator*(Duration lhs, T rhs) { + return lhs *= rhs; +} +template <typename T> +ABSL_ATTRIBUTE_CONST_FUNCTION Duration operator*(T lhs, Duration rhs) { + return rhs *= lhs; +} +template <typename T> +ABSL_ATTRIBUTE_CONST_FUNCTION Duration operator/(Duration lhs, T rhs) { + return lhs /= rhs; +} +ABSL_ATTRIBUTE_CONST_FUNCTION inline int64_t operator/(Duration lhs, + Duration rhs) { + return IDivDuration(lhs, rhs, + &lhs); // trunc towards zero +} +ABSL_ATTRIBUTE_CONST_FUNCTION inline Duration operator%(Duration lhs, + Duration rhs) { + return lhs %= rhs; +} + // ZeroDuration() // // Returns a zero-length duration. This function behaves just like the default @@ -841,6 +852,11 @@ class Time { private: friend constexpr Time time_internal::FromUnixDuration(Duration d); friend constexpr Duration time_internal::ToUnixDuration(Time t); + +#ifdef __cpp_impl_three_way_comparison + friend constexpr std::strong_ordering operator<=>(Time lhs, Time rhs); +#endif // __cpp_impl_three_way_comparison + friend constexpr bool operator<(Time lhs, Time rhs); friend constexpr bool operator==(Time lhs, Time rhs); friend Duration operator-(Time lhs, Time rhs); @@ -852,6 +868,15 @@ class Time { }; // Relational Operators +#ifdef __cpp_impl_three_way_comparison + +ABSL_ATTRIBUTE_CONST_FUNCTION constexpr std::strong_ordering operator<=>( + Time lhs, Time rhs) { + return lhs.rep_ <=> rhs.rep_; +} + +#endif // __cpp_impl_three_way_comparison + ABSL_ATTRIBUTE_CONST_FUNCTION constexpr bool operator<(Time lhs, Time rhs) { return lhs.rep_ < rhs.rep_; } @@ -1727,6 +1752,25 @@ ABSL_ATTRIBUTE_CONST_FUNCTION constexpr bool operator<(Duration lhs, : time_internal::GetRepLo(lhs) < time_internal::GetRepLo(rhs); } + +#ifdef __cpp_impl_three_way_comparison + +ABSL_ATTRIBUTE_CONST_FUNCTION constexpr std::strong_ordering operator<=>( + Duration lhs, Duration rhs) { + const int64_t lhs_hi = time_internal::GetRepHi(lhs); + const int64_t rhs_hi = time_internal::GetRepHi(rhs); + if (auto c = lhs_hi <=> rhs_hi; c != std::strong_ordering::equal) { + return c; + } + const uint32_t lhs_lo = time_internal::GetRepLo(lhs); + const uint32_t rhs_lo = time_internal::GetRepLo(rhs); + return (lhs_hi == (std::numeric_limits<int64_t>::min)()) + ? (lhs_lo + 1) <=> (rhs_lo + 1) + : lhs_lo <=> rhs_lo; +} + +#endif // __cpp_impl_three_way_comparison + ABSL_ATTRIBUTE_CONST_FUNCTION constexpr bool operator==(Duration lhs, Duration rhs) { return time_internal::GetRepHi(lhs) == time_internal::GetRepHi(rhs) && diff --git a/absl/time/time_test.cc b/absl/time/time_test.cc index bcf4f2ad..71f54d64 100644 --- a/absl/time/time_test.cc +++ b/absl/time/time_test.cc @@ -14,11 +14,21 @@ #include "absl/time/time.h" +#include <cstdint> +#include <ios> + +#include "absl/time/civil_time.h" + #if defined(_MSC_VER) #include <winsock2.h> // for timeval #endif #include <chrono> // NOLINT(build/c++11) + +#ifdef __cpp_impl_three_way_comparison +#include <compare> +#endif // __cpp_impl_three_way_comparison + #include <cstring> #include <ctime> #include <iomanip> @@ -77,21 +87,21 @@ MATCHER_P(TimevalMatcher, tv, "") { TEST(Time, ConstExpr) { constexpr absl::Time t0 = absl::UnixEpoch(); - static_assert(t0 == absl::Time(), "UnixEpoch"); + static_assert(t0 == absl::UnixEpoch(), "UnixEpoch"); constexpr absl::Time t1 = absl::InfiniteFuture(); - static_assert(t1 != absl::Time(), "InfiniteFuture"); + static_assert(t1 != absl::UnixEpoch(), "InfiniteFuture"); constexpr absl::Time t2 = absl::InfinitePast(); - static_assert(t2 != absl::Time(), "InfinitePast"); + static_assert(t2 != absl::UnixEpoch(), "InfinitePast"); constexpr absl::Time t3 = absl::FromUnixNanos(0); - static_assert(t3 == absl::Time(), "FromUnixNanos"); + static_assert(t3 == absl::UnixEpoch(), "FromUnixNanos"); constexpr absl::Time t4 = absl::FromUnixMicros(0); - static_assert(t4 == absl::Time(), "FromUnixMicros"); + static_assert(t4 == absl::UnixEpoch(), "FromUnixMicros"); constexpr absl::Time t5 = absl::FromUnixMillis(0); - static_assert(t5 == absl::Time(), "FromUnixMillis"); + static_assert(t5 == absl::UnixEpoch(), "FromUnixMillis"); constexpr absl::Time t6 = absl::FromUnixSeconds(0); - static_assert(t6 == absl::Time(), "FromUnixSeconds"); + static_assert(t6 == absl::UnixEpoch(), "FromUnixSeconds"); constexpr absl::Time t7 = absl::FromTimeT(0); - static_assert(t7 == absl::Time(), "FromTimeT"); + static_assert(t7 == absl::UnixEpoch(), "FromTimeT"); } TEST(Time, ValueSemantics) { @@ -176,7 +186,7 @@ TEST(Time, RelationalOperators) { constexpr absl::Time t2 = absl::FromUnixNanos(1); constexpr absl::Time t3 = absl::FromUnixNanos(2); - static_assert(absl::Time() == t1, ""); + static_assert(absl::UnixEpoch() == t1, ""); static_assert(t1 == t1, ""); static_assert(t2 == t2, ""); static_assert(t3 == t3, ""); @@ -202,6 +212,22 @@ TEST(Time, RelationalOperators) { static_assert(t3 >= t2, ""); static_assert(t1 >= t1, ""); static_assert(t3 >= t1, ""); + +#ifdef __cpp_impl_three_way_comparison + + static_assert((t1 <=> t1) == std::strong_ordering::equal, ""); + static_assert((t2 <=> t2) == std::strong_ordering::equal, ""); + static_assert((t3 <=> t3) == std::strong_ordering::equal, ""); + + static_assert((t1 <=> t2) == std::strong_ordering::less, ""); + static_assert((t2 <=> t3) == std::strong_ordering::less, ""); + static_assert((t1 <=> t3) == std::strong_ordering::less, ""); + + static_assert((t2 <=> t1) == std::strong_ordering::greater, ""); + static_assert((t3 <=> t2) == std::strong_ordering::greater, ""); + static_assert((t3 <=> t1) == std::strong_ordering::greater, ""); + +#endif // __cpp_impl_three_way_comparison } TEST(Time, Infinity) { @@ -213,6 +239,15 @@ TEST(Time, Infinity) { static_assert(ipast < ifuture, ""); static_assert(ifuture > ipast, ""); +#ifdef __cpp_impl_three_way_comparison + + static_assert((ifuture <=> ifuture) == std::strong_ordering::equal, ""); + static_assert((ipast <=> ipast) == std::strong_ordering::equal, ""); + static_assert((ipast <=> ifuture) == std::strong_ordering::less, ""); + static_assert((ifuture <=> ipast) == std::strong_ordering::greater, ""); + +#endif // __cpp_impl_three_way_comparison + // Arithmetic saturates EXPECT_EQ(ifuture, ifuture + absl::Seconds(1)); EXPECT_EQ(ifuture, ifuture - absl::Seconds(1)); @@ -228,6 +263,15 @@ TEST(Time, Infinity) { static_assert(t < ifuture, ""); static_assert(t > ipast, ""); +#ifdef __cpp_impl_three_way_comparison + + static_assert((t <=> ifuture) == std::strong_ordering::less, ""); + static_assert((t <=> ipast) == std::strong_ordering::greater, ""); + static_assert((ipast <=> t) == std::strong_ordering::less, ""); + static_assert((ifuture <=> t) == std::strong_ordering::greater, ""); + +#endif // __cpp_impl_three_way_comparison + EXPECT_EQ(ifuture, t + absl::InfiniteDuration()); EXPECT_EQ(ipast, t - absl::InfiniteDuration()); } @@ -255,7 +299,7 @@ TEST(Time, FloorConversion) { EXPECT_EQ(1, absl::ToUnixNanos(absl::UnixEpoch() + absl::Nanoseconds(3) / 2)); EXPECT_EQ(1, absl::ToUnixNanos(absl::UnixEpoch() + absl::Nanoseconds(1))); EXPECT_EQ(0, absl::ToUnixNanos(absl::UnixEpoch() + absl::Nanoseconds(1) / 2)); - EXPECT_EQ(0, absl::ToUnixNanos(absl::UnixEpoch() + absl::Nanoseconds(0))); + EXPECT_EQ(0, absl::ToUnixNanos(absl::UnixEpoch() + absl::ZeroDuration())); EXPECT_EQ(-1, absl::ToUnixNanos(absl::UnixEpoch() - absl::Nanoseconds(1) / 2)); EXPECT_EQ(-1, absl::ToUnixNanos(absl::UnixEpoch() - absl::Nanoseconds(1))); @@ -272,7 +316,7 @@ TEST(Time, FloorConversion) { EXPECT_EQ(0, absl::ToUniversal(absl::UniversalEpoch() + absl::Nanoseconds(1))); EXPECT_EQ(0, - absl::ToUniversal(absl::UniversalEpoch() + absl::Nanoseconds(0))); + absl::ToUniversal(absl::UniversalEpoch() + absl::ZeroDuration())); EXPECT_EQ(-1, absl::ToUniversal(absl::UniversalEpoch() + absl::Nanoseconds(-1))); EXPECT_EQ(-1, @@ -289,13 +333,13 @@ TEST(Time, FloorConversion) { } to_ts[] = { {absl::FromUnixSeconds(1) + absl::Nanoseconds(1), {1, 1}}, {absl::FromUnixSeconds(1) + absl::Nanoseconds(1) / 2, {1, 0}}, - {absl::FromUnixSeconds(1) + absl::Nanoseconds(0), {1, 0}}, - {absl::FromUnixSeconds(0) + absl::Nanoseconds(0), {0, 0}}, + {absl::FromUnixSeconds(1) + absl::ZeroDuration(), {1, 0}}, + {absl::FromUnixSeconds(0) + absl::ZeroDuration(), {0, 0}}, {absl::FromUnixSeconds(0) - absl::Nanoseconds(1) / 2, {-1, 999999999}}, {absl::FromUnixSeconds(0) - absl::Nanoseconds(1), {-1, 999999999}}, {absl::FromUnixSeconds(-1) + absl::Nanoseconds(1), {-1, 1}}, {absl::FromUnixSeconds(-1) + absl::Nanoseconds(1) / 2, {-1, 0}}, - {absl::FromUnixSeconds(-1) + absl::Nanoseconds(0), {-1, 0}}, + {absl::FromUnixSeconds(-1) + absl::ZeroDuration(), {-1, 0}}, {absl::FromUnixSeconds(-1) - absl::Nanoseconds(1) / 2, {-2, 999999999}}, }; for (const auto& test : to_ts) { @@ -306,12 +350,12 @@ TEST(Time, FloorConversion) { absl::Time t; } from_ts[] = { {{1, 1}, absl::FromUnixSeconds(1) + absl::Nanoseconds(1)}, - {{1, 0}, absl::FromUnixSeconds(1) + absl::Nanoseconds(0)}, - {{0, 0}, absl::FromUnixSeconds(0) + absl::Nanoseconds(0)}, + {{1, 0}, absl::FromUnixSeconds(1) + absl::ZeroDuration()}, + {{0, 0}, absl::FromUnixSeconds(0) + absl::ZeroDuration()}, {{0, -1}, absl::FromUnixSeconds(0) - absl::Nanoseconds(1)}, {{-1, 999999999}, absl::FromUnixSeconds(0) - absl::Nanoseconds(1)}, {{-1, 1}, absl::FromUnixSeconds(-1) + absl::Nanoseconds(1)}, - {{-1, 0}, absl::FromUnixSeconds(-1) + absl::Nanoseconds(0)}, + {{-1, 0}, absl::FromUnixSeconds(-1) + absl::ZeroDuration()}, {{-1, -1}, absl::FromUnixSeconds(-1) - absl::Nanoseconds(1)}, {{-2, 999999999}, absl::FromUnixSeconds(-1) - absl::Nanoseconds(1)}, }; @@ -319,36 +363,36 @@ TEST(Time, FloorConversion) { EXPECT_EQ(test.t, absl::TimeFromTimespec(test.ts)); } - // Tests ToTimeval()/TimeFromTimeval() (same as timespec above) + // Tests absl::ToTimeval()/TimeFromTimeval() (same as timespec above) const struct { absl::Time t; timeval tv; } to_tv[] = { {absl::FromUnixSeconds(1) + absl::Microseconds(1), {1, 1}}, {absl::FromUnixSeconds(1) + absl::Microseconds(1) / 2, {1, 0}}, - {absl::FromUnixSeconds(1) + absl::Microseconds(0), {1, 0}}, - {absl::FromUnixSeconds(0) + absl::Microseconds(0), {0, 0}}, + {absl::FromUnixSeconds(1) + absl::ZeroDuration(), {1, 0}}, + {absl::FromUnixSeconds(0) + absl::ZeroDuration(), {0, 0}}, {absl::FromUnixSeconds(0) - absl::Microseconds(1) / 2, {-1, 999999}}, {absl::FromUnixSeconds(0) - absl::Microseconds(1), {-1, 999999}}, {absl::FromUnixSeconds(-1) + absl::Microseconds(1), {-1, 1}}, {absl::FromUnixSeconds(-1) + absl::Microseconds(1) / 2, {-1, 0}}, - {absl::FromUnixSeconds(-1) + absl::Microseconds(0), {-1, 0}}, + {absl::FromUnixSeconds(-1) + absl::ZeroDuration(), {-1, 0}}, {absl::FromUnixSeconds(-1) - absl::Microseconds(1) / 2, {-2, 999999}}, }; for (const auto& test : to_tv) { - EXPECT_THAT(ToTimeval(test.t), TimevalMatcher(test.tv)); + EXPECT_THAT(absl::ToTimeval(test.t), TimevalMatcher(test.tv)); } const struct { timeval tv; absl::Time t; } from_tv[] = { {{1, 1}, absl::FromUnixSeconds(1) + absl::Microseconds(1)}, - {{1, 0}, absl::FromUnixSeconds(1) + absl::Microseconds(0)}, - {{0, 0}, absl::FromUnixSeconds(0) + absl::Microseconds(0)}, + {{1, 0}, absl::FromUnixSeconds(1) + absl::ZeroDuration()}, + {{0, 0}, absl::FromUnixSeconds(0) + absl::ZeroDuration()}, {{0, -1}, absl::FromUnixSeconds(0) - absl::Microseconds(1)}, {{-1, 999999}, absl::FromUnixSeconds(0) - absl::Microseconds(1)}, {{-1, 1}, absl::FromUnixSeconds(-1) + absl::Microseconds(1)}, - {{-1, 0}, absl::FromUnixSeconds(-1) + absl::Microseconds(0)}, + {{-1, 0}, absl::FromUnixSeconds(-1) + absl::ZeroDuration()}, {{-1, -1}, absl::FromUnixSeconds(-1) - absl::Microseconds(1)}, {{-2, 999999}, absl::FromUnixSeconds(-1) - absl::Microseconds(1)}, }; @@ -438,7 +482,7 @@ TEST(Time, RoundtripConversion) { testing::Eq) << now_time_t; - // TimeFromTimeval() and ToTimeval() + // TimeFromTimeval() and absl::ToTimeval() timeval tv; tv.tv_sec = -1; tv.tv_usec = 0; @@ -723,14 +767,14 @@ TEST(Time, FromCivilUTC) { TEST(Time, ToTM) { const absl::TimeZone utc = absl::UTCTimeZone(); - // Compares the results of ToTM() to gmtime_r() for lots of times over the - // course of a few days. + // Compares the results of absl::ToTM() to gmtime_r() for lots of times over + // the course of a few days. const absl::Time start = absl::FromCivil(absl::CivilSecond(2014, 1, 2, 3, 4, 5), utc); const absl::Time end = absl::FromCivil(absl::CivilSecond(2014, 1, 5, 3, 4, 5), utc); for (absl::Time t = start; t < end; t += absl::Seconds(30)) { - const struct tm tm_bt = ToTM(t, utc); + const struct tm tm_bt = absl::ToTM(t, utc); const time_t tt = absl::ToTimeT(t); struct tm tm_lc; #ifdef _WIN32 @@ -755,16 +799,16 @@ TEST(Time, ToTM) { const absl::TimeZone nyc = absl::time_internal::LoadTimeZone("America/New_York"); absl::Time t = absl::FromCivil(absl::CivilSecond(2014, 3, 1, 0, 0, 0), nyc); - struct tm tm = ToTM(t, nyc); + struct tm tm = absl::ToTM(t, nyc); EXPECT_FALSE(tm.tm_isdst); // Checks that the tm_isdst field is correct when in daylight time. t = absl::FromCivil(absl::CivilSecond(2014, 4, 1, 0, 0, 0), nyc); - tm = ToTM(t, nyc); + tm = absl::ToTM(t, nyc); EXPECT_TRUE(tm.tm_isdst); // Checks overflow. - tm = ToTM(absl::InfiniteFuture(), nyc); + tm = absl::ToTM(absl::InfiniteFuture(), nyc); EXPECT_EQ(std::numeric_limits<int>::max() - 1900, tm.tm_year); EXPECT_EQ(11, tm.tm_mon); EXPECT_EQ(31, tm.tm_mday); @@ -776,7 +820,7 @@ TEST(Time, ToTM) { EXPECT_FALSE(tm.tm_isdst); // Checks underflow. - tm = ToTM(absl::InfinitePast(), nyc); + tm = absl::ToTM(absl::InfinitePast(), nyc); EXPECT_EQ(std::numeric_limits<int>::min(), tm.tm_year); EXPECT_EQ(0, tm.tm_mon); EXPECT_EQ(1, tm.tm_mday); @@ -802,13 +846,13 @@ TEST(Time, FromTM) { tm.tm_min = 2; tm.tm_sec = 3; tm.tm_isdst = -1; - absl::Time t = FromTM(tm, nyc); + absl::Time t = absl::FromTM(tm, nyc); EXPECT_EQ("2014-06-28T01:02:03-04:00", absl::FormatTime(t, nyc)); // DST tm.tm_isdst = 0; - t = FromTM(tm, nyc); + t = absl::FromTM(tm, nyc); EXPECT_EQ("2014-06-28T01:02:03-04:00", absl::FormatTime(t, nyc)); // DST tm.tm_isdst = 1; - t = FromTM(tm, nyc); + t = absl::FromTM(tm, nyc); EXPECT_EQ("2014-06-28T01:02:03-04:00", absl::FormatTime(t, nyc)); // DST // Adjusts tm to refer to an ambiguous time. @@ -819,13 +863,13 @@ TEST(Time, FromTM) { tm.tm_min = 30; tm.tm_sec = 42; tm.tm_isdst = -1; - t = FromTM(tm, nyc); + t = absl::FromTM(tm, nyc); EXPECT_EQ("2014-11-02T01:30:42-04:00", absl::FormatTime(t, nyc)); // DST tm.tm_isdst = 0; - t = FromTM(tm, nyc); + t = absl::FromTM(tm, nyc); EXPECT_EQ("2014-11-02T01:30:42-05:00", absl::FormatTime(t, nyc)); // STD tm.tm_isdst = 1; - t = FromTM(tm, nyc); + t = absl::FromTM(tm, nyc); EXPECT_EQ("2014-11-02T01:30:42-04:00", absl::FormatTime(t, nyc)); // DST // Adjusts tm to refer to a skipped time. @@ -836,13 +880,13 @@ TEST(Time, FromTM) { tm.tm_min = 30; tm.tm_sec = 42; tm.tm_isdst = -1; - t = FromTM(tm, nyc); + t = absl::FromTM(tm, nyc); EXPECT_EQ("2014-03-09T03:30:42-04:00", absl::FormatTime(t, nyc)); // DST tm.tm_isdst = 0; - t = FromTM(tm, nyc); + t = absl::FromTM(tm, nyc); EXPECT_EQ("2014-03-09T01:30:42-05:00", absl::FormatTime(t, nyc)); // STD tm.tm_isdst = 1; - t = FromTM(tm, nyc); + t = absl::FromTM(tm, nyc); EXPECT_EQ("2014-03-09T03:30:42-04:00", absl::FormatTime(t, nyc)); // DST // Adjusts tm to refer to a time with a year larger than 2147483647. @@ -853,7 +897,7 @@ TEST(Time, FromTM) { tm.tm_min = 2; tm.tm_sec = 3; tm.tm_isdst = -1; - t = FromTM(tm, absl::UTCTimeZone()); + t = absl::FromTM(tm, absl::UTCTimeZone()); EXPECT_EQ("2147483648-06-28T01:02:03+00:00", absl::FormatTime(t, absl::UTCTimeZone())); @@ -865,7 +909,7 @@ TEST(Time, FromTM) { tm.tm_min = 2; tm.tm_sec = 3; tm.tm_isdst = -1; - t = FromTM(tm, absl::UTCTimeZone()); + t = absl::FromTM(tm, absl::UTCTimeZone()); EXPECT_EQ("178958989-08-28T01:02:03+00:00", absl::FormatTime(t, absl::UTCTimeZone())); } @@ -878,8 +922,8 @@ TEST(Time, TMRoundTrip) { absl::Time start = absl::FromCivil(absl::CivilHour(2014, 3, 9, 0), nyc); absl::Time end = absl::FromCivil(absl::CivilHour(2014, 3, 9, 4), nyc); for (absl::Time t = start; t < end; t += absl::Minutes(1)) { - struct tm tm = ToTM(t, nyc); - absl::Time rt = FromTM(tm, nyc); + struct tm tm = absl::ToTM(t, nyc); + absl::Time rt = absl::FromTM(tm, nyc); EXPECT_EQ(rt, t); } @@ -887,8 +931,8 @@ TEST(Time, TMRoundTrip) { start = absl::FromCivil(absl::CivilHour(2014, 11, 2, 0), nyc); end = absl::FromCivil(absl::CivilHour(2014, 11, 2, 4), nyc); for (absl::Time t = start; t < end; t += absl::Minutes(1)) { - struct tm tm = ToTM(t, nyc); - absl::Time rt = FromTM(tm, nyc); + struct tm tm = absl::ToTM(t, nyc); + absl::Time rt = absl::FromTM(tm, nyc); EXPECT_EQ(rt, t); } @@ -896,8 +940,8 @@ TEST(Time, TMRoundTrip) { start = absl::FromCivil(absl::CivilHour(2014, 6, 27, 22), nyc); end = absl::FromCivil(absl::CivilHour(2014, 6, 28, 4), nyc); for (absl::Time t = start; t < end; t += absl::Minutes(1)) { - struct tm tm = ToTM(t, nyc); - absl::Time rt = FromTM(tm, nyc); + struct tm tm = absl::ToTM(t, nyc); + absl::Time rt = absl::FromTM(tm, nyc); EXPECT_EQ(rt, t); } } @@ -985,30 +1029,30 @@ TEST(Time, ConversionSaturation) { tv.tv_sec = max_timeval_sec; tv.tv_usec = 999998; t = absl::TimeFromTimeval(tv); - tv = ToTimeval(t); + tv = absl::ToTimeval(t); EXPECT_EQ(max_timeval_sec, tv.tv_sec); EXPECT_EQ(999998, tv.tv_usec); t += absl::Microseconds(1); - tv = ToTimeval(t); + tv = absl::ToTimeval(t); EXPECT_EQ(max_timeval_sec, tv.tv_sec); EXPECT_EQ(999999, tv.tv_usec); t += absl::Microseconds(1); // no effect - tv = ToTimeval(t); + tv = absl::ToTimeval(t); EXPECT_EQ(max_timeval_sec, tv.tv_sec); EXPECT_EQ(999999, tv.tv_usec); tv.tv_sec = min_timeval_sec; tv.tv_usec = 1; t = absl::TimeFromTimeval(tv); - tv = ToTimeval(t); + tv = absl::ToTimeval(t); EXPECT_EQ(min_timeval_sec, tv.tv_sec); EXPECT_EQ(1, tv.tv_usec); t -= absl::Microseconds(1); - tv = ToTimeval(t); + tv = absl::ToTimeval(t); EXPECT_EQ(min_timeval_sec, tv.tv_sec); EXPECT_EQ(0, tv.tv_usec); t -= absl::Microseconds(1); // no effect - tv = ToTimeval(t); + tv = absl::ToTimeval(t); EXPECT_EQ(min_timeval_sec, tv.tv_sec); EXPECT_EQ(0, tv.tv_usec); |