Class DateWrapper
- java.lang.Object
-
- org.schabi.newpipe.extractor.localization.DateWrapper
-
- All Implemented Interfaces:
java.io.Serializable
public class DateWrapper extends java.lang.Object implements java.io.SerializableA 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)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static DateWrapperfromInstant(java.lang.String date)Parses a date string that matches the ISO-8601Instantpattern, e.g.static DateWrapperfromOffsetDateTime(java.lang.String date)Parses a date string that matches the ISO-8601OffsetDateTimepattern, e.g.java.time.InstantgetInstant()java.time.LocalDateTimegetLocalDateTime()java.time.LocalDateTimegetLocalDateTime(java.time.ZoneId zoneId)booleanisApproximation()java.time.OffsetDateTimeoffsetDateTime()java.lang.StringtoString()
-
-
-
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
Instantas anOffsetDateTimeset to UTC.
-
getLocalDateTime
@Nonnull public java.time.LocalDateTime getLocalDateTime()
- Returns:
- the wrapped
Instantas aLocalDateTimein the current time zone.
-
getLocalDateTime
@Nonnull public java.time.LocalDateTime getLocalDateTime(@Nonnull java.time.ZoneId zoneId)- Returns:
- the wrapped
Instantas aLocalDateTimein 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:
toStringin classjava.lang.Object
-
fromOffsetDateTime
@Nullable public static DateWrapper fromOffsetDateTime(java.lang.String date) throws ParsingException
Parses a date string that matches the ISO-8601OffsetDateTimepattern, 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-8601Instantpattern, 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
-
-