module

Finfry::Recurrence

Maps a recurrence cadence to a per-day cost. We pay on a cadence (monthly, yearly, …) but want to see the cost amortized per day — derived purely from the cadence, not from accrual bookkeeping.

Constants

AVG_MONTH = 365.25 / 12
AVG_YEAR = 365.25
DAYS = {"daily" => 1.0, "weekly" => 7.0, "biweekly" => 14.0, "monthly" => 365.25 / 12, "quarterly" => 365.25 / 4, "yearly" => 365.25}

Average days per period. Months/quarters/years use 365.25/N so leap years and uneven month lengths wash out.

Class methods

advance(date : String, cadence : String) : String

The date one cadence after date (ISO "YYYY-MM-DD"). Month/year steps clamp to valid days (Jan 31 + monthly => Feb 28/29).

Source
days(name : String) : Float64
Source
names

Cadence names, in ascending period length (for help text / enums).

Source
occurrences(from : String, cadence : String, through : String) : Array(String)

Occurrence dates from from (inclusive) stepping by cadence up to and including through. Used to catch up the due queue.

Source
per_day(cents : Int64, name : String) : Float64

Per-day cost in (fractional) cents for an amount paid on this cadence.

Source
valid?(name : String) : Bool
Source