Class DateWrapper

  • All Implemented Interfaces:
    java.io.Serializable

    public class DateWrapper
    extends java.lang.Object
    implements java.io.Serializable
    A wrapper class that provides a field to describe if the date/time is precise or just an approximation.
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      DateWrapper​(java.time.Instant instant)  
      DateWrapper​(java.time.Instant instant, boolean isApproximation)  
      DateWrapper​(java.time.LocalDateTime dateTime, boolean isApproximation)  
      DateWrapper​(java.time.OffsetDateTime offsetDateTime)  
      DateWrapper​(java.time.OffsetDateTime offsetDateTime, boolean isApproximation)  
    • Constructor Detail

      • DateWrapper

        public DateWrapper​(@Nonnull
                           java.time.OffsetDateTime offsetDateTime)
      • DateWrapper

        public DateWrapper​(@Nonnull
                           java.time.OffsetDateTime offsetDateTime,
                           boolean isApproximation)
      • DateWrapper

        public DateWrapper​(@Nonnull
                           java.time.Instant instant)
      • DateWrapper

        public DateWrapper​(@Nonnull
                           java.time.Instant instant,
                           boolean isApproximation)
      • DateWrapper

        public DateWrapper​(@Nonnull
                           java.time.LocalDateTime dateTime,
                           boolean isApproximation)
    • Method Detail

      • getInstant

        @Nonnull
        public java.time.Instant getInstant()
        Returns:
        the wrapped Instant
      • offsetDateTime

        @Nonnull
        public java.time.OffsetDateTime offsetDateTime()
        Returns:
        the wrapped Instant as an OffsetDateTime set to UTC.
      • getLocalDateTime

        @Nonnull
        public java.time.LocalDateTime getLocalDateTime()
        Returns:
        the wrapped Instant as a LocalDateTime in the current time zone.
      • getLocalDateTime

        @Nonnull
        public java.time.LocalDateTime getLocalDateTime​(@Nonnull
                                                        java.time.ZoneId zoneId)
        Returns:
        the wrapped Instant as a LocalDateTime in the given time zone.
      • isApproximation

        public boolean isApproximation()
        Returns:
        if the date is considered is precise or just an approximation (e.g. service only returns an approximation like 2 weeks ago instead of a precise date).
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • fromOffsetDateTime

        @Nullable
        public static DateWrapper fromOffsetDateTime​(java.lang.String date)
                                              throws ParsingException
        Parses a date string that matches the ISO-8601 OffsetDateTime pattern, e.g. "2011-12-03T10:15:30+01:00".
        Parameters:
        date - The date string
        Returns:
        a non-approximate DateWrapper, or null if the string is null
        Throws:
        ParsingException - if the string does not match the expected format
      • fromInstant

        @Nullable
        public static DateWrapper fromInstant​(java.lang.String date)
                                       throws ParsingException
        Parses a date string that matches the ISO-8601 Instant pattern, e.g. "2011-12-03T10:15:30Z".
        Parameters:
        date - The date string
        Returns:
        a non-approximate DateWrapper, or null if the string is null
        Throws:
        ParsingException - if the string does not match the expected format