pub enum Period {
Year(i32),
Half(i32, u8),
Quarter(i32, u8),
Month(i32, u8),
Week(i32, u8),
Rolling(u32, NaiveDate),
}Expand description
A named time window with period-over-period semantics.
Variants§
Year(i32)
Half(i32, u8)
Quarter(i32, u8)
Month(i32, u8)
Week(i32, u8)
Rolling(u32, NaiveDate)
Last N days ending on a date.
Implementations§
Source§impl Period
impl Period
Sourcepub fn to_key(&self) -> String
pub fn to_key(&self) -> String
Canonical key string: 2026, 2026-H1, 2026-Q1, 2026-01,
2026-W02, last-30.
Sourcepub fn parse(text: &str) -> Result<Self>
pub fn parse(text: &str) -> Result<Self>
Parse 2026, 2026-H1, 2026-Q1, 2026-01, 2026-M1, 2026-W02,
last-N, this-*, previous-*.
Sourcepub fn parse_with_reference(text: &str, reference: NaiveDate) -> Result<Self>
pub fn parse_with_reference(text: &str, reference: NaiveDate) -> Result<Self>
Parse with an explicit reference date (testable).
Sourcepub fn date_range(&self) -> (NaiveDate, NaiveDate)
pub fn date_range(&self) -> (NaiveDate, NaiveDate)
Inclusive (start, end) dates of the period.
Sourcepub fn date_column(&self) -> &'static str
pub fn date_column(&self) -> &'static str
Which dim_date column equality-filters this period.
Sourcepub fn position_column(&self) -> Option<&'static str>
pub fn position_column(&self) -> Option<&'static str>
The positional column for apples-to-apples truncation of the previous period. None for Rolling (always complete).
Sourcepub fn days_elapsed(&self, reference: NaiveDate) -> i64
pub fn days_elapsed(&self, reference: NaiveDate) -> i64
Days elapsed within the period as of a reference date.
Sourcepub fn is_partial(&self, reference: NaiveDate) -> bool
pub fn is_partial(&self, reference: NaiveDate) -> bool
Is the period still in progress at the reference date?
Sourcepub fn effective_end_date(&self, reference: NaiveDate) -> NaiveDate
pub fn effective_end_date(&self, reference: NaiveDate) -> NaiveDate
The period’s end capped at the reference date.
Sourcepub fn column_for_key(key: &str) -> &'static str
pub fn column_for_key(key: &str) -> &'static str
Pick the dim_date column for an arbitrary period key string.
Trait Implementations§
impl StructuralPartialEq for Period
Auto Trait Implementations§
impl Freeze for Period
impl RefUnwindSafe for Period
impl Send for Period
impl Sync for Period
impl Unpin for Period
impl UnsafeUnpin for Period
impl UnwindSafe for Period
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more