Skip to content

Commit

Permalink
Merge pull request #353 from mdedetrich/accept-dash-as-well-as-unders…
Browse files Browse the repository at this point in the history
…core-chronounit

Accept `half-days` for ChronoUnit Argument
  • Loading branch information
bkirwi authored Sep 11, 2021
2 parents 79c6aa5 + 3f11cb9 commit 514e72f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private[decline] abstract class PlatformArguments {

override def read(string: String): ValidatedNel[String, ChronoUnit] =
try {
Validated.valid(ChronoUnit.valueOf(string.toUpperCase))
Validated.valid(ChronoUnit.valueOf(string.toUpperCase.replace('-', '_')))
} catch {
case _: IllegalArgumentException =>
Validated.invalidNel(s"Invalid time unit: $string")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ class PlatformArgumentsSpec extends AnyWordSpec with Matchers with ScalaCheckDri
Argument[ChronoUnit].read(chronoUnit.name().toLowerCase) should equal(Valid(chronoUnit))
}

"parse half-days as a ChronoUnit value" in {
Argument[ChronoUnit].read("half-days") should equal(Valid(ChronoUnit.HALF_DAYS))
}

"return error for invalid ChronoUnit's" in forAll(
Gen.alphaStr.filterNot(x => ChronoUnit.values().map(_.name()).contains(x))
) { invalidChronoUnit =>
Expand Down

0 comments on commit 514e72f

Please sign in to comment.