Fix wikibase date export format (#3887)

* fixes #3694
This commit is contained in:
loulan 2021-05-10 15:08:02 +08:00 committed by GitHub
parent dd822526e9
commit b481387d73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 25 deletions

View File

@ -123,7 +123,7 @@ public class WbDateConstant implements WbExpression<TimeValue> {
trimmedDatestamp = trimmedDatestamp.substring(1);
bceFlag = true;
}
for (Entry<SimpleDateFormat, Integer> entry : acceptedFormats.entrySet()) {
ParsePosition position = new ParsePosition(0);
Date date = entry.getKey().parse(trimmedDatestamp, position);
@ -161,10 +161,12 @@ public class WbDateConstant implements WbExpression<TimeValue> {
calendar = Calendar.getInstance();
calendar.setTime(bestDate);
long year = calendar.get(Calendar.YEAR);
int month = precision < 10 ? 0 : calendar.get(Calendar.MONTH) + 1;
int day_of_month = precision < 11 ? 0 : calendar.get(Calendar.DAY_OF_MONTH);
if(bceFlag)
year = -1*year;
return Datamodel.makeTimeValue(year, (byte) (calendar.get(Calendar.MONTH) + 1),
(byte) calendar.get(Calendar.DAY_OF_MONTH), (byte) calendar.get(Calendar.HOUR_OF_DAY),
return Datamodel.makeTimeValue(year, (byte) month,
(byte) day_of_month, (byte) calendar.get(Calendar.HOUR_OF_DAY),
(byte) calendar.get(Calendar.MINUTE), (byte) calendar.get(Calendar.SECOND), (byte) precision, 0, 0,
0, calendarIri);
}

View File

@ -74,15 +74,15 @@ 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,
evaluatesTo(Datamodel.makeTimeValue(1001, (byte) 0, (byte) 0, (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,
evaluatesTo(Datamodel.makeTimeValue(1701, (byte) 0, (byte) 0, (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,
evaluatesTo(Datamodel.makeTimeValue(1990, (byte) 0, (byte) 0, (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,
evaluatesTo(Datamodel.makeTimeValue(2018, (byte) 0, (byte) 0, (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,
evaluatesTo(Datamodel.makeTimeValue(2018, (byte) 2, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 10, 0, 0, 0,
TimeValue.CM_GREGORIAN_PRO), month);
evaluatesTo(Datamodel.makeTimeValue(2018, (byte) 2, (byte) 27, (byte) 0, (byte) 0, (byte) 0, (byte) 11, 0, 0, 0,
TimeValue.CM_GREGORIAN_PRO), day);
@ -94,11 +94,11 @@ public class WbDateConstantTest extends WbExpressionTest<TimeValue> {
evaluatesTo(Datamodel.makeTimeValue(2018, (byte) 2, (byte) 27, (byte) 0, (byte) 0, (byte) 0, (byte) 11, 0, 0, 0,
TimeValue.CM_GREGORIAN_PRO), whitespace);
evaluatesTo(Datamodel.makeTimeValue(1320, (byte) 1, (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 8, 0, 0, 0,
evaluatesTo(Datamodel.makeTimeValue(1320, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 8, 0, 0, 0,
TimeValue.CM_JULIAN_PRO), julianDecade);
evaluatesTo(Datamodel.makeTimeValue(1324, (byte) 1, (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 9, 0, 0, 0,
evaluatesTo(Datamodel.makeTimeValue(1324, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 9, 0, 0, 0,
TimeValue.CM_JULIAN_PRO), julianYear);
evaluatesTo(Datamodel.makeTimeValue(1324, (byte) 2, (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 10, 0, 0, 0,
evaluatesTo(Datamodel.makeTimeValue(1324, (byte) 2, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 10, 0, 0, 0,
TimeValue.CM_JULIAN_PRO), julianMonth);
evaluatesTo(Datamodel.makeTimeValue(1324, (byte) 2, (byte) 27, (byte) 0, (byte) 0, (byte) 0, (byte) 11, 0, 0, 0,
TimeValue.CM_JULIAN_PRO), julianDay);
@ -106,15 +106,15 @@ public class WbDateConstantTest extends WbExpressionTest<TimeValue> {
@Test
public void testEvaluateBCE() {
evaluatesTo(Datamodel.makeTimeValue(-1001, (byte) 1, (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 6, 0, 0, 0,
evaluatesTo(Datamodel.makeTimeValue(-1001, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 6, 0, 0, 0,
TimeValue.CM_GREGORIAN_PRO), BCEmillenium);
evaluatesTo(Datamodel.makeTimeValue(-1701, (byte) 1, (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 7, 0, 0, 0,
evaluatesTo(Datamodel.makeTimeValue(-1701, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 7, 0, 0, 0,
TimeValue.CM_GREGORIAN_PRO), BCEcentury);
evaluatesTo(Datamodel.makeTimeValue(-1990, (byte) 1, (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 8, 0, 0, 0,
evaluatesTo(Datamodel.makeTimeValue(-1990, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 8, 0, 0, 0,
TimeValue.CM_GREGORIAN_PRO), BCEdecade);
evaluatesTo(Datamodel.makeTimeValue(-2018, (byte) 1, (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 9, 0, 0, 0,
evaluatesTo(Datamodel.makeTimeValue(-2018, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 9, 0, 0, 0,
TimeValue.CM_GREGORIAN_PRO), BCEyear);
evaluatesTo(Datamodel.makeTimeValue(-2018, (byte) 2, (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 10, 0, 0, 0,
evaluatesTo(Datamodel.makeTimeValue(-2018, (byte) 2, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 10, 0, 0, 0,
TimeValue.CM_GREGORIAN_PRO), BCEmonth);
evaluatesTo(Datamodel.makeTimeValue(-2018, (byte) 2, (byte) 27, (byte) 0, (byte) 0, (byte) 0, (byte) 11, 0, 0, 0,
TimeValue.CM_GREGORIAN_PRO), BCEday);
@ -126,11 +126,11 @@ public class WbDateConstantTest extends WbExpressionTest<TimeValue> {
evaluatesTo(Datamodel.makeTimeValue(-2018, (byte) 2, (byte) 27, (byte) 0, (byte) 0, (byte) 0, (byte) 11, 0, 0, 0,
TimeValue.CM_GREGORIAN_PRO), BCEwhitespace);
evaluatesTo(Datamodel.makeTimeValue(-1320, (byte) 1, (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 8, 0, 0, 0,
evaluatesTo(Datamodel.makeTimeValue(-1320, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 8, 0, 0, 0,
TimeValue.CM_JULIAN_PRO), BCEjulianDecade);
evaluatesTo(Datamodel.makeTimeValue(-1324, (byte) 1, (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 9, 0, 0, 0,
evaluatesTo(Datamodel.makeTimeValue(-1324, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 9, 0, 0, 0,
TimeValue.CM_JULIAN_PRO), BCEjulianYear);
evaluatesTo(Datamodel.makeTimeValue(-1324, (byte) 2, (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 10, 0, 0, 0,
evaluatesTo(Datamodel.makeTimeValue(-1324, (byte) 2, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 10, 0, 0, 0,
TimeValue.CM_JULIAN_PRO), BCEjulianMonth);
evaluatesTo(Datamodel.makeTimeValue(-1324, (byte) 2, (byte) 27, (byte) 0, (byte) 0, (byte) 0, (byte) 11, 0, 0, 0,
TimeValue.CM_JULIAN_PRO), BCEjulianDay);

View File

@ -32,7 +32,7 @@ import com.google.refine.model.Cell;
public class WbDateVariableTest extends WbVariableTest<TimeValue> {
private TimeValue year = Datamodel.makeTimeValue(2018, (byte) 1, (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 9,
private TimeValue year = Datamodel.makeTimeValue(2018, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 9,
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);

View File

@ -58,9 +58,9 @@ public class WikibaseSchemaTest extends WikidataRefineTest {
private ItemIdValue qid1 = Datamodel.makeWikidataItemIdValue("Q1377");
private ItemIdValue qid2 = Datamodel.makeWikidataItemIdValue("Q865528");
private TimeValue date1 = Datamodel.makeTimeValue(1919, (byte) 1, (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 9,
private TimeValue date1 = Datamodel.makeTimeValue(1919, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 9,
(byte) 0, (byte) 0, (byte) 0, TimeValue.CM_GREGORIAN_PRO);
private TimeValue date2 = Datamodel.makeTimeValue(1965, (byte) 1, (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 9,
private TimeValue date2 = Datamodel.makeTimeValue(1965, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 9,
(byte) 0, (byte) 0, (byte) 0, TimeValue.CM_GREGORIAN_PRO);
private StringValue url = Datamodel.makeStringValue("http://www.ljubljana-slovenia.com/university-ljubljana");
private PropertyIdValue inceptionPid = Datamodel.makeWikidataPropertyIdValue("P571");

View File

@ -52,10 +52,10 @@ public class TestingData {
public static final String inceptionWithNewCsv = "subject,inception,reference\n"
+ "Q1377,1919,http://www.ljubljana-slovenia.com/university-ljubljana\n" + "Q865528,1965,\n"
+ "new uni,2016,http://new-uni.com/";
public static final String inceptionWithNewQS = "Q1377\tP571\t+1919-01-01T00:00:00Z/9"
public static final String inceptionWithNewQS = "Q1377\tP571\t+1919-00-00T00:00:00Z/9"
+ "\tS854\t\"http://www.ljubljana-slovenia.com/university-ljubljana\""
+ "\tS813\t+2018-02-28T00:00:00Z/11\n" + "Q865528\tP571\t+1965-01-01T00:00:00Z/9"
+ "\tS813\t+2018-02-28T00:00:00Z/11\n" + "CREATE\n" + "LAST\tP571\t+2016-01-01T00:00:00Z/9"
+ "\tS813\t+2018-02-28T00:00:00Z/11\n" + "Q865528\tP571\t+1965-00-00T00:00:00Z/9"
+ "\tS813\t+2018-02-28T00:00:00Z/11\n" + "CREATE\n" + "LAST\tP571\t+2016-00-00T00:00:00Z/9"
+ "\tS854\t\"http://new-uni.com/\"" + "\tS813\t+2018-02-28T00:00:00Z/11\n";
public static ItemIdValue newIdA = makeNewItemIdValue(1234L, "new item A");