From 744f9daf43c06d920966773c5d6607377b6a6230 Mon Sep 17 00:00:00 2001 From: Konstantin Varlamov Date: Thu, 29 Mar 2018 20:00:13 -0400 Subject: C++ migration: refactor Timestamp logic checking for overflow. (#1000) Rewrite manual checks using `` min()/max() functions and duration_cast. This is cleaner and avoids including . --- Firestore/core/include/firebase/firestore/timestamp.h | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'Firestore/core/include') diff --git a/Firestore/core/include/firebase/firestore/timestamp.h b/Firestore/core/include/firebase/firestore/timestamp.h index 096d121..2ee1c46 100644 --- a/Firestore/core/include/firebase/firestore/timestamp.h +++ b/Firestore/core/include/firebase/firestore/timestamp.h @@ -22,7 +22,6 @@ #if !defined(_STLPORT_VERSION) #include // NOLINT(build/c++11) #endif // !defined(_STLPORT_VERSION) -#include #include namespace firebase { @@ -191,13 +190,13 @@ std::chrono::time_point Timestamp::ToTimePoint() const { using TimePoint = chr::time_point; // Saturate on overflow - const auto max_value = std::numeric_limits::max(); - if (seconds_ > 0 && max_value / Duration::period::den <= seconds_) { - return TimePoint{Duration(max_value)}; + const auto max_seconds = chr::duration_cast(Duration::max()); + if (seconds_ > 0 && max_seconds.count() <= seconds_) { + return TimePoint{Duration::max()}; } - const auto min_value = std::numeric_limits::min(); - if (seconds_ < 0 && min_value / Duration::period::den >= seconds_) { - return TimePoint{Duration(min_value)}; + const auto min_seconds = chr::duration_cast(Duration::min()); + if (seconds_ < 0 && min_seconds.count() >= seconds_) { + return TimePoint{Duration::min()}; } const auto seconds = chr::duration_cast(chr::seconds(seconds_)); -- cgit v1.2.3