pub enum CalendarPeriod {
Day,
Week,
Month,
Quarter,
Year,
}Expand description
A calendar period. Periods are anchored to the calendar, never to an arbitrary start date: months begin on the 1st, quarters on Jan/Apr/Jul/Oct 1, years on Jan 1, and weeks on the ISO Monday.
§Deliberate divergence from Fava (quarters)
Fava’s _IntervalQuarter.get_prev tests date.month > i where it needs
>=, so it puts April in Q1, July in Q2 and October in Q3 — every quarter
boundary month falls into the preceding quarter. Reported as
beancount/fava#2318. rustledger anchors quarters correctly, per the
project’s Python-compatibility policy: match correct behavior, not bugs.
A custom "budget" on a "quarterly" interval therefore accrues over
different boundaries than Fava’s budget view for those three months.
Variants§
Day
One calendar day.
Week
An ISO week, starting Monday.
Month
A calendar month (28, 29, 30 or 31 days).
Quarter
A calendar quarter, anchored at Jan/Apr/Jul/Oct 1.
Year
A calendar year (365 or 366 days).
Implementations§
Source§impl CalendarPeriod
impl CalendarPeriod
Sourcepub fn start_of(self, day: NaiveDate) -> NaiveDate
pub fn start_of(self, day: NaiveDate) -> NaiveDate
The first day of the period containing day.
Falls back to day itself if the truncated date would be out of range,
which keeps this total rather than panicking on ledger-derived dates.
For month, quarter and year that fallback is unreachable: the 1st of a
real month always exists. For WEEK it is reachable at the very start of
the representable calendar, where the containing ISO week begins before
NaiveDate::MIN and there is no Monday to return; the result then is the
day itself, NOT a week start. No ledger reaches that date, but the
saturation is real and this says so rather than implying stricter
semantics than the code provides.
Sourcepub fn next_start(self, start: NaiveDate) -> Option<NaiveDate>
pub fn next_start(self, start: NaiveDate) -> Option<NaiveDate>
The first day of the period after the one starting at start, or None
when that date is outside the representable range.
start is expected to be a period start (the output of Self::start_of);
the difference between this and start is the period’s true calendar
length, which is what makes a per-day accrual divide by 28/29/30/31 for a
month and 365/366 for a year.
Returning None rather than saturating to start is deliberate: a
caller measuring the period’s length would otherwise get zero and, after
the usual .max(1) guard, divide by a single day — inflating a yearly
budget by ~365x near the end of the representable range, silently and
with no error anywhere.
Sourcepub fn period_days(self, start: NaiveDate) -> i64
pub fn period_days(self, start: NaiveDate) -> i64
The calendar length, in days, of the period starting at start.
Equal to the gap to Self::next_start wherever that date exists. The
final period of the representable calendar has no representable next
start, but its LENGTH is still well defined, and this returns it: a day
and a week are fixed-length, and month, quarter and year boundaries all
coincide with the end of the calendar, so the span to the last
representable day is the whole period.
Pro-rata accrual needs the length, not the boundary date. Deriving the
length from next_start alone forced callers to give up on the final
period entirely — a budget was reported as 0.00 for a window inside
it, which reads as “nothing budgeted” rather than “cannot say”.
Trait Implementations§
Source§impl Clone for CalendarPeriod
impl Clone for CalendarPeriod
Source§fn clone(&self) -> CalendarPeriod
fn clone(&self) -> CalendarPeriod
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for CalendarPeriod
Source§impl Debug for CalendarPeriod
impl Debug for CalendarPeriod
impl Eq for CalendarPeriod
Source§impl Hash for CalendarPeriod
impl Hash for CalendarPeriod
Source§impl PartialEq for CalendarPeriod
impl PartialEq for CalendarPeriod
impl StructuralPartialEq for CalendarPeriod
Auto Trait Implementations§
impl Freeze for CalendarPeriod
impl RefUnwindSafe for CalendarPeriod
impl Send for CalendarPeriod
impl Sync for CalendarPeriod
impl Unpin for CalendarPeriod
impl UnsafeUnpin for CalendarPeriod
impl UnwindSafe for CalendarPeriod
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.