Skip to content

Commit 2dd2ca8

Browse files
committed
Merge branch '2.7.x'
Closes gh-32232
2 parents 0789dd0 + 2003cfd commit 2dd2ca8

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/DurationStyle.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2022 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.
@@ -29,6 +29,7 @@
2929
* Duration format styles.
3030
*
3131
* @author Phillip Webb
32+
* @author Valentine Wu
3233
* @since 2.0.0
3334
*/
3435
public enum DurationStyle {
@@ -62,7 +63,7 @@ public String print(Duration value, ChronoUnit unit) {
6263
/**
6364
* ISO-8601 formatting.
6465
*/
65-
ISO8601("^[+-]?P.*$") {
66+
ISO8601("^[+-]?[pP].*$") {
6667

6768
@Override
6869
public Duration parse(String value, ChronoUnit unit) {

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/convert/DurationStyleTests.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2022 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.
@@ -28,6 +28,7 @@
2828
* Tests for {@link DurationStyle}.
2929
*
3030
* @author Phillip Webb
31+
* @author Valentine Wu
3132
*/
3233
class DurationStyleTests {
3334

@@ -39,6 +40,7 @@ void detectAndParseWhenValueIsNullShouldThrowException() {
3940

4041
@Test
4142
void detectAndParseWhenIso8601ShouldReturnDuration() {
43+
assertThat(DurationStyle.detectAndParse("pt20.345s")).isEqualTo(Duration.parse("pt20.345s"));
4244
assertThat(DurationStyle.detectAndParse("PT20.345S")).isEqualTo(Duration.parse("PT20.345S"));
4345
assertThat(DurationStyle.detectAndParse("PT15M")).isEqualTo(Duration.parse("PT15M"));
4446
assertThat(DurationStyle.detectAndParse("+PT15M")).isEqualTo(Duration.parse("PT15M"));
@@ -143,6 +145,7 @@ void detectWhenSimpleShouldReturnSimple() {
143145

144146
@Test
145147
void detectWhenIso8601ShouldReturnIso8601() {
148+
assertThat(DurationStyle.detect("pt20.345s")).isEqualTo(DurationStyle.ISO8601);
146149
assertThat(DurationStyle.detect("PT20.345S")).isEqualTo(DurationStyle.ISO8601);
147150
assertThat(DurationStyle.detect("PT15M")).isEqualTo(DurationStyle.ISO8601);
148151
assertThat(DurationStyle.detect("+PT15M")).isEqualTo(DurationStyle.ISO8601);
@@ -161,6 +164,7 @@ void detectWhenUnknownShouldThrowException() {
161164

162165
@Test
163166
void parseIso8601ShouldParse() {
167+
assertThat(DurationStyle.ISO8601.parse("pt20.345s")).isEqualTo(Duration.parse("pt20.345s"));
164168
assertThat(DurationStyle.ISO8601.parse("PT20.345S")).isEqualTo(Duration.parse("PT20.345S"));
165169
assertThat(DurationStyle.ISO8601.parse("PT15M")).isEqualTo(Duration.parse("PT15M"));
166170
assertThat(DurationStyle.ISO8601.parse("+PT15M")).isEqualTo(Duration.parse("PT15M"));
@@ -173,6 +177,7 @@ void parseIso8601ShouldParse() {
173177

174178
@Test
175179
void parseIso8601WithUnitShouldIgnoreUnit() {
180+
assertThat(DurationStyle.ISO8601.parse("pt20.345s", ChronoUnit.SECONDS)).isEqualTo(Duration.parse("pt20.345s"));
176181
assertThat(DurationStyle.ISO8601.parse("PT20.345S", ChronoUnit.SECONDS)).isEqualTo(Duration.parse("PT20.345S"));
177182
assertThat(DurationStyle.ISO8601.parse("PT15M", ChronoUnit.SECONDS)).isEqualTo(Duration.parse("PT15M"));
178183
assertThat(DurationStyle.ISO8601.parse("+PT15M", ChronoUnit.SECONDS)).isEqualTo(Duration.parse("PT15M"));

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/convert/StringToDurationConverterTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class StringToDurationConverterTests {
3838

3939
@ConversionServiceTest
4040
void convertWhenIso8601ShouldReturnDuration(ConversionService conversionService) {
41+
assertThat(convert(conversionService, "pt20.345s")).isEqualTo(Duration.parse("pt20.345s"));
4142
assertThat(convert(conversionService, "PT20.345S")).isEqualTo(Duration.parse("PT20.345S"));
4243
assertThat(convert(conversionService, "PT15M")).isEqualTo(Duration.parse("PT15M"));
4344
assertThat(convert(conversionService, "+PT15M")).isEqualTo(Duration.parse("PT15M"));

0 commit comments

Comments
 (0)