DenseDateGrid

class DenseDateGrid(unit: AggregationDateUnit, timeZone: ZoneId)

Timezone-safe bucket-index arithmetic for dense date histograms.

MongoDB $densify has no timezone option: month/quarter/year stepping over raw dates drifts off the $dateTrunc(timezone) grid even for fixed offsets. Both backends therefore work in a integer bucket-index space anchored at a grid-aligned local midnight (Monday for WEEK); Mongo inverts indices with $dateAdd(timezone) and this class mirrors it with java.time, so the grids are identical by construction.

All index/key arithmetic runs on the LOCAL wall-clock timeline (LocalDateTime). Elapsed-instant arithmetic (ZonedDateTime with time-based units) would truncate half-hour zone-offset shifts — e.g. Australia/Lord_Howe (+10:00 at the 1970 anchor, +10:30 later) truncates 495264.5 elapsed hours to 495264 and lands on local :30, off the wall-clock hour grid.

Constructors

Link copied to clipboard
constructor(unit: AggregationDateUnit, timeZone: ZoneId)

Properties

Link copied to clipboard

Functions

Link copied to clipboard
fun gapIndices(fromMillis: Long, toMillis: Long): LongStream

Gap bucket indices strictly between the two instants' buckets, emitted in stream direction. The stream is lazy: callers facing a potentially huge gap (e.g. two SECOND buckets a year apart) consume it demand-driven instead of materializing every index.

Link copied to clipboard
fun indexOf(epochMillis: Long): Long

Index of the bucket containing epochMillis, floored: the result n always satisfies keyOf(n) <= epochMillis < keyOf(n + 1).

Link copied to clipboard
fun keyOf(index: Long): Long
Link copied to clipboard
fun keysBetween(fromMillis: Long, toMillis: Long): List<Long>

Grid keys strictly between the two bucket keys, emitted in stream direction.