From e1a1cb4b3589664437172e2acdfc7d9eec4195ce Mon Sep 17 00:00:00 2001 From: Matthew de Detrich Date: Thu, 9 Sep 2021 16:38:48 +0200 Subject: [PATCH] Allow ChronoUnitReader to accept `-` (i.e. half-days) --- .../net/ceedubs/ficus/readers/ChronoUnitReader.scala | 2 +- .../ceedubs/ficus/readers/ChronoUnitReaderSpec.scala | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/scala/net/ceedubs/ficus/readers/ChronoUnitReader.scala b/src/main/scala/net/ceedubs/ficus/readers/ChronoUnitReader.scala index 90eaa15..347719a 100644 --- a/src/main/scala/net/ceedubs/ficus/readers/ChronoUnitReader.scala +++ b/src/main/scala/net/ceedubs/ficus/readers/ChronoUnitReader.scala @@ -9,7 +9,7 @@ trait ChronoUnitReader { /** Reads the value at the path `path` in the Config */ override def read(config: Config, path: String): ChronoUnit = - ChronoUnit.valueOf(config.getString(path).toUpperCase) + ChronoUnit.valueOf(config.getString(path).toUpperCase.replace('-', '_')) } } diff --git a/src/test/scala/net/ceedubs/ficus/readers/ChronoUnitReaderSpec.scala b/src/test/scala/net/ceedubs/ficus/readers/ChronoUnitReaderSpec.scala index 0230c67..87a43e3 100644 --- a/src/test/scala/net/ceedubs/ficus/readers/ChronoUnitReaderSpec.scala +++ b/src/test/scala/net/ceedubs/ficus/readers/ChronoUnitReaderSpec.scala @@ -35,4 +35,15 @@ class ChronoUnitReaderSpec extends Spec { chronoUnit should_== expected } + def readChronoUnitHalfDaysDash = { + val cfg = ConfigFactory.parseString(s""" + | foo { + | chrono-unit = "half-days" + | } + """.stripMargin) + val chronoUnit = cfg.as[ChronoUnit]("foo.chrono-unit") + val expected = ChronoUnit.HALF_DAYS + chronoUnit should_== expected + } + }