Class DateTimes
- java.lang.Object
-
- org.apache.druid.java.util.common.DateTimes
-
public final class DateTimes extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDateTimes.UtcFormatterSimple wrapper class to enforce UTC Chronology in formatter.
-
Field Summary
Fields Modifier and Type Field Description static PatternCOMMON_DATE_TIME_PATTERNThis pattern aims to match strings, produced byAbstractDateTime.toString().static org.joda.time.DateTimeCOMPARE_DATE_AS_STRING_MAXstatic org.joda.time.DateTimeCOMPARE_DATE_AS_STRING_MINstatic org.joda.time.DateTimeEPOCHstatic DateTimes.UtcFormatterISO_DATE_OPTIONAL_TIMEstatic DateTimes.UtcFormatterISO_DATE_OR_TIME_WITH_OFFSETstatic DateTimes.UtcFormatterISO_DATE_TIMEstatic org.joda.time.DateTimeMAXstatic org.joda.time.DateTimeMIN
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleancanCompareAsString(org.joda.time.DateTime dateTime)Returns true if the provided DateTime can be compared against other DateTimes using its string representation.static org.joda.time.DateTimeearlierOf(org.joda.time.DateTime a, org.joda.time.DateTime b)Returns the earlier of the two given dates.static org.joda.time.DateTimeZoneinferTzFromString(String tzId)static org.joda.time.DateTimeZoneinferTzFromString(String tzId, boolean fallback)static org.joda.time.DateTimelaterOf(org.joda.time.DateTime a, org.joda.time.DateTime b)Returns the later of the two given dates.static org.joda.time.DateTimemax(org.joda.time.DateTime dt1, org.joda.time.DateTime dt2)static org.joda.time.DateTimemin(org.joda.time.DateTime dt1, org.joda.time.DateTime dt2)static org.joda.time.DateTimenowUtc()static org.joda.time.DateTimeof(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour)static org.joda.time.DateTimeof(String instant)static intsubMonths(long timestamp1, long timestamp2, org.joda.time.DateTimeZone timeZone)static org.joda.time.DateTimeutc(long instant)static DateTimes.UtcFormatterwrapFormatter(org.joda.time.format.DateTimeFormatter formatter)Creates aDateTimes.UtcFormatterthat wraps around aDateTimeFormatter.
-
-
-
Field Detail
-
EPOCH
public static final org.joda.time.DateTime EPOCH
-
MAX
public static final org.joda.time.DateTime MAX
-
MIN
public static final org.joda.time.DateTime MIN
-
COMPARE_DATE_AS_STRING_MIN
public static final org.joda.time.DateTime COMPARE_DATE_AS_STRING_MIN
-
COMPARE_DATE_AS_STRING_MAX
public static final org.joda.time.DateTime COMPARE_DATE_AS_STRING_MAX
-
ISO_DATE_TIME
public static final DateTimes.UtcFormatter ISO_DATE_TIME
-
ISO_DATE_OPTIONAL_TIME
public static final DateTimes.UtcFormatter ISO_DATE_OPTIONAL_TIME
-
ISO_DATE_OR_TIME_WITH_OFFSET
public static final DateTimes.UtcFormatter ISO_DATE_OR_TIME_WITH_OFFSET
-
COMMON_DATE_TIME_PATTERN
public static final Pattern COMMON_DATE_TIME_PATTERN
This pattern aims to match strings, produced byAbstractDateTime.toString(). It's not rigorous: it could accept some strings that couldn't be obtained by calling toString() on anyDateTimeobject, and also it could not match some valid DateTime string. Use for heuristic purposes only.
-
-
Method Detail
-
inferTzFromString
public static org.joda.time.DateTimeZone inferTzFromString(String tzId)
-
inferTzFromString
public static org.joda.time.DateTimeZone inferTzFromString(String tzId, boolean fallback) throws IllegalArgumentException
- Returns:
- The dateTimezone for the provided {@param tzId}. If {@param fallback} is true, the default timezone will be returned if the tzId does not match a supported timezone.
- Throws:
IllegalArgumentException- if {@param fallback} is false and the provided tzId doesn't match a supported timezone.
-
wrapFormatter
public static DateTimes.UtcFormatter wrapFormatter(org.joda.time.format.DateTimeFormatter formatter)
Creates aDateTimes.UtcFormatterthat wraps around aDateTimeFormatter.- Parameters:
formatter- innerDateTimeFormatterused to parseString
-
utc
public static org.joda.time.DateTime utc(long instant)
-
of
public static org.joda.time.DateTime of(String instant)
-
of
public static org.joda.time.DateTime of(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour)
-
nowUtc
public static org.joda.time.DateTime nowUtc()
-
max
public static org.joda.time.DateTime max(org.joda.time.DateTime dt1, org.joda.time.DateTime dt2)
-
min
public static org.joda.time.DateTime min(org.joda.time.DateTime dt1, org.joda.time.DateTime dt2)
-
subMonths
public static int subMonths(long timestamp1, long timestamp2, org.joda.time.DateTimeZone timeZone)
-
canCompareAsString
public static boolean canCompareAsString(org.joda.time.DateTime dateTime)
Returns true if the provided DateTime can be compared against other DateTimes using its string representation. Useful when generating SQL queries to the metadata store, or any other situation where time comparisons on string representations might be useful. Conditions: the datetime must be between years 0 and 9999 (inclusive) and must be in the ISO UTC chronology. See alsoIntervals.canCompareEndpointsAsStrings(Interval).
-
earlierOf
public static org.joda.time.DateTime earlierOf(org.joda.time.DateTime a, org.joda.time.DateTime b)Returns the earlier of the two given dates. When passed a null and a non-null date, this method simply returns the non-null value.
-
laterOf
public static org.joda.time.DateTime laterOf(org.joda.time.DateTime a, org.joda.time.DateTime b)Returns the later of the two given dates. When passed a null and a non-null date, this method simply returns the non-null value.
-
-