Class DateWrapper

java.lang.Object
org.schabi.newpipe.extractor.localization.DateWrapper
All Implemented Interfaces:
Serializable

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

    • DateWrapper

      public DateWrapper(@Nonnull OffsetDateTime offsetDateTime)
    • DateWrapper

      public DateWrapper(@Nonnull OffsetDateTime offsetDateTime, boolean isApproximation)
    • DateWrapper

      public DateWrapper(@Nonnull Instant instant)
    • DateWrapper

      public DateWrapper(@Nonnull Instant instant, boolean isApproximation)
    • DateWrapper

      public DateWrapper(@Nonnull LocalDateTime dateTime, boolean isApproximation)
  • Method Details

    • getInstant

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

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

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

      @Nonnull public LocalDateTime getLocalDateTime(@Nonnull 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 String toString()
      Overrides:
      toString in class Object
    • fromOffsetDateTime

      @Nullable public static DateWrapper fromOffsetDateTime(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(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