8313813: Field sun.util.calendar.CalendarDate#forceStandardTime is never set

Reviewed-by: aturbanov, naoto
This commit is contained in:
Justin Lu 2023-09-18 22:08:17 +00:00
parent 5308bbbcf8
commit 373e37bf13
3 changed files with 10 additions and 48 deletions

View file

@ -165,31 +165,18 @@ public abstract class AbstractCalendar extends CalendarSystem {
if (date.isNormalized()) { if (date.isNormalized()) {
return ms - date.getZoneOffset(); return ms - date.getZoneOffset();
} }
// adjust time zone and daylight saving // adjust time zone and daylight saving
int[] offsets = new int[2]; // 1) 2:30am during starting-DST transition is
if (date.isStandardTime()) { // interpreted as 3:30am DT
// 1) 2:30am during starting-DST transition is // 2) 5:00pm during DST is interpreted as 5:00pm DT
// intrepreted as 2:30am ST // 3) 1:30am during ending-DST transition is interpreted
// 2) 5:00pm during DST is still interpreted as 5:00pm ST // as 1:30am DT/0:30am ST (before transition)
// 3) 1:30am during ending-DST transition is interpreted if (zi instanceof ZoneInfo zInfo) {
// as 1:30am ST (after transition) // Offset value adjusts accordingly depending on DST status of date
if (zi instanceof ZoneInfo) { zoneOffset = zInfo.getOffsetsByWall(ms, new int[2]);
((ZoneInfo)zi).getOffsetsByStandard(ms, offsets);
zoneOffset = offsets[0];
} else {
zoneOffset = zi.getOffset(ms - zi.getRawOffset());
}
} else { } else {
// 1) 2:30am during starting-DST transition is zoneOffset = zi.getOffset(ms - zi.getRawOffset());
// intrepreted as 3:30am DT
// 2) 5:00pm during DST is intrepreted as 5:00pm DT
// 3) 1:30am during ending-DST transition is interpreted
// as 1:30am DT/0:30am ST (before transition)
if (zi instanceof ZoneInfo) {
zoneOffset = ((ZoneInfo)zi).getOffsetsByWall(ms, offsets);
} else {
zoneOffset = zi.getOffset(ms - zi.getRawOffset());
}
} }
} }
ms -= zoneOffset; ms -= zoneOffset;

View file

@ -26,7 +26,6 @@
package sun.util.calendar; package sun.util.calendar;
import java.lang.Cloneable; import java.lang.Cloneable;
import java.util.Locale;
import java.util.TimeZone; import java.util.TimeZone;
/** /**
@ -82,9 +81,6 @@ public abstract class CalendarDate implements Cloneable {
private TimeZone zoneinfo; private TimeZone zoneinfo;
private int zoneOffset; private int zoneOffset;
private int daylightSaving; private int daylightSaving;
private boolean forceStandardTime;
private Locale locale;
protected CalendarDate() { protected CalendarDate() {
this(TimeZone.getDefault()); this(TimeZone.getDefault());
@ -293,22 +289,10 @@ public abstract class CalendarDate implements Cloneable {
return normalized; return normalized;
} }
public boolean isStandardTime() {
return forceStandardTime;
}
public boolean isDaylightTime() { public boolean isDaylightTime() {
if (isStandardTime()) {
return false;
}
return daylightSaving != 0; return daylightSaving != 0;
} }
protected void setLocale(Locale loc) {
locale = loc;
}
public TimeZone getZone() { public TimeZone getZone() {
return zoneinfo; return zoneinfo;
} }

View file

@ -25,7 +25,6 @@
package sun.util.calendar; package sun.util.calendar;
import java.util.Locale;
import java.util.TimeZone; import java.util.TimeZone;
class ImmutableGregorianDate extends BaseCalendar.Date { class ImmutableGregorianDate extends BaseCalendar.Date {
@ -146,18 +145,10 @@ class ImmutableGregorianDate extends BaseCalendar.Date {
return date.isNormalized(); return date.isNormalized();
} }
public boolean isStandardTime() {
return date.isStandardTime();
}
public boolean isDaylightTime() { public boolean isDaylightTime() {
return date.isDaylightTime(); return date.isDaylightTime();
} }
protected void setLocale(Locale loc) {
unsupported();
}
public TimeZone getZone() { public TimeZone getZone() {
return date.getZone(); return date.getZone();
} }