fiscal-period is a type-safe Scala DSL for representing and manipulating fiscal periods with precise semantics and grain-based operations.
This library is built using the Tagless-Final approach to ensure type safety, modularity, and extensibility. It currently supports a standard monthly calendar system with plans for expanding to other calendar types in the future.
- Unified
Period[G]abstraction parameterized by granularityG(Day,Month,Quarter,Year) - Half-open intervals for
PeriodDay, closed intervals for coarser grains - Core operations:
intersect,union,diffcontains,rollup,next,prevmonthsIn, etc.
- Support for:
- Arbitrary fiscal year start months (e.g., April, October, etc.)
- Standard monthly calendar
val p1 = periodDay(LocalDate.parse("2024-04-01"), LocalDate.parse("2024-04-15"))
val p2 = periodDay(LocalDate.parse("2024-04-10"), LocalDate.parse("2024-04-20"))
val result = intersect(p1, p2)
// result: Some(PeriodDay(2024-04-10, 2024-04-15))This library is designed with algebraic properties in mind.
intersect(a, b)is commutative and associativecontains(a, b)follows antisymmetryrollupoperations respect calendar semantics and grain hierarchy- ...and more algebraic laws are implicitly respected by design
- ✅ Core DSL for period modeling
- ✅ Support for standard monthly calendar with arbitrary fiscal year start
- ⏳ Extension to other fiscal calendars (e.g., 5-4-4, 4-5-4)
- ⏳ Verified algebraic laws using Lean
We welcome contributions! Please feel free to submit issues or pull requests.
MIT License