DateFormatter's ISO patterns use XXX timezone notation (as per SimpleDateFormat's javadoc)
Issue: SPR-14675
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -124,27 +124,19 @@ public class DateFormatterTests {
|
||||
formatter.setTimeZone(UTC);
|
||||
formatter.setIso(ISO.TIME);
|
||||
Date date = getDate(2009, Calendar.JANUARY, 1, 14, 23, 5, 3);
|
||||
assertThat(formatter.print(date, Locale.US), is("14:23:05.003+0000"));
|
||||
assertThat(formatter.parse("14:23:05.003+0000", Locale.US),
|
||||
assertThat(formatter.print(date, Locale.US), is("14:23:05.003Z"));
|
||||
assertThat(formatter.parse("14:23:05.003Z", Locale.US),
|
||||
is(getDate(1970, Calendar.JANUARY, 1, 14, 23, 5, 3)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldParseIsoTimeWithZeros() throws Exception {
|
||||
DateFormatter formatter = new DateFormatter();
|
||||
formatter.setIso(ISO.TIME);
|
||||
Date date = formatter.parse("12:00:00.000-00005", Locale.US);
|
||||
System.out.println(date);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldPrintAndParseISODateTime() throws Exception {
|
||||
DateFormatter formatter = new DateFormatter();
|
||||
formatter.setTimeZone(UTC);
|
||||
formatter.setIso(ISO.DATE_TIME);
|
||||
Date date = getDate(2009, Calendar.JUNE, 1, 14, 23, 5, 3);
|
||||
assertThat(formatter.print(date, Locale.US), is("2009-06-01T14:23:05.003+0000"));
|
||||
assertThat(formatter.parse("2009-06-01T14:23:05.003+0000", Locale.US), is(date));
|
||||
assertThat(formatter.print(date, Locale.US), is("2009-06-01T14:23:05.003Z"));
|
||||
assertThat(formatter.parse("2009-06-01T14:23:05.003Z", Locale.US), is(date));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -201,7 +193,7 @@ public class DateFormatterTests {
|
||||
assertThat("uses pattern",formatter.print(date, Locale.US), is("2009"));
|
||||
|
||||
formatter.setPattern("");
|
||||
assertThat("uses ISO", formatter.print(date, Locale.US), is("2009-06-01T14:23:05.003+0000"));
|
||||
assertThat("uses ISO", formatter.print(date, Locale.US), is("2009-06-01T14:23:05.003Z"));
|
||||
|
||||
formatter.setIso(ISO.NONE);
|
||||
assertThat("uses style pattern", formatter.print(date, Locale.US), is("June 1, 2009"));
|
||||
|
||||
@@ -168,19 +168,19 @@ public class DateFormattingTests {
|
||||
@Test
|
||||
public void testBindISOTime() {
|
||||
MutablePropertyValues propertyValues = new MutablePropertyValues();
|
||||
propertyValues.add("isoTime", "12:00:00.000-0500");
|
||||
propertyValues.add("isoTime", "12:00:00.000-05:00");
|
||||
binder.bind(propertyValues);
|
||||
assertEquals(0, binder.getBindingResult().getErrorCount());
|
||||
assertEquals("17:00:00.000+0000", binder.getBindingResult().getFieldValue("isoTime"));
|
||||
assertEquals("17:00:00.000Z", binder.getBindingResult().getFieldValue("isoTime"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindISODateTime() {
|
||||
MutablePropertyValues propertyValues = new MutablePropertyValues();
|
||||
propertyValues.add("isoDateTime", "2009-10-31T12:00:00.000-0800");
|
||||
propertyValues.add("isoDateTime", "2009-10-31T12:00:00.000-08:00");
|
||||
binder.bind(propertyValues);
|
||||
assertEquals(0, binder.getBindingResult().getErrorCount());
|
||||
assertEquals("2009-10-31T20:00:00.000+0000", binder.getBindingResult().getFieldValue("isoDateTime"));
|
||||
assertEquals("2009-10-31T20:00:00.000Z", binder.getBindingResult().getFieldValue("isoDateTime"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -229,7 +229,7 @@ public class DateFormattingTests {
|
||||
registrar.setFormatter(dateFormatter);
|
||||
setUp(registrar);
|
||||
// This is a format that cannot be parsed by new Date(String)
|
||||
String string = "2009-06-01T14:23:05.003+0000";
|
||||
String string = "2009-06-01T14:23:05.003+00:00";
|
||||
Date date = this.conversionService.convert(string, Date.class);
|
||||
assertNotNull(date);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user