Added more duration unit short names for hour, minute and second.

This commit is contained in:
Alex Wei 2014-08-08 09:57:42 +10:00
parent 60c661d683
commit ebb526304e
3 changed files with 10 additions and 4 deletions

View File

@ -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,

View File

@ -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" : {

View File

@ -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)