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 class
DateTimes.UtcFormatter
Simple wrapper class to enforce UTC Chronology in formatter.
-
Field Summary
Fields Modifier and Type Field Description static Pattern
COMMON_DATE_TIME_PATTERN
This pattern aims to match strings, produced byAbstractDateTime.toString()
.static org.joda.time.DateTime
COMPARE_DATE_AS_STRING_MAX
static org.joda.time.DateTime
COMPARE_DATE_AS_STRING_MIN
static org.joda.time.DateTime
EPOCH
static DateTimes.UtcFormatter
ISO_DATE_OPTIONAL_TIME
static DateTimes.UtcFormatter
ISO_DATE_OR_TIME_WITH_OFFSET
static DateTimes.UtcFormatter
ISO_DATE_TIME
static org.joda.time.DateTime
MAX
static org.joda.time.DateTime
MIN
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
canCompareAsString(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.DateTime
earlierOf(org.joda.time.DateTime a, org.joda.time.DateTime b)
Returns the earlier of the two given dates.static org.joda.time.DateTimeZone
inferTzFromString(String tzId)
static org.joda.time.DateTimeZone
inferTzFromString(String tzId, boolean fallback)
static org.joda.time.DateTime
laterOf(org.joda.time.DateTime a, org.joda.time.DateTime b)
Returns the later of the two given dates.static org.joda.time.DateTime
max(org.joda.time.DateTime dt1, org.joda.time.DateTime dt2)
static org.joda.time.DateTime
min(org.joda.time.DateTime dt1, org.joda.time.DateTime dt2)
static org.joda.time.DateTime
nowUtc()
static org.joda.time.DateTime
of(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour)
static org.joda.time.DateTime
of(String instant)
static int
subMonths(long timestamp1, long timestamp2, org.joda.time.DateTimeZone timeZone)
static org.joda.time.DateTime
utc(long instant)
static DateTimes.UtcFormatter
wrapFormatter(org.joda.time.format.DateTimeFormatter formatter)
Creates aDateTimes.UtcFormatter
that 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 anyDateTime
object, 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.UtcFormatter
that wraps around aDateTimeFormatter
.- Parameters:
formatter
- innerDateTimeFormatter
used 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.
-
-