idlefox/src/date/mod.rs

66 lines
2.7 KiB
Rust

//! The `date` module provides functionality to parse dates from strings and perform operations on dates.
//!
//! It consists of two submodules:
//!
//! - `dateparse`: This submodule is responsible for parsing a string representation of a date into a vector of [date_parse::DateObject] instances.
//! It utilizes in house representation of date as they are without context and therefore dont represent a real date yet.
//!
//! - `date_tools`: This submodule offers utility functions for working with dates.
//! It's main goal is do give a context for a subjective and incomplete date to transform it into a [chrono::NaiveDate] type from the chrono crate.
//!
//! # Functions
//!
//! The following functions are re-exported from the `date_tools` submodule:
//!
//! - [parse_date_list]: This function parses a given input string representing date information and returns a `NaiveDateList`,
//! which is a collection of sequential or random accessible date objects. If there are any unparsed parts
//! left after processing the input, they can be retrieved using the `unparsed` method on the returned `Result`.
//! The function uses the context provided to resolve any relative dates within the input string.
//!
//! - [`parse_single_date`]: This function parses a given input string representing a single date and returns a `NaiveDate`.
//! If there are any unparsed parts left after processing the input, they can be retrieved using the `unparsed` method on the returned `Result`.
//! The function uses the context provided to resolve any relative dates within the input string.
//!
//! # Examples
//!
//! ```
//! # use idlefox::date::parse_date_list;
//! # use chrono::NaiveDate;
//! let input = "Oct 5, Nov 15 - 18, sat, mon , tue-fry and some other text";
//! let context = NaiveDate::from_ymd_opt(2023, 10, 1);
//! let result = parse_date_list(input, context);
//! assert!(result.is_ok());
//! match result {
//! Ok(date_list) => println!("Parsed dates: {}", date_list.len()),
//! Err(e) => eprintln!("Error parsing dates: {}", e),
//! }
//! ```
#![allow(dead_code)]
// All structures
/// A punctual day (just one date)
pub struct DateEventPunctual {}
/// An interval
pub struct DateEventInterval {}
/// A date, wether punctual or interval
pub struct DateEventDate {}
/// A series of dates or intervals
pub struct DateEvent {}
// Defines date routines
pub mod date_parse;
pub mod date_tools;
// Republishing important functions
pub use date_parse::parse_str_into_date;
pub use date_tools::parse_date_list;
pub use date_tools::parse_single_date;
pub use date_tools::NaiveDateList;
pub use date_tools::NaiveDateObject;
// pub use date_tools::naivelistfromstr;
// pub use date_tools::naivedayfromstr;