Skip to main content

CalendarPeriod

Enum CalendarPeriod 

Source
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

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> CalendarPeriod

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for CalendarPeriod

Source§

impl Debug for CalendarPeriod

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for CalendarPeriod

Source§

impl Hash for CalendarPeriod

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for CalendarPeriod

Source§

fn eq(&self, other: &CalendarPeriod) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for CalendarPeriod

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.