Class TimeValueImpl

java.lang.Object
org.wikidata.wdtk.datamodel.implementation.ValueImpl
org.wikidata.wdtk.datamodel.implementation.TimeValueImpl
All Implemented Interfaces:
TimeValue, Value

public class TimeValueImpl extends ValueImpl implements TimeValue
Jackson implementation of TimeValue.
Author:
Fredo Erxleben, Markus Kroetzsch, Antonin Delpeuch
  • Constructor Details

    • TimeValueImpl

      public TimeValueImpl(long year, byte month, byte day, byte hour, byte minute, byte second, byte precision, int beforeTolerance, int afterTolerance, int timezoneOffset, String calendarModel)
      Constructor.
      Parameters:
      year - a year number, where 0 refers to 1BCE
      month - a month number between 1 and 12
      day - a day number between 1 and 31
      hour - an hour number between 0 and 23
      minute - a minute number between 0 and 59
      second - a second number between 0 and 60 (possible leap second)
      precision - a value in the range of TimeValue.PREC_DAY, ..., TimeValue.PREC_1GY
      beforeTolerance - non-negative integer tolerance before the value; see TimeValue.getBeforeTolerance()
      afterTolerance - non-zero, positive integer tolerance before the value; see TimeValue.getAfterTolerance()
      calendarModel - the IRI of the calendar model preferred when displaying the date; usually TimeValue.CM_GREGORIAN_PRO or TimeValue.CM_JULIAN_PRO
      timezoneOffset - offset in minutes that should be applied when displaying this time
  • Method Details

    • getValue

      public org.wikidata.wdtk.datamodel.implementation.TimeValueImpl.JacksonInnerTime getValue()
      Returns the inner value helper object. Only for use by Jackson during serialization.
      Returns:
      the inner time value
    • getYear

      public long getYear()
      Description copied from interface: TimeValue
      Get the year stored for this date. Years in Wikibase can be 0; see "Y0K" issue in the interface documentation.
      Specified by:
      getYear in interface TimeValue
      Returns:
      year number
    • getMonth

      public byte getMonth()
      Description copied from interface: TimeValue
      Get the month stored for this date. It will be a number from 1 to 12.
      Specified by:
      getMonth in interface TimeValue
      Returns:
      month number
    • getDay

      public byte getDay()
      Description copied from interface: TimeValue
      Get the day stored for this date. It will be a number from 1 to 31.
      Specified by:
      getDay in interface TimeValue
      Returns:
      day number
    • getHour

      public byte getHour()
      Description copied from interface: TimeValue
      Get the hour stored for this date. It will be a number from 0 to 23.
      Specified by:
      getHour in interface TimeValue
      Returns:
      hour number
    • getMinute

      public byte getMinute()
      Description copied from interface: TimeValue
      Get the minute stored for this date. It will be a number from 0 to 59.
      Specified by:
      getMinute in interface TimeValue
      Returns:
      minute number
    • getSecond

      public byte getSecond()
      Description copied from interface: TimeValue
      Get the seconds stored for this date. The value will be between 0 and 60 (inclusive) to account for leap seconds. Implementations are not expected to validate leap seconds but they should provide consistent ordering: the time 23:59:60 is always before 00:00:00 on the next day.
      Specified by:
      getSecond in interface TimeValue
      Returns:
      second number
    • getPreferredCalendarModel

      public String getPreferredCalendarModel()
      Description copied from interface: TimeValue
      Get the IRI of the preferred calendar model that should be used to display this date (and that was presumably used when entering it). This is usually TimeValue.CM_GREGORIAN_PRO or TimeValue.CM_JULIAN_PRO.
      Specified by:
      getPreferredCalendarModel in interface TimeValue
      Returns:
      IRI of the preferred calendar model
    • getPreferredCalendarModelItemId

      public ItemIdValue getPreferredCalendarModelItemId()
      Description copied from interface: TimeValue
      Get the ItemIdValue of the preferred calendar model that should be used to display this date (and that was presumably used when entering it).
      Specified by:
      getPreferredCalendarModelItemId in interface TimeValue
    • getPrecision

      public byte getPrecision()
      Description copied from interface: TimeValue
      Get the precision hint of this date. The return value will be in the range of TimeValue.PREC_DAY, ..., TimeValue.PREC_1GY.
      Specified by:
      getPrecision in interface TimeValue
      Returns:
      precision hint for this date
    • getTimezoneOffset

      public int getTimezoneOffset()
      Description copied from interface: TimeValue
      Get the offset in minutes from UTC that should be applied when displaying this time to users. The recorded time point is always in UTC, so the timezone can be ignored for comparing values. The offset should be added to the given time to obtain the intended local value. For example, an offset of +60 and a time of 10:45:00 should be displayed as 11:45:00 to the user (ideally with some indication of the shift; time zone abbreviations like "CET" could be used when matching the given offset, but the offset might also have values that do not correspond to any current or modern time zone). Therefore positive offsets are used for timezones that to the east of the prime meridian.
      Specified by:
      getTimezoneOffset in interface TimeValue
      Returns:
      minute number (positive or negative)
    • getBeforeTolerance

      public int getBeforeTolerance()
      Description copied from interface: TimeValue
      Get a tolerance value that specifies how much earlier in time the value could at most be, measured as a multiple of precision. The value is a non-negative integer.

      For example, for the date 2007-05-12T10:45:00 with precision TimeValue.PREC_MONTH, a before-tolerance value of 3 means that the earliest possible time of this event could have been 2007-02-12T10:45:00. This information about the uncertainty of time points can be taken into account in query answering, but simplified implementations can also ignore it and work with the given (exact) time point instead. If not set specifically by the user, the before-tolerance value should be 0, i.e., the given time point marks the earliest possible time.

      This boundary is inclusive. For example, a date 2014-02-17T00:00:00 with precision TimeValue.PREC_DAY and before-tolerance value 1 specifies a time that between 2014-02-17T00:00:00

      Specified by:
      getBeforeTolerance in interface TimeValue
      Returns:
      a non-negative integer tolerance measured in terms of precision
      See Also:
    • getAfterTolerance

      public int getAfterTolerance()
      Description copied from interface: TimeValue
      Get a tolerance value that specifies how much later in time the value could at most be, measured as a multiple of precision. The value is a positive integer.

      For example, for the date 2007-05-12T10:45:00 with precision TimeValue.PREC_MONTH, an after-tolerance value of 2 means that the latest possible time of this event could have been strictly before 2007-07-12T10:45:00. This information about the uncertainty of time points can be taken into account in query answering, but simplified implementations can also ignore it and work with the given (exact) time point instead. If not set specifically by the user, the after-tolerance value should be 1, i.e., the interval of uncertainty is exactly the length given by precision. However, because most (if not all) other known implementations of the data model got this detail wrong and use 0 instead, we are also using 0 as a default value. This issue is tracked at https://phabricator.wikimedia.org/T194869.

      The boundary is exclusive. For example, a date 2013-02-01T00:00:00 with precision TimeValue.PREC_MONTH and after-tolerance value 1 and before-tolerance value of 0 specifies a time "sometime in February 2013", but it excludes any time in March 2013. The after-tolerance must not be 0 (which would make no sense if the bound is exclusive, and which is not needed since precision up to a single second can be specified anyway).

      Specified by:
      getAfterTolerance in interface TimeValue
      Returns:
      a non-zero, positive integer tolerance measured in terms of precision
      See Also:
    • accept

      public <T> T accept(ValueVisitor<T> valueVisitor)
      Description copied from interface: Value
      Accept a ValueVisitor and return its output.
      Specified by:
      accept in interface Value
      Parameters:
      valueVisitor - the ValueVisitor
      Returns:
      output of the visitor
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toGregorian

      public TimeValue toGregorian()
      Description copied from interface: TimeValue
      Convert the value to the Gregorian calendar, if possible. This conversion can fail if not enough information is available (for example, we need at least day precision to convert from Julian to Gregorian).
      Specified by:
      toGregorian in interface TimeValue
      Returns:
      a TimeValue that uses the Gregorian calendar, or null if the conversion failed.