Add support for sub-year precisions in Wikidata schema, for #1816

This commit is contained in:
Antonin Delpeuch 2018-11-24 15:46:24 +00:00
parent 5c52f3f716
commit bb79125829
2 changed files with 13 additions and 0 deletions

View File

@ -55,6 +55,9 @@ public class WbDateConstant implements WbExpression<TimeValue> {
* precision it induces (an integer according to Wikibase's data model).
*/
public static Map<SimpleDateFormat, Integer> acceptedFormats = ImmutableMap.<SimpleDateFormat, Integer> builder()
.put(new SimpleDateFormat("yyyy'M'"), 6)
.put(new SimpleDateFormat("yyyy'C'"), 7)
.put(new SimpleDateFormat("yyyy'D'"), 8)
.put(new SimpleDateFormat("yyyy"), 9)
.put(new SimpleDateFormat("yyyy-MM"), 10)
.put(new SimpleDateFormat("yyyy-MM-dd"), 11)

View File

@ -30,6 +30,9 @@ import org.wikidata.wdtk.datamodel.interfaces.TimeValue;
public class WbDateConstantTest extends WbExpressionTest<TimeValue> {
private WbDateConstant millenium = new WbDateConstant("1001M");
private WbDateConstant century = new WbDateConstant("1701C");
private WbDateConstant decade = new WbDateConstant("1990D");
private WbDateConstant year = new WbDateConstant("2018");
private WbDateConstant month = new WbDateConstant("2018-02");
private WbDateConstant day = new WbDateConstant("2018-02-27");
@ -46,6 +49,13 @@ public class WbDateConstantTest extends WbExpressionTest<TimeValue> {
@Test
public void testEvaluate() {
evaluatesTo(Datamodel.makeTimeValue(1001, (byte) 1, (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 6, 0, 0, 0,
TimeValue.CM_GREGORIAN_PRO), millenium);
evaluatesTo(Datamodel.makeTimeValue(1701, (byte) 1, (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 7, 0, 0, 0,
TimeValue.CM_GREGORIAN_PRO), century);
evaluatesTo(Datamodel.makeTimeValue(1990, (byte) 1, (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 8, 0, 0, 0,
TimeValue.CM_GREGORIAN_PRO), decade);
evaluatesTo(Datamodel.makeTimeValue(2018, (byte) 1, (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 9, 0, 0, 0,
TimeValue.CM_GREGORIAN_PRO), year);
evaluatesTo(Datamodel.makeTimeValue(2018, (byte) 2, (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 10, 0, 0, 0,