about summary refs log tree commit diff
path: root/absl/time
diff options
context:
space:
mode:
Diffstat (limited to 'absl/time')
-rw-r--r--absl/time/duration_test.cc24
-rw-r--r--absl/time/time.cc6
-rw-r--r--absl/time/time.h73
3 files changed, 53 insertions, 50 deletions
diff --git a/absl/time/duration_test.cc b/absl/time/duration_test.cc
index ab98b02ac38f..7f4522874861 100644
--- a/absl/time/duration_test.cc
+++ b/absl/time/duration_test.cc
@@ -460,10 +460,10 @@ TEST(Duration, InfinityAddition) {
 
   // For reference: IEEE 754 behavior
   const double dbl_inf = std::numeric_limits<double>::infinity();
-  EXPECT_TRUE(isinf(dbl_inf + dbl_inf));
-  EXPECT_TRUE(isnan(dbl_inf + -dbl_inf));  // We return inf
-  EXPECT_TRUE(isnan(-dbl_inf + dbl_inf));  // We return inf
-  EXPECT_TRUE(isinf(-dbl_inf + -dbl_inf));
+  EXPECT_TRUE(std::isinf(dbl_inf + dbl_inf));
+  EXPECT_TRUE(std::isnan(dbl_inf + -dbl_inf));  // We return inf
+  EXPECT_TRUE(std::isnan(-dbl_inf + dbl_inf));  // We return inf
+  EXPECT_TRUE(std::isinf(-dbl_inf + -dbl_inf));
 }
 
 TEST(Duration, InfinitySubtraction) {
@@ -497,10 +497,10 @@ TEST(Duration, InfinitySubtraction) {
 
   // For reference: IEEE 754 behavior
   const double dbl_inf = std::numeric_limits<double>::infinity();
-  EXPECT_TRUE(isnan(dbl_inf - dbl_inf));  // We return inf
-  EXPECT_TRUE(isinf(dbl_inf - -dbl_inf));
-  EXPECT_TRUE(isinf(-dbl_inf - dbl_inf));
-  EXPECT_TRUE(isnan(-dbl_inf - -dbl_inf));  // We return inf
+  EXPECT_TRUE(std::isnan(dbl_inf - dbl_inf));  // We return inf
+  EXPECT_TRUE(std::isinf(dbl_inf - -dbl_inf));
+  EXPECT_TRUE(std::isinf(-dbl_inf - dbl_inf));
+  EXPECT_TRUE(std::isnan(-dbl_inf - -dbl_inf));  // We return inf
 }
 
 TEST(Duration, InfinityMultiplication) {
@@ -708,13 +708,13 @@ TEST(Duration, InfinityIDiv) {
 
   // IEEE 754 says inf / inf should be nan, but int64_t doesn't have
   // nan so we'll return kint64max/kint64min instead.
-  EXPECT_TRUE(isnan(dbl_inf / dbl_inf));
+  EXPECT_TRUE(std::isnan(dbl_inf / dbl_inf));
   EXPECT_EQ(kint64max, inf / inf);
   EXPECT_EQ(kint64max, -inf / -inf);
   EXPECT_EQ(kint64min, -inf / inf);
   EXPECT_EQ(kint64min, inf / -inf);
 
-  EXPECT_TRUE(isinf(dbl_inf / 2.0));
+  EXPECT_TRUE(std::isinf(dbl_inf / 2.0));
   EXPECT_EQ(kint64max, inf / any_dur);
   EXPECT_EQ(kint64max, -inf / -any_dur);
   EXPECT_EQ(kint64min, -inf / any_dur);
@@ -763,8 +763,8 @@ TEST(Duration, DivisionByZero) {
 
   // IEEE 754 behavior
   double z = 0.0, two = 2.0;
-  EXPECT_TRUE(isinf(two / z));
-  EXPECT_TRUE(isnan(z / z));  // We'll return inf
+  EXPECT_TRUE(std::isinf(two / z));
+  EXPECT_TRUE(std::isnan(z / z));  // We'll return inf
 
   // Operator/(Duration, double)
   EXPECT_EQ(inf, zero / 0.0);
diff --git a/absl/time/time.cc b/absl/time/time.cc
index ee14ba306e80..0fb285a7b2dc 100644
--- a/absl/time/time.cc
+++ b/absl/time/time.cc
@@ -15,7 +15,7 @@
 // The implementation of the absl::Time class, which is declared in
 // //absl/time.h.
 //
-// The representation for a absl::Time is a absl::Duration offset from the
+// The representation for an absl::Time is an absl::Duration offset from the
 // epoch.  We use the traditional Unix epoch (1970-01-01 00:00:00 +0000)
 // for convenience, but this is not exposed in the API and could be changed.
 //
@@ -23,12 +23,12 @@
 // conventions are used throughout this file.
 //
 // cz: A cctz::time_zone
-// tz: A absl::TimeZone
+// tz: An absl::TimeZone
 // cl: A cctz::time_zone::civil_lookup
 // al: A cctz::time_zone::absolute_lookup
 // cd: A cctz::civil_day
 // cs: A cctz::civil_second
-// bd: A absl::Time::Breakdown
+// bd: An absl::Time::Breakdown
 
 #include "absl/time/time.h"
 
diff --git a/absl/time/time.h b/absl/time/time.h
index b0ebf6ee8e53..17dbfa6fb90a 100644
--- a/absl/time/time.h
+++ b/absl/time/time.h
@@ -68,9 +68,9 @@
 
 namespace absl {
 
-class Duration;      // Defined below
-class Time;          // Defined below
-class TimeZone;      // Defined below
+class Duration;  // Defined below
+class Time;      // Defined below
+class TimeZone;  // Defined below
 
 namespace time_internal {
 int64_t IDivDuration(bool satq, Duration num, Duration den, Duration* rem);
@@ -558,26 +558,32 @@ class Time {
   constexpr Time() {}
 
   // Assignment operators.
-  Time& operator+=(Duration d) { rep_ += d;  return *this; }
-  Time& operator-=(Duration d) { rep_ -= d;  return *this; }
+  Time& operator+=(Duration d) {
+    rep_ += d;
+    return *this;
+  }
+  Time& operator-=(Duration d) {
+    rep_ -= d;
+    return *this;
+  }
 
   // Time::Breakdown
   //
-  // The calendar and wall-clock (aka "civil time") components of a
+  // The calendar and wall-clock (aka "civil time") components of an
   // `absl::Time` in a certain `absl::TimeZone`. This struct is not
   // intended to represent an instant in time. So, rather than passing
   // a `Time::Breakdown` to a function, pass an `absl::Time` and an
   // `absl::TimeZone`.
   struct Breakdown {
-    int64_t year;             // year (e.g., 2013)
-    int month;              // month of year [1:12]
-    int day;                // day of month [1:31]
-    int hour;               // hour of day [0:23]
-    int minute;             // minute of hour [0:59]
-    int second;             // second of minute [0:59]
-    Duration subsecond;     // [Seconds(0):Seconds(1)) if finite
-    int weekday;            // 1==Mon, ..., 7=Sun
-    int yearday;            // day of year [1:366]
+    int64_t year;          // year (e.g., 2013)
+    int month;           // month of year [1:12]
+    int day;             // day of month [1:31]
+    int hour;            // hour of day [0:23]
+    int minute;          // minute of hour [0:59]
+    int second;          // second of minute [0:59]
+    Duration subsecond;  // [Seconds(0):Seconds(1)) if finite
+    int weekday;         // 1==Mon, ..., 7=Sun
+    int yearday;         // day of year [1:366]
 
     // Note: The following fields exist for backward compatibility
     // with older APIs.  Accessing these fields directly is a sign of
@@ -624,9 +630,7 @@ inline Duration operator-(Time lhs, Time rhs) { return lhs.rep_ - rhs.rep_; }
 // UnixEpoch()
 //
 // Returns the `absl::Time` representing "1970-01-01 00:00:00.0 +0000".
-constexpr Time UnixEpoch() {
-  return Time();
-}
+constexpr Time UnixEpoch() { return Time(); }
 
 // UniversalEpoch()
 //
@@ -717,14 +721,14 @@ constexpr Time InfinitePast() {
 //   // tc.kind == TimeConversion::UNIQUE && tc.normalized == true
 //   // tc.pre.In(tz).month == 11 && tc.pre.In(tz).day == 1
 struct TimeConversion {
-  Time pre;         // time calculated using the pre-transition offset
-  Time trans;       // when the civil-time discontinuity occurred
-  Time post;        // time calculated using the post-transition offset
+  Time pre;    // time calculated using the pre-transition offset
+  Time trans;  // when the civil-time discontinuity occurred
+  Time post;   // time calculated using the post-transition offset
 
   enum Kind {
-    UNIQUE,         // the civil time was singular (pre == trans == post)
-    SKIPPED,        // the civil time did not exist
-    REPEATED,       // the civil time was ambiguous
+    UNIQUE,    // the civil time was singular (pre == trans == post)
+    SKIPPED,   // the civil time did not exist
+    REPEATED,  // the civil time was ambiguous
   };
   Kind kind;
 
@@ -869,8 +873,8 @@ extern const char RFC3339_sec[];   // %Y-%m-%dT%H:%M:%S%Ez
 // RFC1123_no_wday
 //
 // FormatTime()/ParseTime() format specifiers for RFC1123 date/time strings.
-extern const char RFC1123_full[];  // %a, %d %b %E4Y %H:%M:%S %z
-extern const char RFC1123_no_wday[];   // %d %b %E4Y %H:%M:%S %z
+extern const char RFC1123_full[];     // %a, %d %b %E4Y %H:%M:%S %z
+extern const char RFC1123_no_wday[];  // %d %b %E4Y %H:%M:%S %z
 
 // FormatTime()
 //
@@ -937,7 +941,7 @@ inline std::ostream& operator<<(std::ostream& os, Time t) {
 //
 //   "1970-01-01 00:00:00.0 +0000"
 //
-// For example, parsing a std::string of "15:45" (%H:%M) will return a absl::Time
+// For example, parsing a std::string of "15:45" (%H:%M) will return an absl::Time
 // that represents "1970-01-01 15:45:00.0 +0000".  Note: Since ParseTime()
 // returns time instants, it makes the most sense to parse fully-specified
 // date/time strings that include a UTC offset (%z/%Ez), such as those
@@ -968,8 +972,8 @@ inline std::ostream& operator<<(std::ostream& os, Time t) {
 // If the input std::string is "infinite-past", the returned `absl::Time` will be
 // `absl::InfinitePast()` and `true` will be returned.
 //
-bool ParseTime(const std::string& format, const std::string& input,
-               Time* time, std::string* err);
+bool ParseTime(const std::string& format, const std::string& input, Time* time,
+               std::string* err);
 
 // Like ParseTime() above, but if the format std::string does not contain a UTC
 // offset specification (%z/%Ez) then the input is interpreted in the given
@@ -994,8 +998,8 @@ bool ParseTime(const std::string& format, const std::string& input, TimeZone tz,
 // Note: A UTC offset (or 'Z' indicating a zero-offset from UTC) is required.
 //
 // Additionally, if you'd like to specify a time as a count of
-// seconds/milliseconds/etc from the Unix epoch, use a absl::Duration flag and
-// add that duration to absl::UnixEpoch() to get a absl::Time.
+// seconds/milliseconds/etc from the Unix epoch, use an absl::Duration flag
+// and add that duration to absl::UnixEpoch() to get an absl::Time.
 bool ParseFlag(const std::string& text, Time* t, std::string* error);
 std::string UnparseFlag(Time t);
 
@@ -1098,7 +1102,7 @@ constexpr Duration MakeDuration(int64_t hi, uint32_t lo = 0) {
 }
 
 constexpr Duration MakeDuration(int64_t hi, int64_t lo) {
-  return time_internal::MakeDuration(hi, static_cast<uint32_t>(lo));
+  return MakeDuration(hi, static_cast<uint32_t>(lo));
 }
 
 // Creates a normalized Duration from an almost-normalized (sec,ticks)
@@ -1106,9 +1110,8 @@ constexpr Duration MakeDuration(int64_t hi, int64_t lo) {
 // -kTicksPerSecond < *ticks < kTicksPerSecond.  If ticks is negative it
 // will be normalized to a positive value in the resulting Duration.
 constexpr Duration MakeNormalizedDuration(int64_t sec, int64_t ticks) {
-  return (ticks < 0)
-             ? time_internal::MakeDuration(sec - 1, ticks + kTicksPerSecond)
-             : time_internal::MakeDuration(sec, ticks);
+  return (ticks < 0) ? MakeDuration(sec - 1, ticks + kTicksPerSecond)
+                     : MakeDuration(sec, ticks);
 }
 // Provide access to the Duration representation.
 constexpr int64_t GetRepHi(Duration d) { return d.rep_hi_; }