From ebb526304ecebb561ba5c5f4ff4ce369b303e6e0 Mon Sep 17 00:00:00 2001 From: Alex Wei Date: Fri, 8 Aug 2014 09:57:42 +1000 Subject: [PATCH] Added more duration unit short names for hour, minute and second. --- .../main/java/com/typesafe/config/impl/SimpleConfig.java | 6 +++--- config/src/test/resources/test01.conf | 5 ++++- .../test/scala/com/typesafe/config/impl/ConfigTest.scala | 3 +++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/config/src/main/java/com/typesafe/config/impl/SimpleConfig.java b/config/src/main/java/com/typesafe/config/impl/SimpleConfig.java index b202c90c..b3fe1135 100644 --- a/config/src/main/java/com/typesafe/config/impl/SimpleConfig.java +++ b/config/src/main/java/com/typesafe/config/impl/SimpleConfig.java @@ -521,11 +521,11 @@ final class SimpleConfig implements Config, MergeableValue, Serializable { units = TimeUnit.NANOSECONDS; } else if (unitString.equals("d") || unitString.equals("days")) { units = TimeUnit.DAYS; - } else if (unitString.equals("h") || unitString.equals("hours")) { + } else if (unitString.equals("h") || unitString.equals("hours") || unitString.equals("hr") || unitString.equals("hrs")) { units = TimeUnit.HOURS; - } else if (unitString.equals("s") || unitString.equals("seconds")) { + } else if (unitString.equals("s") || unitString.equals("seconds") || unitString.equals("secs")) { units = TimeUnit.SECONDS; - } else if (unitString.equals("m") || unitString.equals("minutes")) { + } else if (unitString.equals("m") || unitString.equals("minutes") || unitString.equals("mins")) { units = TimeUnit.MINUTES; } else { throw new ConfigException.BadValue(originForException, diff --git a/config/src/test/resources/test01.conf b/config/src/test/resources/test01.conf index 586d23f3..2e56d24b 100644 --- a/config/src/test/resources/test01.conf +++ b/config/src/test/resources/test01.conf @@ -56,7 +56,10 @@ "secondAsNumber" : 1000, "halfSecond" : 0.5s, "millis" : 1 milli, - "micros" : 2000 micros + "micros" : 2000 micros, + "secs" : 2 sec, + "mins" : 1 min, + "hrs" : 1 hr }, "memsizes" : { diff --git a/config/src/test/scala/com/typesafe/config/impl/ConfigTest.scala b/config/src/test/scala/com/typesafe/config/impl/ConfigTest.scala index 7ca5fa66..849dd932 100644 --- a/config/src/test/scala/com/typesafe/config/impl/ConfigTest.scala +++ b/config/src/test/scala/com/typesafe/config/impl/ConfigTest.scala @@ -771,6 +771,9 @@ class ConfigTest extends TestUtils { assertEquals(ms2unit(500L), conf.getDuration("durations.halfSecond", unit)) assertEquals(ms2unit(1L), conf.getDuration("durations.millis", unit)) assertEquals(ms2unit(2L), conf.getDuration("durations.micros", unit)) + assertEquals(ms2unit(2000L), conf.getDuration("durations.secs", unit)) + assertEquals(ms2unit(60000L), conf.getDuration("durations.mins", unit)) + assertEquals(ms2unit(3600000L), conf.getDuration("durations.hrs", unit)) } assertDurationAsTimeUnit(NANOSECONDS)