From bb79125829bba258bfd9200a9b193941d8166e5e Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Sat, 24 Nov 2018 15:46:24 +0000 Subject: [PATCH] Add support for sub-year precisions in Wikidata schema, for #1816 --- .../org/openrefine/wikidata/schema/WbDateConstant.java | 3 +++ .../openrefine/wikidata/schema/WbDateConstantTest.java | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbDateConstant.java b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbDateConstant.java index 0fd77d88b..0e061b6bc 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbDateConstant.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbDateConstant.java @@ -55,6 +55,9 @@ public class WbDateConstant implements WbExpression { * precision it induces (an integer according to Wikibase's data model). */ public static Map acceptedFormats = ImmutableMap. 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) diff --git a/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbDateConstantTest.java b/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbDateConstantTest.java index 180c1d4cb..d7d31c92b 100644 --- a/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbDateConstantTest.java +++ b/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbDateConstantTest.java @@ -30,6 +30,9 @@ import org.wikidata.wdtk.datamodel.interfaces.TimeValue; public class WbDateConstantTest extends WbExpressionTest { + 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 { @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,