From 8f0ac6788cd8adcdaa72d94fb825a4286d1383d2 Mon Sep 17 00:00:00 2001 From: Tpt Date: Sun, 11 Mar 2018 22:35:51 +0100 Subject: [PATCH] Uses new Wikibase timestamp format with year in 4 digits --- .../implementation/TimeValueImpl.java | 2 +- .../implementation/json/JacksonInnerTime.java | 27 +++++++------------ .../implementation/json/JsonTestData.java | 2 +- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/TimeValueImpl.java b/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/TimeValueImpl.java index 94f8a4ced..eced40fac 100644 --- a/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/TimeValueImpl.java +++ b/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/TimeValueImpl.java @@ -83,7 +83,7 @@ public class TimeValueImpl extends ValueImpl implements TimeValue { * @param timezoneOffset * offset in minutes that should be applied when displaying this * time - * @return a {@link DatatypeIdValue} corresponding to the input + * @return a {@link TimeValue} corresponding to the input */ TimeValueImpl(long year, byte month, byte day, byte hour, byte minute, byte second, byte precision, int beforeTolerance, diff --git a/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/json/JacksonInnerTime.java b/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/json/JacksonInnerTime.java index 69bff54c8..576e686f9 100644 --- a/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/json/JacksonInnerTime.java +++ b/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/json/JacksonInnerTime.java @@ -41,24 +41,18 @@ */ @JsonIgnoreProperties(ignoreUnknown = true) public class JacksonInnerTime { - private String time; + private final String time; private final int timezone; private final int before; private final int after; private final int precision; private final String calendarmodel; - @JsonIgnore private long year; - @JsonIgnore private byte month; - @JsonIgnore private byte day; - @JsonIgnore private byte hour; - @JsonIgnore private byte minute; - @JsonIgnore private byte second; /** @@ -86,15 +80,15 @@ public class JacksonInnerTime { @JsonCreator public JacksonInnerTime( @JsonProperty("time") String time, - @JsonProperty("timezone") int timezoneOffset, - @JsonProperty("before") int beforeTolerance, - @JsonProperty("after") int afterTolerance, + @JsonProperty("timezone") int timezone, + @JsonProperty("before") int before, + @JsonProperty("after") int after, @JsonProperty("precision") int precision, @JsonProperty("calendarmodel") String calendarModel) { this.time = time; - this.timezone = timezoneOffset; - this.before = beforeTolerance; - this.after = afterTolerance; + this.timezone = timezone; + this.before = before; + this.after = after; this.precision = precision; this.calendarmodel = calendarModel; @@ -148,8 +142,7 @@ public JacksonInnerTime(long year, byte month, byte day, byte hour, this.after = after; this.precision = precision; this.calendarmodel = calendarModel; - - this.composeTimeString(); + this.time = composeTimeString(); } /** @@ -171,8 +164,8 @@ private void decomposeTimeString() { /** * Helper method to compose the time string from its components. */ - private void composeTimeString() { - this.time = String.format("%+012d-%02d-%02dT%02d:%02d:%02dZ", + private String composeTimeString() { + return String.format("%+04d-%02d-%02dT%02d:%02d:%02dZ", this.year, this.month, this.day, this.hour, this.minute, this.second); } diff --git a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/json/JsonTestData.java b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/json/JsonTestData.java index 32469c638..9e62eafd1 100644 --- a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/json/JsonTestData.java +++ b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/json/JsonTestData.java @@ -88,7 +88,7 @@ public class JsonTestData { + "\",\"numeric-id\":" + TEST_NUMERIC_ID + ",\"id\":\"" + TEST_PROPERTY_ID + "\"}}"; public static final String JSON_TIME_VALUE = "{\"type\":\"" + ValueImpl.JSON_VALUE_TYPE_TIME - + "\", \"value\":{\"time\":\"+00000002013-10-28T00:00:00Z\",\"timezone\":0,\"before\":0,\"after\":0,\"precision\":11,\"calendarmodel\":\"http://www.wikidata.org/entity/Q1985727\"}}"; + + "\", \"value\":{\"time\":\"+2013-10-28T00:00:00Z\",\"timezone\":0,\"before\":0,\"after\":0,\"precision\":11,\"calendarmodel\":\"http://www.wikidata.org/entity/Q1985727\"}}"; public static final String JSON_GLOBE_COORDINATES_VALUE = "{\"type\":\"" + ValueImpl.JSON_VALUE_TYPE_GLOBE_COORDINATES + "\", \"value\":{\"latitude\":-90.0,\"longitude\":0.0,\"precision\":10.0,\"globe\":\"http://www.wikidata.org/entity/Q2\"}}";