Skip to content

Commit cfdceba

Browse files
committed
Merge branch '2.7.x'
Closes gh-32245
2 parents 59ecc96 + 9ef067d commit cfdceba

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-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
*
3030
* @author Eddú Meléndez
3131
* @author Edson Chávez
32+
* @author Valentine Wu
3233
* @since 2.3.0
3334
* @see Period
3435
*/
@@ -102,7 +103,7 @@ private void append(StringBuilder result, Period value, Unit unit) {
102103
/**
103104
* ISO-8601 formatting.
104105
*/
105-
ISO8601("^[+-]?P.*$", 0) {
106+
ISO8601("^[+-]?P.*$", Pattern.CASE_INSENSITIVE) {
106107

107108
@Override
108109
public Period parse(String value, ChronoUnit unit) {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 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
*
3030
* @author Eddú Meléndez
3131
* @author Edson Chávez
32+
* @author Valentine Wu
3233
*/
3334
class PeriodStyleTests {
3435

@@ -40,6 +41,7 @@ void detectAndParseWhenValueIsNullShouldThrowException() {
4041

4142
@Test
4243
void detectAndParseWhenIso8601ShouldReturnPeriod() {
44+
assertThat(PeriodStyle.detectAndParse("p15m")).isEqualTo(Period.parse("p15m"));
4345
assertThat(PeriodStyle.detectAndParse("P15M")).isEqualTo(Period.parse("P15M"));
4446
assertThat(PeriodStyle.detectAndParse("-P15M")).isEqualTo(Period.parse("P-15M"));
4547
assertThat(PeriodStyle.detectAndParse("+P15M")).isEqualTo(Period.parse("P15M"));
@@ -123,6 +125,7 @@ void detectWhenSimpleShouldReturnSimple() {
123125

124126
@Test
125127
void detectWhenIso8601ShouldReturnIso8601() {
128+
assertThat(PeriodStyle.detect("p20")).isEqualTo(PeriodStyle.ISO8601);
126129
assertThat(PeriodStyle.detect("P20")).isEqualTo(PeriodStyle.ISO8601);
127130
assertThat(PeriodStyle.detect("-P15M")).isEqualTo(PeriodStyle.ISO8601);
128131
assertThat(PeriodStyle.detect("+P15M")).isEqualTo(PeriodStyle.ISO8601);
@@ -140,6 +143,7 @@ void detectWhenUnknownShouldThrowException() {
140143

141144
@Test
142145
void parseIso8601ShouldParse() {
146+
assertThat(PeriodStyle.ISO8601.parse("p20d")).isEqualTo(Period.parse("p20d"));
143147
assertThat(PeriodStyle.ISO8601.parse("P20D")).isEqualTo(Period.parse("P20D"));
144148
assertThat(PeriodStyle.ISO8601.parse("P15M")).isEqualTo(Period.parse("P15M"));
145149
assertThat(PeriodStyle.ISO8601.parse("+P15M")).isEqualTo(Period.parse("P15M"));
@@ -151,6 +155,7 @@ void parseIso8601ShouldParse() {
151155

152156
@Test
153157
void parseIso8601WithUnitShouldIgnoreUnit() {
158+
assertThat(PeriodStyle.ISO8601.parse("p20d", ChronoUnit.SECONDS)).isEqualTo(Period.parse("p20d"));
154159
assertThat(PeriodStyle.ISO8601.parse("P20D", ChronoUnit.SECONDS)).isEqualTo(Period.parse("P20D"));
155160
assertThat(PeriodStyle.ISO8601.parse("P15M", ChronoUnit.SECONDS)).isEqualTo(Period.parse("P15M"));
156161
assertThat(PeriodStyle.ISO8601.parse("+P15M", ChronoUnit.SECONDS)).isEqualTo(Period.parse("P15M"));

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 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.
@@ -37,6 +37,7 @@ class StringToPeriodConverterTests {
3737

3838
@ConversionServiceTest
3939
void convertWhenIso8601ShouldReturnPeriod(ConversionService conversionService) {
40+
assertThat(convert(conversionService, "p2y")).isEqualTo(Period.parse("p2y"));
4041
assertThat(convert(conversionService, "P2Y")).isEqualTo(Period.parse("P2Y"));
4142
assertThat(convert(conversionService, "P3M")).isEqualTo(Period.parse("P3M"));
4243
assertThat(convert(conversionService, "P4W")).isEqualTo(Period.parse("P4W"));

0 commit comments

Comments
 (0)