From 5534e84b29397fb89c1d08f54bda32be6df38ed7 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Tue, 19 Feb 2019 22:20:11 +0000 Subject: [PATCH] Refine implementation thanks to the tests --- .../src/org/openrefine/wikidata/schema/WbDateConstant.java | 4 +++- .../org/openrefine/wikidata/schema/WbDateVariableTest.java | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbDateConstant.java b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbDateConstant.java index b1ac73f2e..8c7909bad 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbDateConstant.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbDateConstant.java @@ -106,7 +106,9 @@ public class WbDateConstant implements WbExpression { Date date = entry.getKey().parse(trimmedDatestamp, position); // Ignore parses which failed or do not consume all the input - if (date != null && position.getIndex() > maxLength) { + if (date != null && position.getIndex() > maxLength + // only allow to partially consume the input if the precision is more than a year + && (entry.getValue() > 9 || position.getIndex() == trimmedDatestamp.length())) { precision = entry.getValue(); bestDate = date; maxLength = position.getIndex(); diff --git a/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbDateVariableTest.java b/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbDateVariableTest.java index 9238624ee..2150afc1e 100644 --- a/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbDateVariableTest.java +++ b/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbDateVariableTest.java @@ -36,7 +36,7 @@ public class WbDateVariableTest extends WbVariableTest { 0, 0, 0, TimeValue.CM_GREGORIAN_PRO); private TimeValue day = Datamodel.makeTimeValue(2018, (byte) 2, (byte) 27, (byte) 0, (byte) 0, (byte) 0, (byte) 11, 0, 0, 0, TimeValue.CM_GREGORIAN_PRO); - private TimeValue minute = Datamodel.makeTimeValue(2001, (byte) 2, (byte) 3, (byte)4, (byte)5, (byte)0, (byte)13, (byte)0, (byte)0, (byte)0, TimeValue.CM_GREGORIAN_PRO); + private TimeValue minute = Datamodel.makeTimeValue(2001, (byte) 2, (byte) 3, (byte)0, (byte)0, (byte)0, (byte)11, (byte)0, (byte)0, (byte)0, TimeValue.CM_GREGORIAN_PRO); @Override @@ -71,6 +71,7 @@ public class WbDateVariableTest extends WbVariableTest { @Test public void testMinutesISO() { + // Wikidata currently only supports up to day precision evaluatesTo(minute, "2001-02-03T04:05Z"); }