Package org.gbif.api.util
Class IsoDateParsingUtils
- java.lang.Object
-
- org.gbif.api.util.IsoDateParsingUtils
-
public class IsoDateParsingUtils extends Object
Utility class that parses date values, the allowed date formats are: "yyyy-MM-dd", "yyyy-MM" or "yyyy". Note: Does not handle times or time zones. This is used for search queries/predicates with date ranges. Date ranges are closed at the lower bound, and open at the upper bound, to allow less-than predicates to match times on the upper bound date (i.e. after midnight).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classIsoDateParsingUtils.IsoDateFormatEnumerations with the allowed date formats by the occurrence search service.
-
Field Summary
Fields Modifier and Type Field Description static DateTimeFormatterISO_DATE_FORMATTERstatic StringSIMPLE_ISO_DATE_STR_PATTERNstatic PatternSIMPLE_ISO_PATTERN
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static IsoDateParsingUtils.IsoDateFormatgetFirstDateFormatMatch(String value)Iterates over all the OccurrenceDateFormat's and returns the first one that parses successfully the value.static LocalDateparseDate(String value)Parses a single date value.static Range<LocalDate>parseDateRange(String value)Parses a closed-open range of dates, using the most specific format for each side of the range.static TemporalparseTemporal(String value)Parses an ISO 8601-format date or date-time.static TemporalAccessorstripOffsetOrZone(TemporalAccessor temporalAccessor, boolean ignoreOffset)Remove the offset, either ignoring it or using it to adjust the time.static TemporalAccessorstripOffsetOrZoneExceptUTC(TemporalAccessor temporalAccessor, boolean ignoreOffset)Remove the offset, either ignoring it or using it to adjust the time, unless the offset is 0 (UTC).
-
-
-
Field Detail
-
SIMPLE_ISO_DATE_STR_PATTERN
public static final String SIMPLE_ISO_DATE_STR_PATTERN
- See Also:
- Constant Field Values
-
SIMPLE_ISO_PATTERN
public static final Pattern SIMPLE_ISO_PATTERN
-
ISO_DATE_FORMATTER
public static final DateTimeFormatter ISO_DATE_FORMATTER
-
-
Method Detail
-
getFirstDateFormatMatch
public static IsoDateParsingUtils.IsoDateFormat getFirstDateFormatMatch(String value) throws IllegalArgumentException
Iterates over all the OccurrenceDateFormat's and returns the first one that parses successfully the value.- Throws:
IllegalArgumentException- in case of unparsable dates
-
parseTemporal
public static Temporal parseTemporal(String value)
Parses an ISO 8601-format date or date-time.
-
parseDate
public static LocalDate parseDate(String value)
Parses a single date value. The date is interpreted using the first available date format that successfully parses the value.- Returns:
- the lowest possible date according to the precision given or null in case of *
- Throws:
IllegalArgumentException- in case of unparsable dates
-
parseDateRange
public static Range<LocalDate> parseDateRange(String value)
Parses a closed-open range of dates, using the most specific format for each side of the range. Returns null for an unbounded side of the range (*).
-
stripOffsetOrZone
public static TemporalAccessor stripOffsetOrZone(TemporalAccessor temporalAccessor, boolean ignoreOffset)
Remove the offset, either ignoring it or using it to adjust the time.
-
stripOffsetOrZoneExceptUTC
public static TemporalAccessor stripOffsetOrZoneExceptUTC(TemporalAccessor temporalAccessor, boolean ignoreOffset)
Remove the offset, either ignoring it or using it to adjust the time, unless the offset is 0 (UTC).
-
-