pub enum TimeFrame {
Show 17 variants
Sec1,
Min1,
Min3,
Min5,
Min15,
Min30,
Hour1,
Hour2,
Hour4,
Hour6,
Hour8,
Hour12,
Day1,
Day3,
Week1,
Month1,
Year1,
}Expand description
An OHLCV sampling period.
Variants§
Implementations§
Source§impl TimeFrame
impl TimeFrame
Sourcepub fn from_label(s: &str) -> Result<TimeFrame, VolasError>
pub fn from_label(s: &str) -> Result<TimeFrame, VolasError>
Parse a label ("5m", "1h", "1d", "1M", "1w", "1y", "1s", plus
upper-case aliases).
Sourcepub fn unify(&self, ns: i64) -> i64
pub fn unify(&self, ns: i64) -> i64
Unify an epoch-ns timestamp to its period key (in UTC wall-clock). Two timestamps are in the same period iff their keys are equal.
Sourcepub fn unify_tz(&self, ns: i64, tz: Tz) -> i64
pub fn unify_tz(&self, ns: i64, tz: Tz) -> i64
Unify an epoch-ns timestamp to its period key in tz’s wall-clock, so that
hour+ buckets (e.g. daily bars) align to the local trading day — DST-aware
for a named zone. Storage stays UTC; only the bucketing uses tz.
Sourcepub fn period_start_ns(&self, ns: i64, tz: Tz) -> i64
pub fn period_start_ns(&self, ns: i64, tz: Tz) -> i64
The UTC epoch-ns instant at which ns’s period starts in tz’s
wall-clock — the bar label of a cumulated period (owner decision
2026-06-12: bar labels are the grid period start, origin + n·delta, not
the first raw timestamp). The grid mirrors TimeFrame::unify_tz
field-for-field: intraday frames anchor at local midnight (a 15-minute
bar starts at :00/:15/:30/:45), multi-hour frames at hours 0/k/2k…,
Day3 at the Unix epoch, Week1 on Monday, Month1/Year1 on the calendar.
A DST anomaly at the boundary resolves to the bucket’s earliest real
instant (see Tz::wall_to_utc_ns_earliest).
Sourcepub fn can_coarsen(self, dst: TimeFrame) -> bool
pub fn can_coarsen(self, dst: TimeFrame) -> bool
Whether this frame can be cleanly coarsened (aggregated) up to dst —
i.e. every dst bucket boundary is also a boundary of self, so each
dst bar is a whole number of self bars with none straddling.
Fixed-duration frames (≤ Week1) nest by duration divisibility on the
epoch grid. The calendar frames need care: a sub-day / 1-day frame nests
into a week / month / year (its boundaries fall on every UTC midnight,
hence on Monday week-starts and on the 1st), and a month nests into a year
— but a week or a 3-day bar does NOT nest into a month or year (ISO
weeks and epoch-anchored 3-day bars straddle calendar boundaries).