| Crates.io | workdays |
| lib.rs | workdays |
| version | 0.1.3 |
| created_at | 2024-08-22 01:07:07.521301+00 |
| updated_at | 2024-08-28 22:42:47.341925+00 |
| description | A Rust library for computing work days and handling work calendars, inspired by the WORKDAY function in Excel. |
| homepage | |
| repository | https://github.com/swaits/workdays |
| max_upload_size | |
| id | 1347162 |
| size | 23,636 |
workdays is a Rust library for computing work days and handling work
calendars, inspired by the WORKDAY function in Excel. It provides functionality
to define custom work weeks, add holidays, and compute dates based on a given
number of work days.
Add workdays as a dependency in your Cargo.toml:
cargo add workdays
Here's a quick example:
use workdays::WorkCalendar;
use chrono::NaiveDate;
use std::str::FromStr;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut calendar = WorkCalendar::new();
calendar.add_holiday(NaiveDate::from_ymd_opt(2023, 12, 25).unwrap());
calendar.set_work_days("Mon,Tue,Wed,Thu,Fri")?;
let start_date = NaiveDate::from_ymd_opt(2023, 8, 21).unwrap();
let days_worked = 20;
let (end_date, calendar_duration) = calendar.compute_end_date(start_date, days_worked)?;
println!("End date: {}", end_date);
println!("Calendar duration: {} days", calendar_duration.num_days());
// Using FromStr to create a WorkCalendar from YAML or JSON
let config = r#"
work_days:
- Monday
- Tuesday
- Wednesday
holidays:
- 2023-12-25
"#;
let custom_calendar = WorkCalendar::from_str(config)?;
println!("Is Monday a work day? {}", custom_calendar.is_work_day(&chrono::Weekday::Mon));
Ok(())
}
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.