Skip to main content
Version: Python

upper_bin

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

Syntax

upper_bin(dt, interval, offset=0)

Parameters

ParameterTypeDescription
dtDateTime

The DateTime for which to evaluate the end of the containing window.

intervalint

The size of the window in nanoseconds.

offsetint

The window start offset in nanoseconds. For example, a value of MINUTE would offset all windows by one minute. The default is 0.

Returns

The DateTime value binned to the interval and offset.

Examples

This example bins a DateTime to a 15 minute bin.

from deephaven.time import to_datetime, upper_bin

datetime = to_datetime("2022-01-01T00:35:00 NY")
nanos_bin = 900_000_000_000 #15 minutes
nanos_offset = 120_000_000_000 #2 minutes

result0 = upper_bin(datetime, nanos_bin)
print(result0)

result1 = upper_bin(datetime, nanos_bin, offset=nanos_offset)
print(result1)

This example bins multiple DateTimes to a 15 minute bin. Each DateTime in this example is in the same 15 minute window (from 00:30:00 to 00:45:00), upper_bin computes the same results.

from deephaven.time import to_datetime, upper_bin

datetime0 = to_datetime("2022-01-01T00:32:00 NY")
datetime1 = to_datetime("2022-01-01T00:35:00 NY")
datetime2 = to_datetime("2022-01-01T00:39:00 NY")

nanos_bin = 900_000_000_000 #15 minutes
nanos_offset = 120_000_000_000 #2 minutes

result0 = upper_bin(datetime0, nanos_bin)
result1 = upper_bin(datetime1, nanos_bin)
result2 = upper_bin(datetime2, nanos_bin)

print(result0)
print(result1)
print(result2)