Package org.gbif.api.util
Class IsoDateInterval
- java.lang.Object
-
- org.gbif.api.util.IsoDateInterval
-
public class IsoDateInterval extends Object
Represents an ISO 8601:2019 date, date-time or date/date-time interval.
Valid serializations include 2023, 2023-08, 2023-08-29, 2023/2024, 2023-08/2023-09 and so on.
-
-
Constructor Summary
Constructors Constructor Description IsoDateInterval()
Create an empty DateRange.IsoDateInterval(Temporal date)
Create a range with bounds ofdate
.IsoDateInterval(Temporal from, Temporal to)
Create a range with boundsfrom
andto
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static IsoDateInterval
fromString(String text)
Parses a well-formatted IsoDateInterval from the text representation.static IsoDateInterval
fromString(String textFrom, String textTo)
Parses a well-formatted IsoDateInterval from the text representation.Temporal
getFrom()
Temporal
getTo()
void
setFrom(String textFrom)
void
setFrom(Temporal from)
void
setTo(String textTo)
void
setTo(Temporal to)
String
toString()
Returns the date-time interval formatted as a single value where the from and to values are the same (e.g.String
toString(boolean ignoreNonUTCOffset)
Returns the date-time interval formatted as a single value where the from and to values are the same (e.g.
-
-
-
Constructor Detail
-
IsoDateInterval
public IsoDateInterval()
Create an empty DateRange.
-
IsoDateInterval
public IsoDateInterval(Temporal date)
Create a range with bounds ofdate
.
-
IsoDateInterval
public IsoDateInterval(Temporal from, Temporal to)
Create a range with boundsfrom
andto
. from and to must have the same type.- Throws:
IllegalArgumentException
- iffrom
is greater thanto
-
-
Method Detail
-
toString
public String toString()
Returns the date-time interval formatted as a single value where the from and to values are the same (e.g. "2023"), or as unabbreviated date-times at the defined accuracy otherwise ("2023-08-29/2023-08-30" rather than "2023-08-29/30").
-
toString
public String toString(boolean ignoreNonUTCOffset)
Returns the date-time interval formatted as a single value where the from and to values are the same (e.g. "2023"), or as unabbreviated date-times at the defined accuracy otherwise ("2023-08-29/2023-08-30" rather than "2023-08-29/30"). Optionally ignore a non-UTC offset.
-
fromString
public static IsoDateInterval fromString(String text) throws ParseException
Parses a well-formatted IsoDateInterval from the text representation.- Throws:
ParseException
-
fromString
public static IsoDateInterval fromString(String textFrom, String textTo) throws ParseException
Parses a well-formatted IsoDateInterval from the text representation.- Throws:
ParseException
-
-