Skip to content

Add the BDay type with tests and docs#71

Merged
felipenoris merged 2 commits intoJuliaFinance:masterfrom
adranka:add_bday_type
Mar 25, 2026
Merged

Add the BDay type with tests and docs#71
felipenoris merged 2 commits intoJuliaFinance:masterfrom
adranka:add_bday_type

Conversation

@adranka
Copy link
Copy Markdown
Contributor

@adranka adranka commented Jan 10, 2026

Adds the BDay type as suggested in #53.

julia> using BusinessDays, Dates

julia> bd = BDay(5, :USNYSE)
5 business days (USNYSE)

julia> Date(2025, 1, 1)  + bd
2025-01-10

The BDay type uses advancebdays under the hood so it should behave identically.

I'm also subtyping on Dates.DatePeriod so I tried to implement as many of the Period functions from the Dates stdlib as I could, e.g. with gcd:

julia> gcd(BDay(15, :USNYSE), BDay(21, :USNYSE))
3 business days (USNYSE)  

These functions will throw an error if the calendars are not the same:

julia> gcd(BDay(15, :USNYSE), BDay(21, :USSettlement))
ERROR: ArgumentError: Cannot compute gcd of BDay periods with different calendars: BusinessDays.USNYSE() vs BusinessDays.USSettlement()
Stacktrace:
 [1] gcd(bd1::BDay{BusinessDays.USNYSE}, bd2::BDay{BusinessDays.USSettlement})
   @ BusinessDays ~/code/BusinessDays.jl/src/bday.jl:165
 [2] top-level scope
   @ REPL[12]:1
 [3] top-level scope
   @ REPL:1

Developed with support from Claude Code AI.

@felipenoris let me know if this looks okay, or if you'd prefer this type to be outside BusinessDays.jl, I could put it in it's package instead.

Closes #53

@felipenoris
Copy link
Copy Markdown
Collaborator

Awesome! Thanks!

@felipenoris felipenoris merged commit 5f099dd into JuliaFinance:master Mar 25, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add type to easily add or substract business days

2 participants