Skip to main content
Version: Python

lower_bin

lower_bin returns a DateTime value, which is at the starting (lower) end of a time range defined by the interval nanoseconds. For example, a 15*MINUTE intervalNanos value would return the DateTime value for the start of the fifteen-minute window (00-15, 15-30, 30-45, 45-60) that contains the input date-time.

Syntax

lower_bin(dt, interval, offset=0)

Parameters

ParameterTypeDescription
dtDateTime

The DateTime for which to evaluate the start 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. Default is 0.

Returns

Returns the DateTime value at the start of the bin.

Examples

This example bins a DateTime to a 15 minute bin.

from deephaven.time import to_datetime, lower_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 = lower_bin(datetime, nanos_bin)
print(result0)

result1 = lower_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), so lower_bin computes the same results.

from deephaven.time import to_datetime, lower_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 = lower_bin(datetime0, nanos_bin)
result1 = lower_bin(datetime1, nanos_bin)
result2 = lower_bin(datetime2, nanos_bin)

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