diff -r 40c07de877ab src/hotspot/share/runtime/os.cpp --- a/src/hotspot/share/runtime/os.cpp Mon Jul 27 10:56:51 2020 +0200 +++ b/src/hotspot/share/runtime/os.cpp Wed Jul 29 21:56:03 2020 +0200 @@ -89,15 +89,32 @@ DEBUG_ONLY(bool os::_mutex_init_done = false;) static time_t get_timezone(const struct tm* time_struct) { + // seconds to add to local time to get UTC + time_t offset; + #if defined(_ALLBSD_SOURCE) - return time_struct->tm_gmtoff; + offset = -(time_struct->tm_gmtoff); #elif defined(_WINDOWS) long zone; _get_timezone(&zone); - return static_cast(zone); + offset = static_cast(zone); #else - return timezone; + offset = timezone; #endif + +// tm_gmtoff already includes adjustment for daylight saving +#if !defined(_ALLBSD_SOURCE) + // 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; + if (time_struct->tm_isdst > 0) { + offset = offset - seconds_per_hour; + } +#endif + + return offset; } int os::snprintf(char* buf, size_t len, const char* fmt, ...) { @@ -152,17 +169,7 @@ return NULL; } } - const time_t zone = get_timezone(&time_struct); - - // 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; - } + time_t UTC_to_local = get_timezone(&time_struct); // No offset when dealing with UTC if (utc) { @@ -183,6 +190,9 @@ abs_local_to_UTC = -(abs_local_to_UTC); } // Convert time zone offset seconds to hours and minutes. + 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; const time_t zone_hours = (abs_local_to_UTC / seconds_per_hour); const time_t zone_min = ((abs_local_to_UTC % seconds_per_hour) / seconds_per_minute);