Move cold inline Time and TimeZone helpers out of the header to reduce code size. Moving civil-time conversion helpers, timezone lookup wrappers, and stream formatting out of the header into the implementation file avoids duplicating them across call sites while keeping Duration arithmetic inline. PiperOrigin-RevId: 1005561962
diff --git a/absl/time/time.cc b/absl/time/time.cc index fee9901..1ae8e62 100644 --- a/absl/time/time.cc +++ b/absl/time/time.cc
@@ -508,5 +508,37 @@ return tm; } +Time& Time::operator-=(Duration d) { + rep_ -= d; + return *this; +} + +std::string TimeZone::name() const { return cz_.name(); } + +TimeZone FixedTimeZone(int seconds) { + return TimeZone( + time_internal::cctz::fixed_time_zone(std::chrono::seconds(seconds))); +} + +TimeZone LocalTimeZone() { + return TimeZone(time_internal::cctz::local_time_zone()); +} + +CivilSecond ToCivilSecond(Time t, TimeZone tz) { + return tz.At(t).cs; // already a CivilSecond +} + +CivilMinute ToCivilMinute(Time t, TimeZone tz) { + return CivilMinute(tz.At(t).cs); +} + +CivilHour ToCivilHour(Time t, TimeZone tz) { return CivilHour(tz.At(t).cs); } + +CivilDay ToCivilDay(Time t, TimeZone tz) { return CivilDay(tz.At(t).cs); } + +std::ostream& operator<<(std::ostream& os, Time t) { + return os << FormatTime(t); +} + ABSL_NAMESPACE_END } // namespace absl
diff --git a/absl/time/time.h b/absl/time/time.h index b2bfcb2..3199b22 100644 --- a/absl/time/time.h +++ b/absl/time/time.h
@@ -810,10 +810,7 @@ rep_ += d; return *this; } - Time& operator-=(Duration d) { - rep_ -= d; - return *this; - } + Time& operator-=(Duration d); // Time::Breakdown // @@ -1103,7 +1100,7 @@ explicit operator time_internal::cctz::time_zone() const { return cz_; } - std::string name() const { return cz_.name(); } + std::string name() const; // TimeZone::CivilInfo // @@ -1271,10 +1268,7 @@ // Returns a TimeZone that is a fixed offset (seconds east) from UTC. // Note: If the absolute value of the offset is greater than 24 hours // you'll get UTC (i.e., no offset) instead. -inline TimeZone FixedTimeZone(int seconds) { - return TimeZone( - time_internal::cctz::fixed_time_zone(std::chrono::seconds(seconds))); -} +TimeZone FixedTimeZone(int seconds); // UTCTimeZone() // @@ -1289,9 +1283,7 @@ // no configured local zone. Warning: Be wary of using LocalTimeZone(), // and particularly so in a server process, as the zone configured for the // local machine should be irrelevant. Prefer an explicit zone name. -inline TimeZone LocalTimeZone() { - return TimeZone(time_internal::cctz::local_time_zone()); -} +TimeZone LocalTimeZone(); // ToCivilSecond() // ToCivilMinute() @@ -1307,20 +1299,10 @@ // absl::Time t = ...; // absl::TimeZone tz = ...; // const auto cd = absl::ToCivilDay(t, tz); -ABSL_ATTRIBUTE_PURE_FUNCTION inline CivilSecond ToCivilSecond(Time t, - TimeZone tz) { - return tz.At(t).cs; // already a CivilSecond -} -ABSL_ATTRIBUTE_PURE_FUNCTION inline CivilMinute ToCivilMinute(Time t, - TimeZone tz) { - return CivilMinute(tz.At(t).cs); -} -ABSL_ATTRIBUTE_PURE_FUNCTION inline CivilHour ToCivilHour(Time t, TimeZone tz) { - return CivilHour(tz.At(t).cs); -} -ABSL_ATTRIBUTE_PURE_FUNCTION inline CivilDay ToCivilDay(Time t, TimeZone tz) { - return CivilDay(tz.At(t).cs); -} +ABSL_ATTRIBUTE_PURE_FUNCTION CivilSecond ToCivilSecond(Time t, TimeZone tz); +ABSL_ATTRIBUTE_PURE_FUNCTION CivilMinute ToCivilMinute(Time t, TimeZone tz); +ABSL_ATTRIBUTE_PURE_FUNCTION CivilHour ToCivilHour(Time t, TimeZone tz); +ABSL_ATTRIBUTE_PURE_FUNCTION CivilDay ToCivilDay(Time t, TimeZone tz); ABSL_ATTRIBUTE_PURE_FUNCTION inline CivilMonth ToCivilMonth(Time t, TimeZone tz) { return CivilMonth(tz.At(t).cs); @@ -1507,9 +1489,7 @@ ABSL_ATTRIBUTE_PURE_FUNCTION std::string FormatTime(Time t); // Output stream operator. -inline std::ostream& operator<<(std::ostream& os, Time t) { - return os << FormatTime(t); -} +std::ostream& operator<<(std::ostream& os, Time t); // Support for StrFormat(), StrCat() etc. template <typename Sink>