Hello,
We are facing problems in "Asia/Calcutta" timezone code for specific dates when the DST offset comes out to be non-zero value. The dates were between 01-Jan-1943 and 31-Dec-1945. I have tried jdk version 1.4.2_13 and 1.5+ but it gives the same error in all the cases. I have try installing the updater also on jdk 1.4 installation but that also didnt help.
Here is the code - This is just a pseudo code and there could be logical or syntax problems. This is just to explain the problem :)
public static void main(String[] args) {
DateFormat dateParser = DateFormat.getDateInstance(DateFormat.SHORT);
DateFormat simpleDateFormat = new SimpleDateFormat("mm/dd/yyyy");//.getDateInstance(SimpleDateFormat.LONG);
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("Asia/Calcutta"));
dateParser.setTimeZone(TimeZone.getTimeZone("Asia/Calcutta"));
Date d1 = null;
Date d2 = null;
Date d3 = null;
Date d4 = null;
try {
d1 = dateParser.parse("3/11/1900");
d2 = dateParser.parse("3/11/1944");
d3 = dateParser.parse("3/11/1945");
d4 = dateParser.parse("3/11/1990");
} catch (ParseException e) {
e.printStackTrace();
System.exit(1);
}
_testDate(d1);
_testDate(d2);
_testDate(d3);
_testDate(d4);
}
private static void _testDate(Date d) {
GregorianCalendar cal = new GregorianCalendar();
TimeZone tz = TimeZone.getTimeZone("Asia/Calcutta");
cal.setTimeZone(tz);
cal.setTime(d);
cal.setTimeZone(tz);
int dstOffset = cal.get(Calendar.DST_OFFSET);
int zoneOffset = cal.get(Calendar.ZONE_OFFSET);
System.out.println("Timezone = " + tz.getID());
System.out.println("Date = " + d);
System.out.println("dstOffset from GregorianCalendar = " + dstOffset);
System.out.println("zoneOffset from GregorianCalendar = " + zoneOffset);
// Ask the timezone what the DST offset is for the specified date.
int tzOffset = tz.getOffset(d.getTime());
int tzRawOffset = tz.getRawOffset();
int tzDstOffset = tzOffset - tzRawOffset;
System.out.println("tz.useDaylightTime() = " + tz.useDaylightTime());
System.out.println("tzDstOffset = " + tzDstOffset);
if ((tz.useDaylightTime() == false) && (tzDstOffset != 0)) {
System.err
.println("ERROR non zero DST offset from timezone not consistent with useDaylightTime() of timezone.");
} else {
System.err.println("DST offset from timezone Ok.");
}
}
This is the output from above -
Timezone = Asia/Calcutta
Date = Sat Mar 10 10:06:40 PST 1900
dstOffset from GregorianCalendar = 0
zoneOffset from GregorianCalendar = 21200000
tz.useDaylightTime() = false
tzDstOffset = 1400000
ERROR non zero DST offset from timezone not consistent with useDaylightTime() of timezone.
Timezone = Asia/Calcutta
Date = Fri Mar 10 10:30:00 PDT 1944
dstOffset from GregorianCalendar = 3600000
zoneOffset from GregorianCalendar = 19800000
tz.useDaylightTime() = false
tzDstOffset = 3600000
ERROR non zero DST offset from timezone not consistent with useDaylightTime() of timezone.
Timezone = Asia/Calcutta
Date = Sat Mar 10 10:30:00 PDT 1945
dstOffset from GregorianCalendar = 3600000
zoneOffset from GregorianCalendar = 19800000
tz.useDaylightTime() = false
tzDstOffset = 3600000
ERROR non zero DST offset from timezone not consistent with useDaylightTime() of timezone.
Timezone = Asia/Calcutta
Date = Sat Mar 10 10:30:00 PST 1990
dstOffset from GregorianCalendar = 0
zoneOffset from GregorianCalendar = 19800000
tz.useDaylightTime() = false
tzDstOffset = 0
DST offset from timezone Ok.
Is there any work-around for the same? Any help would be appericated.
Thanks,