diff options
author | Abseil Team <absl-team@google.com> | 2017-09-27T17·50-0700 |
---|---|---|
committer | Derek Mauro <dmauro@google.com> | 2017-09-27T20·03-0400 |
commit | cdf20caa491f59c0a35a8d8fbec0d948e4bc7e4c (patch) | |
tree | 1d3dc27123440a6745c85bc6ae8265da0891a56b /absl/time | |
parent | 7a64d73e1ef61b15971f8cc90876a5128729b0d4 (diff) |
Changes imported from Abseil "staging" branch:
- 43853019b439efb32c79d5d50e24508588e1bbe0 Undo the not applying qualifications to absl types in enc... by Derek Mauro <dmauro@google.com> - 06d62a10621c9864279ee57097069cfe3cb7b42a fix capitalization by Abseil Team <absl-team@google.com> - 22adbfee340bb452ba38b68975ade6f072859c4a Fix indices in str_split.h comments. by Derek Mauro <dmauro@google.com> - ae5143a559ad8633a78cd76620e30a781006d088 Fix the inconsistent licenses directives in the BUILD fil... by Derek Mauro <dmauro@google.com> - 0a76a3653b2ecfdad433d3e2f5b651c4ecdcf74b Remove strip.cc, fastmem.h, and fastmem_test.cc from the ... by Derek Mauro <dmauro@google.com> - 77908cfce5927aabca1f8d62481106f22cfc1936 Internal change. by Derek Mauro <dmauro@google.com> - d3277b4171f37e22ab346becb5e295c36c7a0219 Be consistent in (not) applying qualifications for enclos... by Abseil Team <absl-team@google.com> - 9ec7f8164e7d6a5f64288a7360a346628393cc50 Add std:: qualification to isnan and isinf in duration_te... by Derek Mauro <dmauro@google.com> - 9f7c87d7764ddba05286fabca1f4f15285f3250a Fix typos in string_view comments. by Abseil Team <absl-team@google.com> - 281860804f8053143d969b99876e3dbc6deb1236 Fix typo in container.h docs. by Abseil Team <absl-team@google.com> - 0b0a9388c7a9d7f72349d44b5b46132f45bde56c Add bazel-* symlinks to gitignore. by Michael Pratt <mpratt@google.com> GitOrigin-RevId: 43853019b439efb32c79d5d50e24508588e1bbe0 Change-Id: I9e74a5430816a34ecf1acb86486ed3b0bd12a1d6
Diffstat (limited to 'absl/time')
-rw-r--r-- | absl/time/duration_test.cc | 24 | ||||
-rw-r--r-- | absl/time/time.cc | 6 | ||||
-rw-r--r-- | absl/time/time.h | 73 |
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_; } |