Add Period converter support
Add converter support for `javax.time.Period` including: String -> Period Number -> Period Period -> String Period to Number conversion is not supported since `Period` has no ability to deduce the number of calendar days in the period. See gh-21136
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -130,6 +130,19 @@ public class JavaCompilerFieldValuesParser implements FieldValuesParser {
|
||||
DATA_SIZE_SUFFIX = Collections.unmodifiableMap(values);
|
||||
}
|
||||
|
||||
private static final String PERIOD_OF = "Period.of";
|
||||
|
||||
private static final Map<String, String> PERIOD_SUFFIX;
|
||||
|
||||
static {
|
||||
Map<String, String> values = new HashMap<>();
|
||||
values.put("Days", "d");
|
||||
values.put("Weeks", "w");
|
||||
values.put("Months", "m");
|
||||
values.put("Years", "y");
|
||||
PERIOD_SUFFIX = Collections.unmodifiableMap(values);
|
||||
}
|
||||
|
||||
private final Map<String, Object> fieldValues = new HashMap<>();
|
||||
|
||||
private final Map<String, Object> staticFinals = new HashMap<>();
|
||||
@@ -194,6 +207,10 @@ public class JavaCompilerFieldValuesParser implements FieldValuesParser {
|
||||
if (dataSizeValue != null) {
|
||||
return dataSizeValue;
|
||||
}
|
||||
Object periodValue = getFactoryValue(expression, factoryValue, PERIOD_OF, PERIOD_SUFFIX);
|
||||
if (periodValue != null) {
|
||||
return periodValue;
|
||||
}
|
||||
return factoryValue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user