Skip to content

Commit cce918b

Browse files
author
Ichiroh Takiguchi
committed
8292899: CustomTzIDCheckDST.java testcase failed on AIX platform
Reviewed-by: andrew Backport-of: 3464019d7e8fe57adc910339c00ba79884c77852
1 parent 47352be commit cce918b

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/java.base/unix/native/libjava/TimeZone_md.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -379,12 +379,11 @@ mapPlatformToJavaTimezone(const char *java_home_dir, const char *tz) {
379379
size_t tz_len = 0;
380380

381381
/* On AIX, the TZ environment variable may end with a comma
382-
* followed by modifier fields. These are ignored here. */
383-
temp_tz = strchr(tz, ',');
384-
tz_len = (temp_tz == NULL) ? strlen(tz) : temp_tz - tz;
385-
tz_buf = (char *)malloc(tz_len + 1);
386-
memcpy(tz_buf, tz, tz_len);
387-
tz_buf[tz_len] = 0;
382+
* followed by modifier fields until early AIX6.1.
383+
* This restriction has been removed from AIX7. */
384+
385+
tz_buf = strdup(tz);
386+
tz_len = strlen(tz_buf);
388387

389388
/* Open tzmappings file, with buffer overrun check */
390389
if ((strlen(java_home_dir) + 15) > PATH_MAX) {
@@ -553,11 +552,22 @@ getGMTOffsetID()
553552
}
554553
#endif
555554

555+
#if defined(_AIX)
556+
// strftime() with "%z" does not return ISO 8601 format by AIX default.
557+
// XPG_SUS_ENV=ON environment variable is required.
558+
// But Hotspot does not support XPG_SUS_ENV=ON.
559+
// Ignore daylight saving settings to calculate current time difference
560+
localtm.tm_isdst = 0;
561+
int gmt_off = (int)(difftime(mktime(&localtm), mktime(&gmt)) / 60.0);
562+
sprintf(buf, (const char *)"GMT%c%02.2d:%02.2d",
563+
gmt_off < 0 ? '-' : '+' , abs(gmt_off / 60), gmt_off % 60);
564+
#else
556565
if (strftime(offset, 6, "%z", &localtm) != 5) {
557566
return strdup("GMT");
558567
}
559568

560569
sprintf(buf, (const char *)"GMT%c%c%c:%c%c", offset[0], offset[1], offset[2],
561570
offset[3], offset[4]);
571+
#endif
562572
return strdup(buf);
563573
}

0 commit comments

Comments
 (0)