pub enum TimeUnit {
Seconds,
Minutes,
Hours,
Days,
Weeks,
Months,
Years,
Ever,
}Expand description
Time unit definitions for interval configuration.
Represents different time granularities for event counting.
§Calendar-Aligned Buckets vs Uniform Buckets
Default (calendar-aligned):
- Buckets snap to calendar boundaries in local time
Daysrotate at local midnight (12:00 AM)Weeksrotate Monday at midnightMonthsrotate on the 1stYearsrotate January 1st
Uniform buckets (disable calendar feature):
- Buckets align to January 1st of the current year at 00:00 UTC
Days= 24-hour periods from that pointWeeks= 7-day periodsMonths= 30-day periods (not calendar months)Years= 365-day periods (ignores leap days)- All counters of the same time unit have aligned start times
§Why Calendar-Aligned by Default?
Best for client-side and user-facing use cases:
- Aligns to how users talk: “today”, “this week”, “this month”
- Day boundaries at local midnight (not arbitrary 24-hour windows)
- Matches how users think: “I used the app 3 times today”
- Works with daily/weekly/monthly goals and limits
Use uniform buckets (disable calendar feature) when you need:
- Consistent bucket sizes for statistical analysis
- Predictable memory usage (30 days ≈ 1 month)
- Industry-standard “30-day rolling window” (backend analytics)
- Better year approximation: 12 × 30 = 360 days (1.4% error vs 365)
TimeUnits are ordered from smallest to largest: Minutes < Hours < Days < Weeks < Months < Years < Ever
Ever is a special variant that represents “use the longest configured
time unit for this event.” It is resolved lazily during query execution.
Variants§
Implementations§
Trait Implementations§
Source§impl<'de> Deserialize<'de> for TimeUnit
impl<'de> Deserialize<'de> for TimeUnit
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl From<TimeUnit> for TimeWindow
impl From<TimeUnit> for TimeWindow
Source§impl Ord for TimeUnit
impl Ord for TimeUnit
Source§impl PartialOrd for TimeUnit
impl PartialOrd for TimeUnit
impl Copy for TimeUnit
impl Eq for TimeUnit
impl StructuralPartialEq for TimeUnit
Auto Trait Implementations§
impl Freeze for TimeUnit
impl RefUnwindSafe for TimeUnit
impl Send for TimeUnit
impl Sync for TimeUnit
impl Unpin for TimeUnit
impl UnwindSafe for TimeUnit
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