Path: blob/main/crates/polars-time/src/windows/bounds.rs
6939 views
use super::group_by::ClosedWindow;12#[derive(Copy, Clone, Debug)]3pub struct Bounds {4pub(crate) start: i64,5pub(crate) stop: i64,6}78impl Bounds {9/// Create a new [`Bounds`] and check the input is correct.10pub(crate) fn new_checked(start: i64, stop: i64) -> Self {11assert!(12start <= stop,13"boundary start must be smaller than stop; is your time column sorted in ascending order?\14\nIf you did a group_by, note that null values are a separate group."15);16Self::new(start, stop)17}1819/// Create a new [`Bounds`] without checking input correctness.20pub(crate) fn new(start: i64, stop: i64) -> Self {21Bounds { start, stop }22}2324/// Duration in unit for this Boundary25#[inline]26pub(crate) fn duration(&self) -> i64 {27self.stop - self.start28}2930// check if unit is within bounds31#[inline]32pub(crate) fn is_member(&self, t: i64, closed: ClosedWindow) -> bool {33match closed {34ClosedWindow::Right => t > self.start && t <= self.stop,35ClosedWindow::Left => t >= self.start && t < self.stop,36ClosedWindow::None => t > self.start && t < self.stop,37ClosedWindow::Both => t >= self.start && t <= self.stop,38}39}4041#[inline]42pub(crate) fn is_member_entry(&self, t: i64, closed: ClosedWindow) -> bool {43match closed {44ClosedWindow::Right => t > self.start,45ClosedWindow::Left => t >= self.start,46ClosedWindow::None => t > self.start,47ClosedWindow::Both => t >= self.start,48}49}5051#[inline]52pub(crate) fn is_member_exit(&self, t: i64, closed: ClosedWindow) -> bool {53match closed {54ClosedWindow::Right => t <= self.stop,55ClosedWindow::Left => t < self.stop,56ClosedWindow::None => t < self.stop,57ClosedWindow::Both => t <= self.stop,58}59}6061#[inline]62pub(crate) fn is_future(&self, t: i64, closed: ClosedWindow) -> bool {63match closed {64ClosedWindow::Left | ClosedWindow::None => self.stop <= t,65ClosedWindow::Both | ClosedWindow::Right => self.stop < t,66}67}6869#[inline]70pub(crate) fn is_past(&self, t: i64, closed: ClosedWindow) -> bool {71match closed {72ClosedWindow::Left | ClosedWindow::Both => self.start > t,73ClosedWindow::None | ClosedWindow::Right => self.start >= t,74}75}76}777879