Class DateTimes

java.lang.Object
org.projecthusky.common.utils.time.DateTimes

public final class DateTimes extends Object
Helper utilities related to HL7 DateTime (DTM) resources.
Author:
Quentin Ligier
See Also:
  • Method Details

    • completeToEarliestInstant

      public static @NonNull Hl7Dtm completeToEarliestInstant(@NonNull Hl7Dtm hl7Dtm)
      Takes an HL7 DTM-formatted value given as a Hl7Dtm, sets the resolution to the fraction of seconds by filling missing values to the start of the year, month, day, hour and minute if needed (i.e. sets it to the earliest instant covered by the partial date). The DTM value must be given in UTC.

      For example, if the value "201903" is given, the day is fixed to the start of the month (the first of march) and the time is set to 00:00:00, which results in: "20190301000000".

      If the HL7 DTM is already precise to the fraction of seconds, it will be returned as-is.

      Parameters:
      hl7Dtm - The HL7 DTM-formatted dateTime to process.
      Returns:
      the full precision dateTime.
    • completeToLatestInstant

      public static @NonNull Hl7Dtm completeToLatestInstant(@NonNull Hl7Dtm hl7Dtm)
      Takes an HL7 DTM-formatted value given as a Hl7Dtm, sets the resolution to the fraction of seconds by filling missing values to the end of the year, month, day, hour and minute if needed (i.e. sets it to the latest instant covered by the partial date). The DTM value must be given in UTC.

      By example, if the value "201903" is given, the day is fixed to the end of the month (the last of march) and the time is set to the end of the day (usually 23:59:59), which results in: "20190331235959".

      If the HL7 DTM is already precise to the fraction of seconds, it will be returned as-is.

      Parameters:
      hl7Dtm - The HL7 DTM-formatted dateTime to process.
      Returns:
      the full precision dateTime.
    • completeToEarliestInstant

      public static @NonNull Hl7Dtm completeToEarliestInstant(@NonNull org.openehealth.ipf.commons.ihe.xds.core.metadata.Timestamp timestamp)
      Takes an HL7 DTM-formatted value given as a Hl7Dtm, sets the resolution to the fraction of seconds by filling missing values to the start of the year, month, day, hour and minute if needed (i.e. sets it to the earliest instant covered by the partial date). The DTM value must be given in UTC.

      For example, if the value "201903" is given, the day is fixed to the start of the month (the first of march) and the time is set to 00:00:00, which results in: "20190301000000".

      If the HL7 DTM is already precise to the fraction of seconds, it will be returned as-is.

      Parameters:
      timestamp - The HL7 DTM-formatted dateTime to process.
      Returns:
      the full precision dateTime.
    • completeToLatestInstant

      public static @NonNull Hl7Dtm completeToLatestInstant(@NonNull org.openehealth.ipf.commons.ihe.xds.core.metadata.Timestamp timestamp)
      Takes an HL7 DTM-formatted value given as a Hl7Dtm, sets the resolution to the fraction of seconds by filling missing values to the end of the year, month, day, hour and minute if needed (i.e. sets it to the latest instant covered by the partial date). The DTM value must be given in UTC.

      By example, if the value "201903" is given, the day is fixed to the end of the month (the last of march) and the time is set to the end of the day (usually 23:59:59), which results in: "20190331235959".

      If the HL7 DTM is already precise to the fraction of seconds, it will be returned as-is.

      Parameters:
      timestamp - The HL7 DTM-formatted dateTime to process.
      Returns:
      the full precision dateTime.
    • toInstant

      public static @NonNull Instant toInstant(@NonNull Hl7Dtm timestamp)
      Converts a Hl7Dtm to an Instant.
      Parameters:
      timestamp - The timestamp to convert.
      Returns:
      the equivalent instant.
    • getZonedDateTime

      public static @NonNull ZonedDateTime getZonedDateTime(@NonNull Instant instant)
      Converts an Instant to a local ZonedDateTime.
      Parameters:
      instant - The instant to convert.
      Returns:
      the equivalent zoned date time.
    • toHl7Dtm

      public static @NonNull String toHl7Dtm(@NonNull Instant instant)
      Formats an Instant to an HL7 DTM. UTC is assumed.
      Parameters:
      instant - The instant to convert.
      Returns:
      the resulting HL7 DTM.
    • toDatetimeTs

      public static @NonNull TS toDatetimeTs(@NonNull TemporalAccessor temporal)
      Converts an Instant to a TS (TS.CH.TZ, Time Stamp) with a precision to the second. UTC is assumed.
      Parameters:
      temporal - The temporal object to convert.
      Returns:
      the resulting timestamp.
    • toDateTs

      public static @NonNull TS toDateTs(@NonNull TemporalAccessor temporal)
      Converts an Instant to a TS (TS.CH.TZ, Time Stamp) with a precision to the day. UTC is assumed.
      Parameters:
      temporal - The temporal object to convert.
      Returns:
      the resulting timestamp.
    • toDateTs

      public static @NonNull TS toDateTs(@NonNull TemporalAccessor temporal, ZoneId zone)
      Converts an Instant to a TS (TS.CH.TZ, Time Stamp) with a precision to the day with passed time zone.
      Parameters:
      temporal - The temporal object to convert.
      zone - time zone
      Returns:
      the resulting timestamp.
    • toLocalDate

      public static @Nullable LocalDate toLocalDate(@NonNull TS ts)
      Converts a TS (TS.CH.TZ, Time Stamp) to a local date. Only two formats are allowed in the TS.CH.TZ.
      Parameters:
      ts - The timestamp to convert.
      Returns:
      the equivalent local date or null if a null flavor was used in the ts.