Skip to content

knih/fiscal-period

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fiscal-period

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.

Features

  • Unified Period[G] abstraction parameterized by granularity G (Day, Month, Quarter, Year)
  • Half-open intervals for PeriodDay, closed intervals for coarser grains
  • Core operations:
    • intersect, union, diff
    • contains, rollup, next, prev
    • monthsIn, etc.
  • Support for:
    • Arbitrary fiscal year start months (e.g., April, October, etc.)
    • Standard monthly calendar

Quick Example

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))

Algebraic Design

This library is designed with algebraic properties in mind.

  • intersect(a, b) is commutative and associative
  • contains(a, b) follows antisymmetry
  • rollup operations respect calendar semantics and grain hierarchy
  • ...and more algebraic laws are implicitly respected by design

Roadmap

  • ✅ 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

Contributing

We welcome contributions! Please feel free to submit issues or pull requests.

License

MIT License

About

A type-safe and extensible DSL for computing and working with fiscal periods, implemented in the tagless-final style.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages