Package org.elasticsearch.common.time
Class DateUtils
java.lang.Object
org.elasticsearch.common.time.DateUtils
-
Field Summary
Modifier and TypeFieldDescriptionstatic long
static long
static long
static Instant
The maximum nanosecond resolution date we can properly handle. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Instant
clampToNanosRange(Instant instant)
Returns an instant that is with valid nanosecond resolution.static ZoneId
dateTimeZoneToZoneId(org.joda.time.DateTimeZone timeZone)
static ZonedDateTime
Returns the current UTC date-time with milliseconds precision.static ZonedDateTime
nowWithMillisResolution(Clock clock)
static ZoneId
static long
roundFloor(long utcMillis, long unitMillis)
Rounds the given utc milliseconds sicne the epoch down to the next unit millis Note: This does not check for correctness of the result, as this only works with units smaller or equal than a day In order to ensure the performance of this methods, there are no guards or checks in itstatic long
roundMonthOfYear(long utcMillis)
Round down to the beginning of the month of the year of the specified timestatic long
roundQuarterOfYear(long utcMillis)
Round down to the beginning of the quarter of the year of the specified timestatic long
roundWeekOfWeekYear(long utcMillis)
Round down to the beginning of the week based on week year of the specified timestatic long
roundYear(long utcMillis)
Round down to the beginning of the year of the specified timestatic Instant
toInstant(long nanoSecondsSinceEpoch)
convert a long value to a java time instant the long value resembles the nanoseconds since the epochstatic long
convert a java time instant to a long value which is stored in lucene the long value resembles the nanoseconds since the epochstatic long
toMilliSeconds(long nanoSecondsSinceEpoch)
Convert a nanosecond timestamp in millisecondsstatic long
toNanoSeconds(long milliSecondsSinceEpoch)
Convert a nanosecond timestamp in millisecondsstatic org.joda.time.DateTimeZone
zoneIdToDateTimeZone(ZoneId zoneId)
-
Field Details
-
MAX_MILLIS_BEFORE_9999
public static final long MAX_MILLIS_BEFORE_9999- See Also:
- Constant Field Values
-
MAX_MILLIS_BEFORE_MINUS_9999
public static final long MAX_MILLIS_BEFORE_MINUS_9999- See Also:
- Constant Field Values
-
DEPRECATED_SHORT_TZ_IDS
-
DEPRECATED_LONG_TIMEZONES
-
MAX_NANOSECOND_INSTANT
The maximum nanosecond resolution date we can properly handle. -
MAX_NANOSECOND
public static final long MAX_NANOSECOND
-
-
Constructor Details
-
DateUtils
public DateUtils()
-
-
Method Details
-
zoneIdToDateTimeZone
-
dateTimeZoneToZoneId
-
of
-
toLong
convert a java time instant to a long value which is stored in lucene the long value resembles the nanoseconds since the epoch- Parameters:
instant
- the instant to convert- Returns:
- the nano seconds and seconds as a single long
-
clampToNanosRange
Returns an instant that is with valid nanosecond resolution. If the parameter is before the valid nanosecond range then this returns the minimum Instant valid for nanosecond resultion. If the parameter is after the valid nanosecond range then this returns the maximum Instant valid for nanosecond resolution.Useful for checking if all values for the field are within some range, even if the range's endpoints are not valid nanosecond resolution.
-
toInstant
convert a long value to a java time instant the long value resembles the nanoseconds since the epoch- Parameters:
nanoSecondsSinceEpoch
- the nanoseconds since the epoch- Returns:
- the instant resembling the specified date
-
toNanoSeconds
public static long toNanoSeconds(long milliSecondsSinceEpoch)Convert a nanosecond timestamp in milliseconds- Parameters:
milliSecondsSinceEpoch
- the millisecond since the epoch- Returns:
- the nanoseconds since the epoch
-
toMilliSeconds
public static long toMilliSeconds(long nanoSecondsSinceEpoch)Convert a nanosecond timestamp in milliseconds- Parameters:
nanoSecondsSinceEpoch
- the nanoseconds since the epoch- Returns:
- the milliseconds since the epoch
-
roundFloor
public static long roundFloor(long utcMillis, long unitMillis)Rounds the given utc milliseconds sicne the epoch down to the next unit millis Note: This does not check for correctness of the result, as this only works with units smaller or equal than a day In order to ensure the performance of this methods, there are no guards or checks in it- Parameters:
utcMillis
- the milliseconds since the epochunitMillis
- the unit to round to- Returns:
- the rounded milliseconds since the epoch
-
roundQuarterOfYear
public static long roundQuarterOfYear(long utcMillis)Round down to the beginning of the quarter of the year of the specified time- Parameters:
utcMillis
- the milliseconds since the epoch- Returns:
- The milliseconds since the epoch rounded down to the quarter of the year
-
roundMonthOfYear
public static long roundMonthOfYear(long utcMillis)Round down to the beginning of the month of the year of the specified time- Parameters:
utcMillis
- the milliseconds since the epoch- Returns:
- The milliseconds since the epoch rounded down to the month of the year
-
roundYear
public static long roundYear(long utcMillis)Round down to the beginning of the year of the specified time- Parameters:
utcMillis
- the milliseconds since the epoch- Returns:
- The milliseconds since the epoch rounded down to the beginning of the year
-
roundWeekOfWeekYear
public static long roundWeekOfWeekYear(long utcMillis)Round down to the beginning of the week based on week year of the specified time- Parameters:
utcMillis
- the milliseconds since the epoch- Returns:
- The milliseconds since the epoch rounded down to the beginning of the week based on week year
-
nowWithMillisResolution
Returns the current UTC date-time with milliseconds precision. In Java 9+ (as opposed to Java 8) theClock
implementation uses system's best clock implementation (which could mean that the precision of the clock can be milliseconds, microseconds or nanoseconds), whereas in Java 8System.currentTimeMillis()
is always used. To account for these differences, this method defines a newClock
which will offer a value forZonedDateTime.now()
set to always have milliseconds precision.- Returns:
ZonedDateTime
instance for the current date-time with milliseconds precision in UTC
-
nowWithMillisResolution
-