range_date
A Rust crate for handling date ranges with support for years, quarters, months, and days.
Features
- 🗓️ Multiple Date Periods: Support for Year(Y), Quarter(Q), Month(M), and Day(D) time periods
- 🔄 Type Conversion: String parsing and serialization support
- 📅 Date Calculations: Utilities like leap year detection
- ⚡ High Performance: Built on top of the efficient
chronolibrary - 🛡️ Type Safety: Complete type system with proper error handling
Quick Start
Add this to your Cargo.toml:
[]
= "0.1.1"
Usage Examples
Basic Usage
use ;
use FromStr;
// Create a date range for Q1 2024
let range = RangeDate ;
// String representation
println!; // Output: 2024Q1
// Parse from string
let parsed = from_str.unwrap;
println!; // RangeDate { year: 2024, range_type: Month, range_index: 3 }
Date Period Types
use DatePeriod;
// Supported time period types
let year = new.unwrap; // Year
let quarter = new.unwrap; // Quarter
let month = new.unwrap; // Month
let daily = new.unwrap; // Daily
Serialization Support
use RangeDate;
use FromStr;
use serde_json;
let range = from_str.unwrap;
let json = to_string.unwrap;
println!; // "2024Q2"
Date Range Format
The crate uses a compact string format for date ranges:
- Format:
YYYY[PERIOD][INDEX] - Examples:
2024Y1- Year 20242024Q2- Q2 2024 (April-June)2024M03- March 20242024D060- 60th day of 2024
API Documentation
For complete API documentation, visit docs.rs.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.