Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
8250636: iso8601_time returns incorrect offset part on MacOS
Backport-of: 1d480a7
  • Loading branch information
Sergey Nazarkin authored and Yuri Nesterenko committed Dec 11, 2020
1 parent 7a2731e commit cf0e935
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions src/hotspot/share/runtime/os.cpp
Expand Up @@ -94,18 +94,6 @@ void os_init_globals() {
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);
Expand Down Expand Up @@ -158,21 +146,28 @@ char* os::iso8601_time(char* buffer, size_t buffer_length, bool utc) {
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;
}

// No offset when dealing with UTC
if (utc) {
UTC_to_local = 0;
time_t UTC_to_local = 0;
if (!utc) {
#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
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.
Expand Down

1 comment on commit cf0e935

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.