Skip to main content
Version: Java (Groovy)

upperBin

upperBin returns a date-time value, which is at the ending (upper) end of a time range defined by the interval nanoseconds. For example, a 5*MINUTE intervalNanos value would return the instant value for the end of the five-minute window that contains the input instant.

Syntax

upperBin(instant, intervalNanos)
upperBin(instant, interval)
upperBin(dateTime, intervalNanos)
upperBin(dateTime, interval)
upperBin(instant, intervalNanos, offset)
upperBin(instant, interval, offset)
upperBin(dateTime, intervalNanos, offset)
upperBin(dateTime, interval, offset)

Parameters

ParameterTypeDescription
instantInstant

The date-time for which to evaluate the end of the containing window.

dateTimeZonedDateTime

The date-time for which to evaluate the end of the containing window.

intervalNanoslong

The time interval represented as nanoseconds. If this parameter is used, the offset parameter must also be in nanoseconds.

intervalDuration

The time interval represented as a Duration. If this parameter is used, the offset parameter must also be a Duration.

offsetlong

The window end offset in nanoseconds. For example, a value of MINUTE would offset all windows by one minute.

offsetDuration

The window end offset as a Duration. For example, a value of "PT1M" would offset all windows by one minute.

Returns

A date-time representing the end of the window.

Example

The following example converts a date-time to the upper end of a 15-minute interval. Output is shown for no offset and an offset of 2 minutes.

import io.deephaven.time.DateTimeUtils
datetime = parseInstant("2020-01-01T00:35:00 ET")
nanos_bin = MINUTE * 15
nanos_offset = MINUTE * 2
duration_bin = parseDuration("PT15M")
duration_offset = parseDuration("PT2M")

// no offset
result1 = DateTimeUtils.upperBin(datetime, nanos_bin)
println result1

// offset of two minutes
result2 = DateTimeUtils.upperBin(datetime, nanos_bin, nanos_offset)
println result2

// repeat result2, but with duration types
result2_durations = DateTimeUtils.upperBin(datetime, duration_bin, duration_offset)
println result2_durations