date_filter_search
date_filter_search is a Rust library for filtering and searching dates, designed to be integrated into applications.
The library supports parsing both absolute and relative date formats:
- Relative (time interval) – available keys:
Y,M,D,h,m,s- Examples:
"10m": 10 minutes from now."2Y": 2 years from now."6M": 6 months from now.
- Examples:
- Absolute (a specific date or a date range or part thereof) – allowed separators:
/,-,_,,:,;,.,,- Examples:
"2023-04-05 10:20:30": an exact date."2022-12": the entire month of December 2022."2021-3 to 2021-6": from March 2021 to June 2021.
- Examples:
Main Features
- Flexible Parsing:
Supports both absolute and relative formats to specify date intervals. - Conversion and Calculation:
Converts dates to seconds and allows arithmetic operations to calculate intervals and comparisons. - Error Handling:
Provides a robust error handling system with clear messages through theDateErrorenum. - Ease of Integration:
Designed for use in both graphical applications and command-line tools (for example, to filter logs or operation records).
Installation
Add the library to your Cargo.toml file:
[]
= "0.1.0"
Make sure to update the version according to the current release.
Usage
A practical example is available in the examples/ folder, demonstrating how to use date_filter_search in a command-line tool. To run the example:
Replace 1Y with the query you wish to test (e.g., 2021to2023).
API Reference
Main Functions
parsing_search(input: &str) -> Result<(u64, u64), DateError>
Parses the input—interpreting it as an absolute or relative interval—and returns a pair of timestamps (start and end).
search_generic(target: u64, lower_bound: u64, upper_bound: u64) -> bool
Checks whether the target timestamp falls between lower_bound and upper_bound (inclusive).
string_to_date_seconds(input: &str) -> Result<u64, DateError>
Converts a string representing a date into the number of seconds since a defined epoch.
Error Handling
The library uses the DateError enum to represent various errors that can occur during parsing or date conversion. Common errors include:
EmptyInput: The provided input is empty.
InvalidDateFormat: The date format does not match the expected specification.
InvalidRegex: The regex used for parsing is invalid.
OutOfRange(String): The specified value is out of the allowed range.
ParsingError(String): Error during value parsing.
IncorrectUnit(String): The unit for relative dates is not recognized.
Contributing
Contributions are welcome! If you’d like to improve the library:
Fork the repository.
Implement your changes.
Open a pull request describing your proposed changes.
License
This project is distributed under the terms of the GNU General Public License (GPL), which guarantees the freedom to redistribute and modify the software in accordance with free software standards
Author
Written by Catoni Mirko (IMprojtech)
Contacts and Resources
GitHub Repository: https://github.com/IMprojtech/Date_Filter_Search
Issue Tracker: Use the GitHub repository to report issues or request new features.