Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Cannot Reproduce
-
Affects Version/s: 1.3
-
Fix Version/s: None
-
Component/s: Converters
-
Labels:None
Description
Here's a unit test. It fails with the first two of the 5 parameters. I think this is probably a bug in the SimpleDateFormat and/or GregorianCalendar, but you can probably fix it by choosing a time zone and sticking to it when you convert to/from XML.
@RunWith(Parameterized.class)
public class DateFormatTests {
private static final String pattern = "yyyy-MM-dd HH:mm:ss.S z";
final private String input;
final private SimpleDateFormat format;
private XStream xstream = new XStream();
public DateFormatTests(String input)
{ this.format = new SimpleDateFormat(pattern, Locale.UK); format.setTimeZone(TimeZone.getTimeZone("GMT")); this.input = input; }@Test
{ Date date = format.parse(input); String xml = xstream.toXML(date); Date output = (Date) xstream.fromXML(xml); System.err.println(xml + " : " + format.format(output)); assertTrue(xml.contains(input)); }public void testDateFormat() throws Exception
@Parameters
public static List<Object[]> data() {
List<Object[]> params = new ArrayList<Object[]>();
{ "1970-01-01 11:20:34.0 GMT"}// First two fail (in GMT timezone)...
params.add(new Object[]
);
{ "1971-01-01 11:20:34.0 GMT"}params.add(new Object[]
);
{ "1972-01-01 11:20:34.0 GMT"}params.add(new Object[]
);
{ "1973-01-01 11:20:34.0 GMT"}params.add(new Object[]
);
{ "1974-01-01 11:20:34.0 GMT"}params.add(new Object[]
);
return params;
}
}