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/civil_time.h12
-rw-r--r--absl/time/civil_time_test.cc12
-rw-r--r--absl/time/internal/cctz/include/cctz/civil_time_detail.h14
-rw-r--r--absl/time/internal/cctz/src/time_zone_info.cc4
-rw-r--r--absl/time/time.cc5
-rw-r--r--absl/time/time_test.cc16
6 files changed, 36 insertions, 27 deletions
diff --git a/absl/time/civil_time.h b/absl/time/civil_time.h
index 6bb7eec74157..beaf7d898551 100644
--- a/absl/time/civil_time.h
+++ b/absl/time/civil_time.h
@@ -370,15 +370,15 @@ using Weekday = time_internal::cctz::weekday;
 
 // GetWeekday()
 //
-// Returns the absl::Weekday for the given absl::CivilDay.
+// Returns the absl::Weekday for the given (realigned) civil-time value.
 //
 // Example:
 //
 //   absl::CivilDay a(2015, 8, 13);
 //   absl::Weekday wd = absl::GetWeekday(a);  // wd == absl::Weekday::thursday
 //
-inline Weekday GetWeekday(CivilDay cd) {
-  return time_internal::cctz::get_weekday(cd);
+inline Weekday GetWeekday(CivilSecond cs) {
+  return time_internal::cctz::get_weekday(cs);
 }
 
 // NextWeekday()
@@ -420,7 +420,7 @@ inline CivilDay PrevWeekday(CivilDay cd, Weekday wd) {
 
 // GetYearDay()
 //
-// Returns the day-of-year for the given absl::CivilDay.
+// Returns the day-of-year for the given (realigned) civil-time value.
 //
 // Example:
 //
@@ -429,8 +429,8 @@ inline CivilDay PrevWeekday(CivilDay cd, Weekday wd) {
 //   absl::CivilDay b(2015, 12, 31);
 //   int yd_dec_31 = absl::GetYearDay(b);  // yd_dec_31 = 365
 //
-inline int GetYearDay(CivilDay cd) {
-  return time_internal::cctz::get_yearday(cd);
+inline int GetYearDay(CivilSecond cs) {
+  return time_internal::cctz::get_yearday(cs);
 }
 
 // FormatCivilTime()
diff --git a/absl/time/civil_time_test.cc b/absl/time/civil_time_test.cc
index 070f0d573823..03cd1f12d563 100644
--- a/absl/time/civil_time_test.cc
+++ b/absl/time/civil_time_test.cc
@@ -616,6 +616,8 @@ TEST(CivilTime, Properties) {
   EXPECT_EQ(4, ss.hour());
   EXPECT_EQ(5, ss.minute());
   EXPECT_EQ(6, ss.second());
+  EXPECT_EQ(absl::Weekday::tuesday, absl::GetWeekday(ss));
+  EXPECT_EQ(34, absl::GetYearDay(ss));
 
   absl::CivilMinute mm(2015, 2, 3, 4, 5, 6);
   EXPECT_EQ(2015, mm.year());
@@ -624,6 +626,8 @@ TEST(CivilTime, Properties) {
   EXPECT_EQ(4, mm.hour());
   EXPECT_EQ(5, mm.minute());
   EXPECT_EQ(0, mm.second());
+  EXPECT_EQ(absl::Weekday::tuesday, absl::GetWeekday(mm));
+  EXPECT_EQ(34, absl::GetYearDay(mm));
 
   absl::CivilHour hh(2015, 2, 3, 4, 5, 6);
   EXPECT_EQ(2015, hh.year());
@@ -632,6 +636,8 @@ TEST(CivilTime, Properties) {
   EXPECT_EQ(4, hh.hour());
   EXPECT_EQ(0, hh.minute());
   EXPECT_EQ(0, hh.second());
+  EXPECT_EQ(absl::Weekday::tuesday, absl::GetWeekday(hh));
+  EXPECT_EQ(34, absl::GetYearDay(hh));
 
   absl::CivilDay d(2015, 2, 3, 4, 5, 6);
   EXPECT_EQ(2015, d.year());
@@ -640,6 +646,8 @@ TEST(CivilTime, Properties) {
   EXPECT_EQ(0, d.hour());
   EXPECT_EQ(0, d.minute());
   EXPECT_EQ(0, d.second());
+  EXPECT_EQ(absl::Weekday::tuesday, absl::GetWeekday(d));
+  EXPECT_EQ(34, absl::GetYearDay(d));
 
   absl::CivilMonth m(2015, 2, 3, 4, 5, 6);
   EXPECT_EQ(2015, m.year());
@@ -648,6 +656,8 @@ TEST(CivilTime, Properties) {
   EXPECT_EQ(0, m.hour());
   EXPECT_EQ(0, m.minute());
   EXPECT_EQ(0, m.second());
+  EXPECT_EQ(absl::Weekday::sunday, absl::GetWeekday(m));
+  EXPECT_EQ(32, absl::GetYearDay(m));
 
   absl::CivilYear y(2015, 2, 3, 4, 5, 6);
   EXPECT_EQ(2015, y.year());
@@ -656,6 +666,8 @@ TEST(CivilTime, Properties) {
   EXPECT_EQ(0, y.hour());
   EXPECT_EQ(0, y.minute());
   EXPECT_EQ(0, y.second());
+  EXPECT_EQ(absl::Weekday::thursday, absl::GetWeekday(y));
+  EXPECT_EQ(1, absl::GetYearDay(y));
 }
 
 TEST(CivilTime, Format) {
diff --git a/absl/time/internal/cctz/include/cctz/civil_time_detail.h b/absl/time/internal/cctz/include/cctz/civil_time_detail.h
index 0dcb1ad46ba2..433078a73097 100644
--- a/absl/time/internal/cctz/include/cctz/civil_time_detail.h
+++ b/absl/time/internal/cctz/include/cctz/civil_time_detail.h
@@ -535,8 +535,7 @@ enum class weekday {
   sunday,
 };
 
-template <typename T>
-CONSTEXPR_F weekday get_weekday(const civil_time<T>& ct) noexcept {
+CONSTEXPR_F weekday get_weekday(const civil_second& cs) noexcept {
   CONSTEXPR_D weekday k_weekday_by_mon_off[13] = {
       weekday::monday,    weekday::tuesday,  weekday::wednesday,
       weekday::thursday,  weekday::friday,   weekday::saturday,
@@ -547,9 +546,9 @@ CONSTEXPR_F weekday get_weekday(const civil_time<T>& ct) noexcept {
   CONSTEXPR_D int k_weekday_offsets[1 + 12] = {
       -1, 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4,
   };
-  year_t wd = 2400 + (ct.year() % 400) - (ct.month() < 3);
+  year_t wd = 2400 + (cs.year() % 400) - (cs.month() < 3);
   wd += wd / 4 - wd / 100 + wd / 400;
-  wd += k_weekday_offsets[ct.month()] + ct.day();
+  wd += k_weekday_offsets[cs.month()] + cs.day();
   return k_weekday_by_mon_off[wd % 7 + 6];
 }
 
@@ -595,13 +594,12 @@ CONSTEXPR_F civil_day prev_weekday(civil_day cd, weekday wd) noexcept {
   }
 }
 
-template <typename T>
-CONSTEXPR_F int get_yearday(const civil_time<T>& ct) noexcept {
+CONSTEXPR_F int get_yearday(const civil_second& cs) noexcept {
   CONSTEXPR_D int k_month_offsets[1 + 12] = {
       -1, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334,
   };
-  const int feb29 = (ct.month() > 2 && impl::is_leap_year(ct.year()));
-  return k_month_offsets[ct.month()] + feb29 + ct.day();
+  const int feb29 = (cs.month() > 2 && impl::is_leap_year(cs.year()));
+  return k_month_offsets[cs.month()] + feb29 + cs.day();
 }
 
 ////////////////////////////////////////////////////////////////////////
diff --git a/absl/time/internal/cctz/src/time_zone_info.cc b/absl/time/internal/cctz/src/time_zone_info.cc
index 184bd434c2d2..72bb3bde8eae 100644
--- a/absl/time/internal/cctz/src/time_zone_info.cc
+++ b/absl/time/internal/cctz/src/time_zone_info.cc
@@ -505,9 +505,9 @@ bool TimeZoneInfo::Load(const std::string& name, ZoneInfoSource* zip) {
   if (tzh.tzh_version[0] != '\0') {
     // Snarf up the NL-enclosed future POSIX spec. Note
     // that version '3' files utilize an extended format.
-    auto get_char = [](ZoneInfoSource* zip) -> int {
+    auto get_char = [](ZoneInfoSource* azip) -> int {
       unsigned char ch;  // all non-EOF results are positive
-      return (zip->Read(&ch, 1) == 1) ? ch : EOF;
+      return (azip->Read(&ch, 1) == 1) ? ch : EOF;
     };
     if (get_char(zip) != '\n')
       return false;
diff --git a/absl/time/time.cc b/absl/time/time.cc
index 338c4523d1b1..6a387bcee61f 100644
--- a/absl/time/time.cc
+++ b/absl/time/time.cc
@@ -457,8 +457,7 @@ struct tm ToTM(absl::Time t, absl::TimeZone tz) {
     tm.tm_year = static_cast<int>(cs.year() - 1900);
   }
 
-  const CivilDay cd(cs);
-  switch (GetWeekday(cd)) {
+  switch (GetWeekday(cs)) {
     case Weekday::sunday:
       tm.tm_wday = 0;
       break;
@@ -481,7 +480,7 @@ struct tm ToTM(absl::Time t, absl::TimeZone tz) {
       tm.tm_wday = 6;
       break;
   }
-  tm.tm_yday = GetYearDay(cd) - 1;
+  tm.tm_yday = GetYearDay(cs) - 1;
   tm.tm_isdst = ci.is_dst ? 1 : 0;
 
   return tm;
diff --git a/absl/time/time_test.cc b/absl/time/time_test.cc
index e2b2f8097021..37af39d99830 100644
--- a/absl/time/time_test.cc
+++ b/absl/time/time_test.cc
@@ -112,7 +112,7 @@ TEST(Time, UnixEpoch) {
   const auto ci = absl::UTCTimeZone().At(absl::UnixEpoch());
   EXPECT_EQ(absl::CivilSecond(1970, 1, 1, 0, 0, 0), ci.cs);
   EXPECT_EQ(absl::ZeroDuration(), ci.subsecond);
-  EXPECT_EQ(absl::Weekday::thursday, absl::GetWeekday(absl::CivilDay(ci.cs)));
+  EXPECT_EQ(absl::Weekday::thursday, absl::GetWeekday(ci.cs));
 }
 
 TEST(Time, Breakdown) {
@@ -123,14 +123,14 @@ TEST(Time, Breakdown) {
   auto ci = tz.At(t);
   EXPECT_CIVIL_INFO(ci, 1969, 12, 31, 19, 0, 0, -18000, false);
   EXPECT_EQ(absl::ZeroDuration(), ci.subsecond);
-  EXPECT_EQ(absl::Weekday::wednesday, absl::GetWeekday(absl::CivilDay(ci.cs)));
+  EXPECT_EQ(absl::Weekday::wednesday, absl::GetWeekday(ci.cs));
 
   // Just before the epoch.
   t -= absl::Nanoseconds(1);
   ci = tz.At(t);
   EXPECT_CIVIL_INFO(ci, 1969, 12, 31, 18, 59, 59, -18000, false);
   EXPECT_EQ(absl::Nanoseconds(999999999), ci.subsecond);
-  EXPECT_EQ(absl::Weekday::wednesday, absl::GetWeekday(absl::CivilDay(ci.cs)));
+  EXPECT_EQ(absl::Weekday::wednesday, absl::GetWeekday(ci.cs));
 
   // Some time later.
   t += absl::Hours(24) * 2735;
@@ -139,7 +139,7 @@ TEST(Time, Breakdown) {
   ci = tz.At(t);
   EXPECT_CIVIL_INFO(ci, 1977, 6, 28, 14, 30, 15, -14400, true);
   EXPECT_EQ(8, ci.subsecond / absl::Nanoseconds(1));
-  EXPECT_EQ(absl::Weekday::tuesday, absl::GetWeekday(absl::CivilDay(ci.cs)));
+  EXPECT_EQ(absl::Weekday::tuesday, absl::GetWeekday(ci.cs));
 }
 
 TEST(Time, AdditiveOperators) {
@@ -979,15 +979,15 @@ TEST(Time, ConversionSaturation) {
   EXPECT_CIVIL_INFO(ci, std::numeric_limits<int64_t>::max(), 12, 31, 23,
                             59, 59, 0, false);
   EXPECT_EQ(absl::InfiniteDuration(), ci.subsecond);
-  EXPECT_EQ(absl::Weekday::thursday, absl::GetWeekday(absl::CivilDay(ci.cs)));
-  EXPECT_EQ(365, absl::GetYearDay(absl::CivilDay(ci.cs)));
+  EXPECT_EQ(absl::Weekday::thursday, absl::GetWeekday(ci.cs));
+  EXPECT_EQ(365, absl::GetYearDay(ci.cs));
   EXPECT_STREQ("-00", ci.zone_abbr);  // artifact of TimeZone::At()
   ci = utc.At(absl::InfinitePast());
   EXPECT_CIVIL_INFO(ci, std::numeric_limits<int64_t>::min(), 1, 1, 0, 0,
                             0, 0, false);
   EXPECT_EQ(-absl::InfiniteDuration(), ci.subsecond);
-  EXPECT_EQ(absl::Weekday::sunday, absl::GetWeekday(absl::CivilDay(ci.cs)));
-  EXPECT_EQ(1, absl::GetYearDay(absl::CivilDay(ci.cs)));
+  EXPECT_EQ(absl::Weekday::sunday, absl::GetWeekday(ci.cs));
+  EXPECT_EQ(1, absl::GetYearDay(ci.cs));
   EXPECT_STREQ("-00", ci.zone_abbr);  // artifact of TimeZone::At()
 
   // Approach the maximal Time value from below.