Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
9230ea4a
Commit
9230ea4a
authored
Jun 30, 2020
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Support iso-offset for date-time and time formatting with MVC"
See gh-21630
parent
c3b1172a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
13 deletions
+30
-13
DateTimeFormatters.java
...ork/boot/autoconfigure/web/format/DateTimeFormatters.java
+1
-1
additional-spring-configuration-metadata.json
...es/META-INF/additional-spring-configuration-metadata.json
+4
-4
WebConversionServiceTests.java
...t/autoconfigure/web/format/WebConversionServiceTests.java
+25
-8
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/format/DateTimeFormatters.java
View file @
9230ea4a
...
@@ -107,7 +107,7 @@ public class DateTimeFormatters {
...
@@ -107,7 +107,7 @@ public class DateTimeFormatters {
}
}
private
static
boolean
isIsoOffset
(
String
pattern
)
{
private
static
boolean
isIsoOffset
(
String
pattern
)
{
return
"isooffset"
.
equalsIgnoreCase
(
pattern
);
return
"isooffset"
.
equalsIgnoreCase
(
pattern
)
||
"iso-offset"
.
equalsIgnoreCase
(
pattern
)
;
}
}
}
}
spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json
View file @
9230ea4a
...
@@ -1966,8 +1966,8 @@
...
@@ -1966,8 +1966,8 @@
"description"
:
"ISO-8601 extended local date-time format."
"description"
:
"ISO-8601 extended local date-time format."
},
},
{
{
"value"
:
"isooffset"
,
"value"
:
"iso
-
offset"
,
"description"
:
"ISO
Offset local
date-time format."
"description"
:
"ISO
offset
date-time format."
}
}
],
],
"providers"
:
[
"providers"
:
[
...
@@ -1988,8 +1988,8 @@
...
@@ -1988,8 +1988,8 @@
"description"
:
"ISO-8601 extended local time format"
"description"
:
"ISO-8601 extended local time format"
},
},
{
{
"value"
:
"isooffset"
,
"value"
:
"iso
-
offset"
,
"description"
:
"ISO
Offset local
time format."
"description"
:
"ISO
offset
time format."
}
}
],
],
"providers"
:
[
"providers"
:
[
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/format/WebConversionServiceTests.java
View file @
9230ea4a
...
@@ -80,15 +80,23 @@ class WebConversionServiceTests {
...
@@ -80,15 +80,23 @@ class WebConversionServiceTests {
void
isoTimeFormat
()
{
void
isoTimeFormat
()
{
WebConversionService
conversionService
=
new
WebConversionService
(
new
DateTimeFormatters
().
timeFormat
(
"iso"
));
WebConversionService
conversionService
=
new
WebConversionService
(
new
DateTimeFormatters
().
timeFormat
(
"iso"
));
LocalTime
time
=
LocalTime
.
of
(
12
,
45
,
23
);
LocalTime
time
=
LocalTime
.
of
(
12
,
45
,
23
);
System
.
out
.
println
(
conversionService
.
convert
(
time
,
String
.
class
));
assertThat
(
conversionService
.
convert
(
time
,
String
.
class
))
assertThat
(
conversionService
.
convert
(
time
,
String
.
class
))
.
isEqualTo
(
DateTimeFormatter
.
ISO_LOCAL_TIME
.
format
(
time
));
.
isEqualTo
(
DateTimeFormatter
.
ISO_LOCAL_TIME
.
format
(
time
));
}
}
@Test
@Test
void
isoOffsetTimeFormat
()
{
void
isoOffsetTimeFormat
()
{
WebConversionService
conversionService
=
new
WebConversionService
(
new
DateTimeFormatters
().
timeFormat
(
"isooffset"
));
isoOffsetTimeFormat
(
new
DateTimeFormatters
().
timeFormat
(
"isooffset"
));
OffsetTime
offsetTime
=
OffsetTime
.
of
(
LocalTime
.
of
(
12
,
45
,
23
),
ZoneOffset
.
ofHoursMinutes
(
1
,
30
));
}
@Test
void
hyphenatedIsoOffsetTimeFormat
()
{
isoOffsetTimeFormat
(
new
DateTimeFormatters
().
timeFormat
(
"iso-offset"
));
}
private
void
isoOffsetTimeFormat
(
DateTimeFormatters
formatters
)
{
WebConversionService
conversionService
=
new
WebConversionService
(
formatters
);
OffsetTime
offsetTime
=
OffsetTime
.
of
(
LocalTime
.
of
(
12
,
45
,
23
),
ZoneOffset
.
ofHoursMinutes
(
1
,
30
));
assertThat
(
conversionService
.
convert
(
offsetTime
,
String
.
class
))
assertThat
(
conversionService
.
convert
(
offsetTime
,
String
.
class
))
.
isEqualTo
(
DateTimeFormatter
.
ISO_OFFSET_TIME
.
format
(
offsetTime
));
.
isEqualTo
(
DateTimeFormatter
.
ISO_OFFSET_TIME
.
format
(
offsetTime
));
}
}
...
@@ -120,13 +128,22 @@ class WebConversionServiceTests {
...
@@ -120,13 +128,22 @@ class WebConversionServiceTests {
@Test
@Test
void
isoOffsetDateTimeFormat
()
{
void
isoOffsetDateTimeFormat
()
{
WebConversionService
conversionService
=
new
WebConversionService
(
isoOffsetDateTimeFormat
(
new
DateTimeFormatters
().
dateTimeFormat
(
"isooffset"
));
new
DateTimeFormatters
().
dateTimeFormat
(
"isooffset"
));
}
OffsetDateTime
offsetdate
=
OffsetDateTime
.
of
(
LocalDate
.
of
(
2020
,
4
,
26
),
LocalTime
.
of
(
12
,
45
,
23
),
ZoneOffset
.
ofHoursMinutes
(
1
,
30
));
@Test
void
hyphenatedIsoOffsetDateTimeFormat
()
{
isoOffsetDateTimeFormat
(
new
DateTimeFormatters
().
dateTimeFormat
(
"iso-offset"
));
}
private
void
isoOffsetDateTimeFormat
(
DateTimeFormatters
formatters
)
{
WebConversionService
conversionService
=
new
WebConversionService
(
formatters
);
OffsetDateTime
offsetdate
=
OffsetDateTime
.
of
(
LocalDate
.
of
(
2020
,
4
,
26
),
LocalTime
.
of
(
12
,
45
,
23
),
ZoneOffset
.
ofHoursMinutes
(
1
,
30
));
assertThat
(
conversionService
.
convert
(
offsetdate
,
String
.
class
))
assertThat
(
conversionService
.
convert
(
offsetdate
,
String
.
class
))
.
isEqualTo
(
DateTimeFormatter
.
ISO_OFFSET_DATE_TIME
.
format
(
offsetdate
));
.
isEqualTo
(
DateTimeFormatter
.
ISO_OFFSET_DATE_TIME
.
format
(
offsetdate
));
}
}
@Test
@Test
void
customDateTimeFormat
()
{
void
customDateTimeFormat
()
{
WebConversionService
conversionService
=
new
WebConversionService
(
WebConversionService
conversionService
=
new
WebConversionService
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment