about summary refs log tree commit diff
path: root/absl/time/internal/cctz/src
diff options
context:
space:
mode:
Diffstat (limited to 'absl/time/internal/cctz/src')
-rw-r--r--absl/time/internal/cctz/src/time_zone_libc.cc2
-rw-r--r--absl/time/internal/cctz/src/time_zone_lookup_test.cc10
2 files changed, 11 insertions, 1 deletions
diff --git a/absl/time/internal/cctz/src/time_zone_libc.cc b/absl/time/internal/cctz/src/time_zone_libc.cc
index 074c8d0a4a40..e35fa18b7733 100644
--- a/absl/time/internal/cctz/src/time_zone_libc.cc
+++ b/absl/time/internal/cctz/src/time_zone_libc.cc
@@ -111,7 +111,7 @@ time_zone::absolute_lookup TimeZoneLibC::BreakTime(
     al.offset = 0;
     al.abbr = "UTC";
   }
-  al.cs = civil_second(tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
+  al.cs = civil_second(tm.tm_year + year_t{1900}, tm.tm_mon + 1, tm.tm_mday,
                        tm.tm_hour, tm.tm_min, tm.tm_sec);
   al.is_dst = tm.tm_isdst > 0;
   return al;
diff --git a/absl/time/internal/cctz/src/time_zone_lookup_test.cc b/absl/time/internal/cctz/src/time_zone_lookup_test.cc
index 551292fb55e0..280c96b4f207 100644
--- a/absl/time/internal/cctz/src/time_zone_lookup_test.cc
+++ b/absl/time/internal/cctz/src/time_zone_lookup_test.cc
@@ -990,6 +990,16 @@ TEST(MakeTime, SysSecondsLimits) {
   EXPECT_EQ(time_point<absl::time_internal::cctz::seconds>::min(), tp);
   tp = convert(civil_second::min(), west);
   EXPECT_EQ(time_point<absl::time_internal::cctz::seconds>::min(), tp);
+
+  // Checks that "tm_year + 1900", as used by the "libc" implementation,
+  // can produce year values beyond the range on an int without overflow.
+#if defined(_WIN32) || defined(_WIN64)
+  // localtime_s() and gmtime_s() don't believe in years past 3000.
+#else
+  const time_zone libc_utc = LoadZone("libc:UTC");
+  tp = convert(civil_year(year_t{2147483648}), libc_utc);
+  EXPECT_EQ("2147483648-01-01T00:00:00+00:00", format(RFC3339, tp, libc_utc));
+#endif
 }
 
 TEST(NextTransition, UTC) {