Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
1.6.0
-
None
-
Found to be present in Linux Mint 14 and Solaris 10.
Description
Possibly related issue: AXIS2-5458
The methods convertToDate and convertToDateTime output incorrect values for dates before 1928-01-01. For example,
GIVEN ConverterUtil.convertToDate("1900-01-01")
RESULT is "Sun Dec 31 23:23:24 CST 1899"
GIVEN ConverterUtil.convertToDate("1929-01-01")
RESULT is "Tue Jan 01 00:00:00 CST 1929"
The same issue was observed in convertToDateTime as well.
Note that the local timezone had to be changed to CST to observe the issue. In the local timezone (IST), the bug could not be observed.
-----------------------------------------------------------------------------------------------------------------------------------------------------------
The fix described in AXIS2-5458 did not work, so I had to modify ConverterUtil.convertToDate further and was able to fix this by the following modification. I am not sure whether this will work for all timezones.
public static Date convertToDate(String source) {
// the lexical form of the date is ''? yyyy '' mm '-' dd zzzzzz?
if ((source == null) || source.trim().equals(""))
source = source.trim();
boolean bc = false;
if (source.startsWith("-"))
int year = 0;
int month = 0;
int day = 0;
int timeZoneOffSet = TimeZone.getDefault().getRawOffset();
if (source.length() >= 10) {
//first 10 numbers must give the year
if ((source.charAt(4) != '') || (source.charAt(7) != ''))
year = Integer.parseInt(source.substring(0,4));
month = Integer.parseInt(source.substring(5,7));
day = Integer.parseInt(source.substring(8,10));
if (source.length() > 10) {
String restpart = source.substring(10);
if (restpart.startsWith("Z"))
else if (restpart.startsWith("+") || restpart.startsWith("-")) {
// this is a specific time format string
if (restpart.charAt(3) != ':')
int hours = Integer.parseInt(restpart.substring(1,3));
int minits = Integer.parseInt(restpart.substring(4,6));
timeZoneOffSet = ((hours * 60) + minits) * 60000;
if (restpart.startsWith("-"))
} else
{ throw new RuntimeException("In valid string sufix"); } }
} else
Calendar calendar = Calendar.getInstance();
calendar.clear();
calendar.setLenient(false);
calendar.set(Calendar.YEAR, year);
//xml month stars from the 1 and calendar month is starts with 0
calendar.set(Calendar.MONTH, month - 1);
calendar.set(Calendar.DAY_OF_MONTH, day);
//BEGIN MODIFICATION
if(source.length() >10 )
//END MODIFICATION
calendar.getTimeInMillis();
if (bc)
return calendar.getTime();
}