/** * Copies a {@link TimeValue}. * * @param object * object to copy * @return copied object */ public TimeValue copy(TimeValue object) { return dataObjectFactory.getTimeValue(object.getYear(), object.getMonth(), object.getDay(), object.getHour(), object.getMinute(), object.getSecond(), object.getPrecision(), object.getBeforeTolerance(), object.getAfterTolerance(), object.getTimezoneOffset(), object.getPreferredCalendarModel()); }
if (value.getYear() == 0 || (value.getYear() < 0 && value.getPrecision() >= TimeValue.PREC_YEAR)) { xsdYearString = String.format("%05d", value.getYear() - 1); } else { xsdYearString = String.format("%04d", value.getYear()); if (value.getPrecision() >= TimeValue.PREC_DAY) { if (value.getPrecision() > TimeValue.PREC_DAY) { logger.warn("Time values with times of day not supported yet. Exporting only date of " + value.toString()); + String.format("%02d", value.getMonth()) + "-" + String.format("%02d", value.getDay()), RdfWriter.XSD_DATE); } else if (value.getPrecision() == TimeValue.PREC_MONTH) { return rdfWriter.getLiteral( xsdYearString + "-" + String.format("%02d", value.getMonth()), RdfWriter.XSD_G_YEAR_MONTH); } else { // (value.getPrecision() <= TimeValue.PREC_YEAR)
/** * Helper method that finds the first value of a time-valued property (if * any), and extracts an integer year. It checks if the value has sufficient * precision to extract an exact year. * * @param document * the document to extract the data from * @param propertyId * the string id of the property to look for * @return the year, or Interger.MIN_VALUE if none was found */ private int getYearIfAny(StatementDocument document, String propertyId) { TimeValue date = document.findStatementTimeValue(propertyId); if (date != null && date.getPrecision() >= TimeValue.PREC_YEAR) { return (int) date.getYear(); } else { return Integer.MIN_VALUE; } }
/** * Write the auxiliary RDF data for encoding the given value. * * @param value * the value to write * @param resource * the (subject) URI to use to represent this value in RDF * @throws RDFHandlerException */ @Override public void writeValue(TimeValue value, Resource resource) throws RDFHandlerException { this.rdfWriter.writeTripleValueObject(resource, RdfWriter.RDF_TYPE, RdfWriter.WB_TIME_VALUE); this.rdfWriter.writeTripleValueObject(resource, RdfWriter.WB_TIME, TimeValueConverter.getTimeLiteral(value, this.rdfWriter)); this.rdfWriter.writeTripleIntegerObject(resource, RdfWriter.WB_TIME_PRECISION, value.getPrecision()); this.rdfWriter.writeTripleIntegerObject(resource, RdfWriter.WB_TIME_TIMEZONE, value.getTimezoneOffset()); this.rdfWriter.writeTripleUriObject(resource, RdfWriter.WB_TIME_CALENDAR_MODEL, value.getPreferredCalendarModel()); }
/** * Write the auxiliary RDF data for encoding the given value. * * @param value * the value to write * @param resource * the (subject) URI to use to represent this value in RDF * @throws RDFHandlerException */ @Override public void writeValue(TimeValue value, Resource resource) throws RDFHandlerException { this.rdfWriter.writeTripleValueObject(resource, RdfWriter.RDF_TYPE, RdfWriter.WB_TIME_VALUE); this.rdfWriter.writeTripleValueObject(resource, RdfWriter.WB_TIME, TimeValueConverter.getTimeLiteral(value, this.rdfWriter)); this.rdfWriter.writeTripleIntegerObject(resource, RdfWriter.WB_TIME_PRECISION, value.getPrecision()); this.rdfWriter.writeTripleUriObject(resource, RdfWriter.WB_PREFERRED_CALENDAR, value.getPreferredCalendarModel()); }
/** * Helper method that finds the first value of a time-valued property (if * any), and extracts an integer year. It checks if the value has sufficient * precision to extract an exact year. * * @param document * the document to extract the data from * @param propertyId * string id of the property to look for * @return the year, or Interger.MIN_VALUE if none was found */ private int getYearIfAny(StatementDocument document, String propertyId) { TimeValue date = document.findStatementTimeValue(propertyId); if (date != null && date.getPrecision() >= TimeValue.PREC_YEAR) { return (int) date.getYear(); } else { return Integer.MIN_VALUE; } }
/** * Copies a {@link TimeValue}. * * @param object * object to copy * @return copied object */ public TimeValue copy(TimeValue object) { return dataObjectFactory.getTimeValue(object.getYear(), object.getMonth(), object.getDay(), object.getHour(), object.getMinute(), object.getSecond(), object.getPrecision(), object.getBeforeTolerance(), object.getAfterTolerance(), object.getTimezoneOffset(), object.getPreferredCalendarModel()); }
/** * Returns the RDF literal to encode the time component of a given time * value. * <p> * Times with limited precision are encoded using limited-precision XML * Schema datatypes, such as gYear, if available. Wikidata encodes the year * 1BCE as 0000, while XML Schema, even in version 2, does not allow 0000 * and interprets -0001 as 1BCE. Thus all negative years must be shifted by * 1, but we only do this if the year is precise. * * @param value * the value to convert * @param rdfWriter * the object to use for creating the literal * @return the RDF literal */ private static Literal getTimeLiteral(TimeValue value, RdfWriter rdfWriter) { long year = value.getYear(); //Year normalization if (year == 0 || (year < 0 && value.getPrecision() >= TimeValue.PREC_YEAR)) { year--; } String timestamp = String.format("%04d-%02d-%02dT%02d:%02d:%02dZ", year, value.getMonth(), value.getDay(), value.getHour(), value.getMinute(), value.getSecond()); return rdfWriter.getLiteral(timestamp, RdfWriter.XSD_DATETIME); }
/** * Returns a hash code for the given object. * * @see java.lang.Object#hashCode() * @param o * the object to create a hash for * @return the hash code of the object */ public static int hashCode(TimeValue o) { int result; result = Long.hashCode(o.getYear()); result = prime * result + o.getMonth(); result = prime * result + o.getDay(); result = prime * result + o.getHour(); result = prime * result + o.getMinute(); result = prime * result + o.getSecond(); result = prime * result + o.getPrecision(); result = prime * result + o.getBeforeTolerance(); result = prime * result + o.getAfterTolerance(); result = prime * result + o.getTimezoneOffset(); result = prime * result + o.getPreferredCalendarModel().hashCode(); return result; }
/** * Returns a representation of the date from the value attributes as ISO * 8601 encoding. * * @param value * @return ISO 8601 value (String) */ public static String formatTimeISO8601(TimeValue value) { StringBuilder builder = new StringBuilder(); DecimalFormat yearForm = new DecimalFormat(FORMAT_YEAR); DecimalFormat timeForm = new DecimalFormat(FORMAT_OTHER); if (value.getYear() > 0) { builder.append("+"); } builder.append(yearForm.format(value.getYear())); builder.append("-"); builder.append(timeForm.format(value.getMonth())); builder.append("-"); builder.append(timeForm.format(value.getDay())); builder.append("T"); builder.append(timeForm.format(value.getHour())); builder.append(":"); builder.append(timeForm.format(value.getMinute())); builder.append(":"); builder.append(timeForm.format(value.getSecond())); builder.append("Z"); return builder.toString(); }
/** * Returns a hash code for the given object. * * @see java.lang.Object#hashCode() * @param o * the object to create a hash for * @return the hash code of the object */ public static int hashCode(TimeValue o) { int result; result = Long.hashCode(o.getYear()); result = prime * result + o.getMonth(); result = prime * result + o.getDay(); result = prime * result + o.getHour(); result = prime * result + o.getMinute(); result = prime * result + o.getSecond(); result = prime * result + o.getPrecision(); result = prime * result + o.getBeforeTolerance(); result = prime * result + o.getAfterTolerance(); result = prime * result + o.getTimezoneOffset(); result = prime * result + o.getPreferredCalendarModel().hashCode(); return result; }
/** * Returns a representation of the date from the value attributes as ISO * 8601 encoding. * * @param value * @return ISO 8601 value (String) */ public static String formatTimeISO8601(TimeValue value) { StringBuilder builder = new StringBuilder(); DecimalFormat yearForm = new DecimalFormat(FORMAT_YEAR); DecimalFormat timeForm = new DecimalFormat(FORMAT_OTHER); if (value.getYear() > 0) { builder.append("+"); } builder.append(yearForm.format(value.getYear())); builder.append("-"); builder.append(timeForm.format(value.getMonth())); builder.append("-"); builder.append(timeForm.format(value.getDay())); builder.append("T"); builder.append(timeForm.format(value.getHour())); builder.append(":"); builder.append(timeForm.format(value.getMinute())); builder.append(":"); builder.append(timeForm.format(value.getSecond())); builder.append("Z"); return builder.toString(); }
return o1.getYear() == other.getYear() && o1.getMonth() == other.getMonth() && o1.getDay() == other.getDay() && o1.getHour() == other.getHour() && o1.getMinute() == other.getMinute() && o1.getSecond() == other.getSecond() && o1.getPrecision() == other.getPrecision() && o1.getBeforeTolerance() == other.getBeforeTolerance() && o1.getAfterTolerance() == other.getAfterTolerance() && o1.getTimezoneOffset() == other.getTimezoneOffset() && o1.getPreferredCalendarModel().equals( other.getPreferredCalendarModel());
return o1.getYear() == other.getYear() && o1.getMonth() == other.getMonth() && o1.getDay() == other.getDay() && o1.getHour() == other.getHour() && o1.getMinute() == other.getMinute() && o1.getSecond() == other.getSecond() && o1.getPrecision() == other.getPrecision() && o1.getBeforeTolerance() == other.getBeforeTolerance() && o1.getAfterTolerance() == other.getAfterTolerance() && o1.getTimezoneOffset() == other.getTimezoneOffset() && o1.getPreferredCalendarModel().equals( other.getPreferredCalendarModel());
public static String getTimeValueUri(TimeValue value) { md.reset(); updateMessageDigestWithLong(md, value.getYear()); md.update(value.getMonth()); md.update(value.getDay()); md.update(value.getHour()); md.update(value.getMinute()); md.update(value.getSecond()); updateMessageDigestWithString(md, value.getPreferredCalendarModel()); updateMessageDigestWithInt(md, value.getBeforeTolerance()); updateMessageDigestWithInt(md, value.getAfterTolerance()); updateMessageDigestWithInt(md, value.getTimezoneOffset()); return PREFIX_WIKIDATA_VALUE + bytesToHex(md.digest()); }
DecimalFormat timeForm = new DecimalFormat("00"); return o.getYear() + "-" + timeForm.format(o.getMonth()) + "-" + timeForm.format(o.getDay()) + (o.getPrecision() > TimeValue.PREC_DAY || o.getHour() + o.getMinute() + o.getSecond() > 0 ? ("T" + timeForm.format(o.getHour()) + ":" + timeForm.format(o.getMinute()) + ":" + timeForm .format(o.getSecond())) : "") + " (Prec.: " + getTimePrecisionString(o.getPrecision()) + " [-" + o.getBeforeTolerance() + " .. +" + o.getAfterTolerance() + "]" + ", PCal: " + getCalendarString(o.getPreferredCalendarModel()) + (o.getTimezoneOffset() != 0 ? (", Timezone: " + o.getTimezoneOffset() + "min ") : "") + ")";
DecimalFormat timeForm = new DecimalFormat("00"); return o.getYear() + "-" + timeForm.format(o.getMonth()) + "-" + timeForm.format(o.getDay()) + (o.getPrecision() > TimeValue.PREC_DAY || o.getHour() + o.getMinute() + o.getSecond() > 0 ? ("T" + timeForm.format(o.getHour()) + ":" + timeForm.format(o.getMinute()) + ":" + timeForm .format(o.getSecond())) : "") + " (Prec.: " + getTimePrecisionString(o.getPrecision()) + " [-" + o.getBeforeTolerance() + " .. +" + o.getAfterTolerance() + "]" + ", PCal: " + getCalendarString(o.getPreferredCalendarModel()) + (o.getTimezoneOffset() != 0 ? (", Timezone: " + o.getTimezoneOffset() + "min ") : "") + ")";
public static String getTimeValueUri(TimeValue value) { md.reset(); updateMessageDigestWithLong(md, value.getYear()); md.update(value.getMonth()); md.update(value.getDay()); md.update(value.getHour()); md.update(value.getMinute()); md.update(value.getSecond()); updateMessageDigestWithString(md, value.getPreferredCalendarModel()); updateMessageDigestWithInt(md, value.getBeforeTolerance()); updateMessageDigestWithInt(md, value.getAfterTolerance()); updateMessageDigestWithInt(md, value.getTimezoneOffset()); return PREFIX_WIKIDATA + VALUE_PREFIX_TIME + bytesToHex(md.digest()); }