Package ca.uhn.fhir.util
Class DateUtils
java.lang.Object
ca.uhn.fhir.util.DateUtils
A utility class for parsing and formatting HTTP dates as used in cookies and
other headers. This class handles dates as defined by RFC 2616 section
3.3.1 as well as some other common non-standard formats.
This class is basically intended to be a high-performance workaround for the fact that Java SimpleDateFormat is kind of expensive to create and yet isn't thread safe.
This class was adapted from the class with the same name from the Jetty project, licensed under the terms of the Apache Software License 2.0.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final TimeZone
GMT TimeZonestatic final String
Date format pattern used to parse HTTP date headers in ANSI Casctime()
format.static final String
Date format pattern used to parse HTTP date headers in RFC 1036 format.static final String
Date format pattern used to parse HTTP date headers in RFC 1123 format. -
Method Summary
Modifier and TypeMethodDescriptionstatic int
convertDateToDayInteger
(Date theDateValue) static String
convertDateToIso8601String
(Date theDateValue) static Optional
<LocalDateTime> extractLocalDateTimeForRangeEndOrEmpty
(TemporalAccessor theTemporalAccessor) Calculate a LocalDateTime with any missing date/time data points defaulting to the latest values (ex 23 for hour) from a TemporalAccessor or empty if it doesn't contain a year.static Optional
<LocalDateTime> extractLocalDateTimeForRangeStartOrEmpty
(TemporalAccessor theTemporalAccessor) Calculate a LocalDateTime with any missing date/time data points defaulting to the earliest values (ex 0 for hour) from a TemporalAccessor or empty if it doesn't contain a year.static String
formatDate
(Date date) Formats the given date according to the RFC 1123 pattern.getCompletedDate
(String theIncompleteDateStr) Convert an incomplete date e.g.static Date
getEndOfDay
(Date theDate) static Date
getHighestInstantFromDate
(Date theDateValue) static Date
getLowestInstantFromDate
(Date theDateValue) static <T> T
static Date
Parses a date value.static Optional
<TemporalAccessor> parseDateTimeStringIfValid
(String theDateTimeString, DateTimeFormatter theSupportedDateTimeFormatter) With the provided DateTimeFormatter, parse a date time String or return empty if the String doesn't correspond to the formatter.
-
Field Details
-
GMT
GMT TimeZone -
PATTERN_RFC1123
Date format pattern used to parse HTTP date headers in RFC 1123 format.- See Also:
-
PATTERN_RFC1036
Date format pattern used to parse HTTP date headers in RFC 1036 format.- See Also:
-
PATTERN_ASCTIME
Date format pattern used to parse HTTP date headers in ANSI Casctime()
format.- See Also:
-
-
Method Details
-
extractLocalDateTimeForRangeStartOrEmpty
public static Optional<LocalDateTime> extractLocalDateTimeForRangeStartOrEmpty(TemporalAccessor theTemporalAccessor) Calculate a LocalDateTime with any missing date/time data points defaulting to the earliest values (ex 0 for hour) from a TemporalAccessor or empty if it doesn't contain a year.- Parameters:
theTemporalAccessor
- The TemporalAccessor containing date/time information- Returns:
- A LocalDateTime or empty
-
extractLocalDateTimeForRangeEndOrEmpty
public static Optional<LocalDateTime> extractLocalDateTimeForRangeEndOrEmpty(TemporalAccessor theTemporalAccessor) Calculate a LocalDateTime with any missing date/time data points defaulting to the latest values (ex 23 for hour) from a TemporalAccessor or empty if it doesn't contain a year.- Parameters:
theTemporalAccessor
- The TemporalAccessor containing date/time information- Returns:
- A LocalDateTime or empty
-
parseDateTimeStringIfValid
public static Optional<TemporalAccessor> parseDateTimeStringIfValid(String theDateTimeString, DateTimeFormatter theSupportedDateTimeFormatter) With the provided DateTimeFormatter, parse a date time String or return empty if the String doesn't correspond to the formatter.- Parameters:
theDateTimeString
- A date/time String in some date formattheSupportedDateTimeFormatter
- The DateTimeFormatter we expect corresponds to the String- Returns:
- The parsed TemporalAccessor or empty
-
parseDate
Parses a date value. The formats used for parsing the date value are retrieved from the default http params.- Parameters:
theDateValue
- the date value to parse- Returns:
- the parsed date or null if input could not be parsed
-
getHighestInstantFromDate
-
getLowestInstantFromDate
-
convertDateToDayInteger
-
convertDateToIso8601String
-
formatDate
Formats the given date according to the RFC 1123 pattern.- Parameters:
date
- The date to format.- Returns:
- An RFC 1123 formatted date string.
- See Also:
-
notNull
-
getCompletedDate
public static org.apache.commons.lang3.tuple.Pair<String,String> getCompletedDate(String theIncompleteDateStr) Convert an incomplete date e.g. 2020 or 2020-01 to a complete date with lower bound to the first day of the year/month, and upper bound to the last day of the year/month e.g. 2020 to 2020-01-01 (left), 2020-12-31 (right) 2020-02 to 2020-02-01 (left), 2020-02-29 (right)- Parameters:
theIncompleteDateStr
- 2020 or 2020-01- Returns:
- a pair of complete date, left is lower bound, and right is upper bound
-
getEndOfDay
-