Skip to content

Commit 1c98bf1

Browse files
committed
Parse duration as days
1 parent 4b50422 commit 1c98bf1

File tree

4 files changed

+7
-3
lines changed

4 files changed

+7
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
build
33
.gradle
44
!gradle/wrapper/gradle-wrapper.jar
5+
.kotlin
56

67
# IntelliJ
78
out

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-all.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

src/main/java/com/coditory/quark/config/DurationParser.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import java.util.regex.Pattern;
77

88
class DurationParser {
9-
private static final Pattern pattern = Pattern.compile("\\d+(\\.\\d+)? *(ms|s|m|h)");
9+
private static final Pattern pattern = Pattern.compile("\\d+(\\.\\d+)? *(ms|s|m|h|d)");
1010

1111
static Duration parseDuration(String value) {
1212
if (value.startsWith("-P") || value.startsWith("P")) {
@@ -20,6 +20,9 @@ static Duration parseDuration(String value) {
2020
if (unit.equals("MS")) {
2121
unit = "S";
2222
durationNumber = durationNumber / 1000;
23+
} else if (unit.equals("D")) {
24+
unit = "H";
25+
durationNumber = durationNumber * 24;
2326
}
2427
return durationNumber % 1 == 0
2528
? durationParse("PT" + (int) durationNumber + unit)

src/test/groovy/com/coditory/quark/config/parsing/DurationParsingSpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class DurationParsingSpec extends Specification {
2929
"1.5s" || Duration.parse("PT1.5S")
3030
"1m" || Duration.parse("PT1M")
3131
"2h" || Duration.parse("PT2H")
32+
"2d" || Duration.parse("PT48H")
3233
}
3334

3435
@Unroll
@@ -40,7 +41,6 @@ class DurationParsingSpec extends Specification {
4041
where:
4142
value << [
4243
"1.5m",
43-
"1d",
4444
"10.5mss",
4545
"1.0.5ms"
4646
]

0 commit comments

Comments
 (0)