changeset 9352:46bd8a39ef9c

8250636: iso8601_time returns incorrect offset part on MacOS Reviewed-by: phh, andrew
author snazarki
date Mon, 10 Aug 2020 11:25:38 +0300
parents 812256bab2b6
children 1df9d5db32db
files src/share/vm/runtime/os.cpp
diffstat 1 files changed, 16 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/runtime/os.cpp	Tue Mar 19 12:29:40 2019 -0400
+++ b/src/share/vm/runtime/os.cpp	Mon Aug 10 11:25:38 2020 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -96,18 +96,6 @@
   os::init_globals();
 }
 
-static time_t get_timezone(const struct tm* time_struct) {
-#if defined(_ALLBSD_SOURCE)
-  return time_struct->tm_gmtoff;
-#elif defined(_WINDOWS)
-  long zone;
-  _get_timezone(&zone);
-  return static_cast<time_t>(zone);
-#else
-  return timezone;
-#endif
-}
-
 int os::snprintf(char* buf, size_t len, const char* fmt, ...) {
   va_list args;
   va_start(args, fmt);
@@ -154,17 +142,27 @@
     assert(false, "Failed localtime_pd");
     return NULL;
   }
-  const time_t zone = get_timezone(&time_struct);
+
+  const time_t seconds_per_minute = 60;
+  const time_t minutes_per_hour = 60;
+  const time_t seconds_per_hour = seconds_per_minute * minutes_per_hour;
+
+  time_t UTC_to_local = 0;
+#if defined(_WINDOWS)
+  long zone;
+  _get_timezone(&zone);
+  UTC_to_local = static_cast<time_t>(zone);
 
   // If daylight savings time is in effect,
   // we are 1 hour East of our time zone
-  const time_t seconds_per_minute = 60;
-  const time_t minutes_per_hour = 60;
-  const time_t seconds_per_hour = seconds_per_minute * minutes_per_hour;
-  time_t UTC_to_local = zone;
   if (time_struct.tm_isdst > 0) {
     UTC_to_local = UTC_to_local - seconds_per_hour;
   }
+#else
+  // tm_gmtoff already includes adjustment for daylight saving
+  UTC_to_local = -(time_struct.tm_gmtoff);
+#endif
+
   // Compute the time zone offset.
   //    localtime_pd() sets timezone to the difference (in seconds)
   //    between UTC and and local time.