Skip to content

Commit bb94ba6

Browse files
committed
DateFormatter's ISO patterns use XXX timezone notation (as per SimpleDateFormat's javadoc)
Issue: SPR-14675
1 parent 64d6561 commit bb94ba6

File tree

3 files changed

+13
-21
lines changed

3 files changed

+13
-21
lines changed

spring-context/src/main/java/org/springframework/format/datetime/DateFormatter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ public class DateFormatter implements Formatter<Date> {
4949
static {
5050
Map<ISO, String> formats = new HashMap<>(4);
5151
formats.put(ISO.DATE, "yyyy-MM-dd");
52-
formats.put(ISO.TIME, "HH:mm:ss.SSSZ");
53-
formats.put(ISO.DATE_TIME, "yyyy-MM-dd'T'HH:mm:ss.SSSZ");
52+
formats.put(ISO.TIME, "HH:mm:ss.SSSXXX");
53+
formats.put(ISO.DATE_TIME, "yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
5454
ISO_PATTERNS = Collections.unmodifiableMap(formats);
5555
}
5656

spring-context/src/test/java/org/springframework/format/datetime/DateFormatterTests.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -124,27 +124,19 @@ public void shouldPrintAndParseISOTime() throws Exception {
124124
formatter.setTimeZone(UTC);
125125
formatter.setIso(ISO.TIME);
126126
Date date = getDate(2009, Calendar.JANUARY, 1, 14, 23, 5, 3);
127-
assertThat(formatter.print(date, Locale.US), is("14:23:05.003+0000"));
128-
assertThat(formatter.parse("14:23:05.003+0000", Locale.US),
127+
assertThat(formatter.print(date, Locale.US), is("14:23:05.003Z"));
128+
assertThat(formatter.parse("14:23:05.003Z", Locale.US),
129129
is(getDate(1970, Calendar.JANUARY, 1, 14, 23, 5, 3)));
130130
}
131131

132-
@Test
133-
public void shouldParseIsoTimeWithZeros() throws Exception {
134-
DateFormatter formatter = new DateFormatter();
135-
formatter.setIso(ISO.TIME);
136-
Date date = formatter.parse("12:00:00.000-00005", Locale.US);
137-
System.out.println(date);
138-
}
139-
140132
@Test
141133
public void shouldPrintAndParseISODateTime() throws Exception {
142134
DateFormatter formatter = new DateFormatter();
143135
formatter.setTimeZone(UTC);
144136
formatter.setIso(ISO.DATE_TIME);
145137
Date date = getDate(2009, Calendar.JUNE, 1, 14, 23, 5, 3);
146-
assertThat(formatter.print(date, Locale.US), is("2009-06-01T14:23:05.003+0000"));
147-
assertThat(formatter.parse("2009-06-01T14:23:05.003+0000", Locale.US), is(date));
138+
assertThat(formatter.print(date, Locale.US), is("2009-06-01T14:23:05.003Z"));
139+
assertThat(formatter.parse("2009-06-01T14:23:05.003Z", Locale.US), is(date));
148140
}
149141

150142
@Test
@@ -201,7 +193,7 @@ public void shouldUseCorrectOrder() throws Exception {
201193
assertThat("uses pattern",formatter.print(date, Locale.US), is("2009"));
202194

203195
formatter.setPattern("");
204-
assertThat("uses ISO", formatter.print(date, Locale.US), is("2009-06-01T14:23:05.003+0000"));
196+
assertThat("uses ISO", formatter.print(date, Locale.US), is("2009-06-01T14:23:05.003Z"));
205197

206198
formatter.setIso(ISO.NONE);
207199
assertThat("uses style pattern", formatter.print(date, Locale.US), is("June 1, 2009"));

spring-context/src/test/java/org/springframework/format/datetime/DateFormattingTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,19 +168,19 @@ public void testBindISODate() {
168168
@Test
169169
public void testBindISOTime() {
170170
MutablePropertyValues propertyValues = new MutablePropertyValues();
171-
propertyValues.add("isoTime", "12:00:00.000-0500");
171+
propertyValues.add("isoTime", "12:00:00.000-05:00");
172172
binder.bind(propertyValues);
173173
assertEquals(0, binder.getBindingResult().getErrorCount());
174-
assertEquals("17:00:00.000+0000", binder.getBindingResult().getFieldValue("isoTime"));
174+
assertEquals("17:00:00.000Z", binder.getBindingResult().getFieldValue("isoTime"));
175175
}
176176

177177
@Test
178178
public void testBindISODateTime() {
179179
MutablePropertyValues propertyValues = new MutablePropertyValues();
180-
propertyValues.add("isoDateTime", "2009-10-31T12:00:00.000-0800");
180+
propertyValues.add("isoDateTime", "2009-10-31T12:00:00.000-08:00");
181181
binder.bind(propertyValues);
182182
assertEquals(0, binder.getBindingResult().getErrorCount());
183-
assertEquals("2009-10-31T20:00:00.000+0000", binder.getBindingResult().getFieldValue("isoDateTime"));
183+
assertEquals("2009-10-31T20:00:00.000Z", binder.getBindingResult().getFieldValue("isoDateTime"));
184184
}
185185

186186
@Test
@@ -229,7 +229,7 @@ public void stringToDateWithGlobalFormat() throws Exception {
229229
registrar.setFormatter(dateFormatter);
230230
setUp(registrar);
231231
// This is a format that cannot be parsed by new Date(String)
232-
String string = "2009-06-01T14:23:05.003+0000";
232+
String string = "2009-06-01T14:23:05.003+00:00";
233233
Date date = this.conversionService.convert(string, Date.class);
234234
assertNotNull(date);
235235
}

0 commit comments

Comments
 (0)