Refine implementation thanks to the tests
This commit is contained in:
parent
6bc9a6ea8e
commit
5534e84b29
@ -106,7 +106,9 @@ public class WbDateConstant implements WbExpression<TimeValue> {
|
|||||||
Date date = entry.getKey().parse(trimmedDatestamp, position);
|
Date date = entry.getKey().parse(trimmedDatestamp, position);
|
||||||
|
|
||||||
// Ignore parses which failed or do not consume all the input
|
// 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();
|
precision = entry.getValue();
|
||||||
bestDate = date;
|
bestDate = date;
|
||||||
maxLength = position.getIndex();
|
maxLength = position.getIndex();
|
||||||
|
@ -36,7 +36,7 @@ public class WbDateVariableTest extends WbVariableTest<TimeValue> {
|
|||||||
0, 0, 0, TimeValue.CM_GREGORIAN_PRO);
|
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,
|
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);
|
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
|
@Override
|
||||||
@ -71,6 +71,7 @@ public class WbDateVariableTest extends WbVariableTest<TimeValue> {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMinutesISO() {
|
public void testMinutesISO() {
|
||||||
|
// Wikidata currently only supports up to day precision
|
||||||
evaluatesTo(minute, "2001-02-03T04:05Z");
|
evaluatesTo(minute, "2001-02-03T04:05Z");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user