bdays

License bdays on Travis CI bdays on crates.io bdays on docs.rs

Provides functions to perform business days calculation between dates, given a Holiday Calendar.

A Business Day is defined as a weekday that is not a holiday.

To check if a date is a holiday, you must provide an implementation of the HolidayCalendar trait.

This crate is a port of BusinessDays.jl to the Rust programming language.

Provided Holiday Calendars

This crate provides a set of built-in holiday calendars in the bdays::calendars submodule.

Usage

```rust use chrono::NaiveDate; use bdays::HolidayCalendar;

// creates a holiday calendar instance let cal = bdays::calendars::WeekendsOnly;

let d0 = NaiveDate::fromymd(2018, 11, 22); let d1 = NaiveDate::fromymd(2018, 11, 24); let d2 = NaiveDate::from_ymd(2018, 11, 26);

// checks if a date is a holiday asserteq!( cal.isholiday(d0), false );

// checks if a date is a business day asserteq!( cal.isbday(d0), true ); asserteq!( cal.isbday(d1), false );

// adjusts to the last/next business day asserteq!( cal.tobday(d1, false), NaiveDate::fromymd(2018, 11, 23) ); asserteq!( cal.to_bday(d1, true) , d2 );

// advances a number of business days asserteq!( cal.advancebdays(d0, 2), d2 ); asserteq!( cal.advancebdays(d2, -2), d0 );

// returns the number of business days between dates asserteq!( cal.bdays(d0, d2), 2); asserteq!( cal.bdays(d2, d0), -2); ```

HolidayCalendarCache

As a motivation, this example might take some time to finish. ```rust extern crate bdays; extern crate chrono;

use chrono::NaiveDate; use bdays::HolidayCalendar;

let cal = bdays::calendars::brazil::BRSettlement; let d0 = NaiveDate::fromymd(2001, 2, 1); let d1 = NaiveDate::fromymd(2100, 2, 1);

for _i in 0..30 { cal.bdays(d0, d1); } `` You can useHolidayCalendarCache` to perform fast business days calculation for a given range of dates.

```rust use chrono::NaiveDate; use bdays::HolidayCalendar;

let cal = bdays::HolidayCalendarCache::new( bdays::calendars::brazil::BRSettlement, NaiveDate::fromymd(1980, 1, 1), NaiveDate::fromymd(2100, 12, 31) );

let d0 = NaiveDate::fromymd(2001, 2, 1); let d1 = NaiveDate::fromymd(2100, 2, 1);

for _i in 0..30 { cal.bdays(d0, d1); } ```