Crates.io | business |
lib.rs | business |
version | 0.1.0 |
source | src |
created_at | 2022-10-04 21:14:14.057733 |
updated_at | 2022-10-04 21:14:14.057733 |
description | Rust business day calculations |
homepage | https://github.com/ameykusurkar/business-rs |
repository | https://github.com/ameykusurkar/business-rs.git |
max_upload_size | |
id | 680160 |
size | 28,228 |
A crate for doing business day calculations. It is a Rust implementation of GoCardless' business Ruby gem.
Let's dive right in with an example. For more details, see [Calendar
].
use chrono::NaiveDate;
let xmas = NaiveDate::from_ymd(2020, 12, 25); // Friday
let cal = business::Calendar::with_holidays(&[xmas]);
assert_eq!(cal.is_business_day(xmas), false);
// The earliest business day
assert_eq!(cal.roll_forward(xmas), NaiveDate::from_ymd(2020, 12, 28));
let xmas_eve = NaiveDate::from_ymd(2020, 12, 24);
assert_eq!(cal.is_business_day(xmas_eve), true);
// Skips over weekend and business holidays
assert_eq!(cal.add_business_days(xmas_eve, 2), NaiveDate::from_ymd(2020, 12, 29));
Calendar
from YAMLThe YAML has to be in the following format:
# Defaults to Mon-Fri if omitted
working_days:
- monday
- tuesday
- wednesday
- thursday
- friday
# ISO 8601 dates, defaults to no holidays if omitted
holidays:
- 2017-12-25
- 2017-12-26
A calendar can be built as such:
let yml = std::fs::read_to_string("examples/basic/cal.yml").unwrap();
let cal: Calendar = serde_yaml::from_str(&yml).unwrap();