Fix Wikidata date parsing tests

This commit is contained in:
Antonin Delpeuch 2019-02-19 22:32:50 +00:00
parent 5534e84b29
commit b157651e9e
2 changed files with 5 additions and 3 deletions

View File

@ -54,7 +54,7 @@ public class WbDateVariable extends WbVariableExpr<TimeValue> {
public TimeValue fromCell(Cell cell, ExpressionContext ctxt) public TimeValue fromCell(Cell cell, ExpressionContext ctxt)
throws SkipSchemaExpressionException { throws SkipSchemaExpressionException {
try { try {
// TODO accept parsed dates (without converting them to strings) // parsed dates are accepted by converting them to strings
return WbDateConstant.parse(cell.value.toString()); return WbDateConstant.parse(cell.value.toString());
} catch (ParseException e) { } catch (ParseException e) {
if(!cell.value.toString().isEmpty()) { if(!cell.value.toString().isEmpty()) {

View File

@ -38,6 +38,7 @@ public class WbDateConstantTest extends WbExpressionTest<TimeValue> {
private WbDateConstant day = new WbDateConstant("2018-02-27"); private WbDateConstant day = new WbDateConstant("2018-02-27");
private WbDateConstant whitespace = new WbDateConstant(" 2018-02-27 "); private WbDateConstant whitespace = new WbDateConstant(" 2018-02-27 ");
private WbDateConstant second = new WbDateConstant("2017-01-03T04:12:45"); private WbDateConstant second = new WbDateConstant("2017-01-03T04:12:45");
private WbDateConstant secondz = new WbDateConstant("2017-01-03T04:12:45Z");
@Test @Test
public void testSerialize() { public void testSerialize() {
@ -64,6 +65,8 @@ public class WbDateConstantTest extends WbExpressionTest<TimeValue> {
TimeValue.CM_GREGORIAN_PRO), day); TimeValue.CM_GREGORIAN_PRO), day);
evaluatesTo(Datamodel.makeTimeValue(2017, (byte) 1, (byte) 3, (byte) 0, (byte) 0, (byte) 0, (byte) 11, 0, 0, 0, evaluatesTo(Datamodel.makeTimeValue(2017, (byte) 1, (byte) 3, (byte) 0, (byte) 0, (byte) 0, (byte) 11, 0, 0, 0,
TimeValue.CM_GREGORIAN_PRO), second); TimeValue.CM_GREGORIAN_PRO), second);
evaluatesTo(Datamodel.makeTimeValue(2017, (byte) 1, (byte) 3, (byte) 0, (byte) 0, (byte) 0, (byte) 11, 0, 0, 0,
TimeValue.CM_GREGORIAN_PRO), secondz);
evaluatesTo(Datamodel.makeTimeValue(2018, (byte) 2, (byte) 27, (byte) 0, (byte) 0, (byte) 0, (byte) 11, 0, 0, 0, evaluatesTo(Datamodel.makeTimeValue(2018, (byte) 2, (byte) 27, (byte) 0, (byte) 0, (byte) 0, (byte) 11, 0, 0, 0,
TimeValue.CM_GREGORIAN_PRO), whitespace); TimeValue.CM_GREGORIAN_PRO), whitespace);
@ -76,7 +79,6 @@ public class WbDateConstantTest extends WbExpressionTest<TimeValue> {
@Test @Test
public void testPartlyValid() { public void testPartlyValid() {
evaluatesTo(Datamodel.makeTimeValue(2018, (byte) 1, (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 9, 0, 0, 0, isSkipped(new WbDateConstant("2018-partly valid"));
TimeValue.CM_GREGORIAN_PRO), new WbDateConstant("2018-partly valid"));
} }
} }