Update documentation to use rustframe::utils for BDatesList and DatesList

This commit is contained in:
Palash Tyagi 2025-04-21 01:27:41 +01:00
parent 488f101618
commit 25e3405d85
2 changed files with 39 additions and 40 deletions

View File

@ -165,9 +165,9 @@ enum GroupKey {
/// ```rust /// ```rust
/// use chrono::NaiveDate; /// use chrono::NaiveDate;
/// use std::error::Error; /// use std::error::Error;
/// # use bdates::{BDatesList, BDateFreq}; // Replace bdates with your actual crate/module name /// use rustframe::utils::{BDatesList, BDateFreq}; // Replace bdates with your actual crate/module name
/// ///
/// # fn main() -> Result<(), Box<dyn Error>> { /// fn main() -> Result<(), Box<dyn Error>> {
/// let start_date = "2023-11-01".to_string(); // Wednesday /// let start_date = "2023-11-01".to_string(); // Wednesday
/// let end_date = "2023-11-07".to_string(); // Tuesday /// let end_date = "2023-11-07".to_string(); // Tuesday
/// let freq = BDateFreq::Daily; /// let freq = BDateFreq::Daily;
@ -184,8 +184,8 @@ enum GroupKey {
/// ///
/// assert_eq!(bdates.list()?, expected_dates); /// assert_eq!(bdates.list()?, expected_dates);
/// assert_eq!(bdates.count()?, 5); /// assert_eq!(bdates.count()?, 5);
/// # Ok(()) /// Ok(())
/// # } /// }
/// ``` /// ```
/// ///
/// **2. Using `from_n_periods` (Start Date and Count):** /// **2. Using `from_n_periods` (Start Date and Count):**
@ -193,9 +193,9 @@ enum GroupKey {
/// ```rust /// ```rust
/// use chrono::NaiveDate; /// use chrono::NaiveDate;
/// use std::error::Error; /// use std::error::Error;
/// # use bdates::{BDatesList, BDateFreq}; // Replace bdates with your actual crate/module name /// use rustframe::utils::{BDatesList, BDateFreq}; // Replace bdates with your actual crate/module name
/// ///
/// # fn main() -> Result<(), Box<dyn Error>> { /// fn main() -> Result<(), Box<dyn Error>> {
/// let start_date = "2024-02-28".to_string(); // Wednesday /// let start_date = "2024-02-28".to_string(); // Wednesday
/// let freq = BDateFreq::WeeklyFriday; /// let freq = BDateFreq::WeeklyFriday;
/// let n_periods = 3; /// let n_periods = 3;
@ -214,8 +214,8 @@ enum GroupKey {
/// assert_eq!(bdates.count()?, 3); /// assert_eq!(bdates.count()?, 3);
/// assert_eq!(bdates.start_date_str(), "2024-02-28"); // Keeps original start string /// assert_eq!(bdates.start_date_str(), "2024-02-28"); // Keeps original start string
/// assert_eq!(bdates.end_date_str(), "2024-03-15"); // End date is the last generated date /// assert_eq!(bdates.end_date_str(), "2024-03-15"); // End date is the last generated date
/// # Ok(()) /// Ok(())
/// # } /// }
/// ``` /// ```
/// ///
/// **3. Using `groups()`:** /// **3. Using `groups()`:**
@ -223,9 +223,9 @@ enum GroupKey {
/// ```rust /// ```rust
/// use chrono::NaiveDate; /// use chrono::NaiveDate;
/// use std::error::Error; /// use std::error::Error;
/// # use bdates::{BDatesList, BDateFreq}; // Replace bdates with your actual crate/module name /// use rustframe::utils::{BDatesList, BDateFreq}; // Replace bdates with your actual crate/module name
/// ///
/// # fn main() -> Result<(), Box<dyn Error>> { /// fn main() -> Result<(), Box<dyn Error>> {
/// let start_date = "2023-11-20".to_string(); // Mon, Week 47 /// let start_date = "2023-11-20".to_string(); // Mon, Week 47
/// let end_date = "2023-12-08".to_string(); // Fri, Week 49 /// let end_date = "2023-12-08".to_string(); // Fri, Week 49
/// let freq = BDateFreq::WeeklyMonday; /// let freq = BDateFreq::WeeklyMonday;
@ -239,8 +239,8 @@ enum GroupKey {
/// assert_eq!(groups[0], vec![NaiveDate::from_ymd_opt(2023, 11, 20).unwrap()]); // Week 47 /// assert_eq!(groups[0], vec![NaiveDate::from_ymd_opt(2023, 11, 20).unwrap()]); // Week 47
/// assert_eq!(groups[1], vec![NaiveDate::from_ymd_opt(2023, 11, 27).unwrap()]); // Week 48 /// assert_eq!(groups[1], vec![NaiveDate::from_ymd_opt(2023, 11, 27).unwrap()]); // Week 48
/// assert_eq!(groups[2], vec![NaiveDate::from_ymd_opt(2023, 12, 4).unwrap()]); // Week 49 /// assert_eq!(groups[2], vec![NaiveDate::from_ymd_opt(2023, 12, 4).unwrap()]); // Week 49
/// # Ok(()) /// Ok(())
/// # } /// }
/// ``` /// ```
impl BDatesList { impl BDatesList {
/// Creates a new `BDatesList` instance defined by a start and end date. /// Creates a new `BDatesList` instance defined by a start and end date.
@ -451,9 +451,9 @@ impl BDatesList {
/// ```rust /// ```rust
/// use chrono::NaiveDate; /// use chrono::NaiveDate;
/// use std::error::Error; /// use std::error::Error;
/// # use bdates::{BDatesGenerator, BDateFreq}; // Replace bdates with your actual crate/module name /// use rustframe::utils::{BDatesGenerator, BDateFreq};
/// ///
/// # fn main() -> Result<(), Box<dyn Error>> { /// fn main() -> Result<(), Box<dyn Error>> {
/// let start = NaiveDate::from_ymd_opt(2023, 12, 28).unwrap(); // Thursday /// let start = NaiveDate::from_ymd_opt(2023, 12, 28).unwrap(); // Thursday
/// let freq = BDateFreq::MonthEnd; /// let freq = BDateFreq::MonthEnd;
/// let n_periods = 4; // Dec '23, Jan '24, Feb '24, Mar '24 /// let n_periods = 4; // Dec '23, Jan '24, Feb '24, Mar '24
@ -466,8 +466,8 @@ impl BDatesList {
/// assert_eq!(generator.next(), Some(NaiveDate::from_ymd_opt(2024, 2, 29).unwrap())); // Leap year /// assert_eq!(generator.next(), Some(NaiveDate::from_ymd_opt(2024, 2, 29).unwrap())); // Leap year
/// assert_eq!(generator.next(), Some(NaiveDate::from_ymd_opt(2024, 3, 29).unwrap())); // Mar 31 is Sun /// assert_eq!(generator.next(), Some(NaiveDate::from_ymd_opt(2024, 3, 29).unwrap())); // Mar 31 is Sun
/// assert_eq!(generator.next(), None); // Exhausted /// assert_eq!(generator.next(), None); // Exhausted
/// # Ok(()) /// Ok(())
/// # } /// }
/// ``` /// ```
/// ///
/// **2. Collecting into a Vec:** /// **2. Collecting into a Vec:**
@ -475,9 +475,9 @@ impl BDatesList {
/// ```rust /// ```rust
/// use chrono::NaiveDate; /// use chrono::NaiveDate;
/// use std::error::Error; /// use std::error::Error;
/// # use bdates::{BDatesGenerator, BDateFreq}; // Replace bdates with your actual crate/module name /// use rustframe::utils::{BDatesGenerator, BDateFreq}; // Replace bdates with your actual crate/module name
/// ///
/// # fn main() -> Result<(), Box<dyn Error>> { /// fn main() -> Result<(), Box<dyn Error>> {
/// let start = NaiveDate::from_ymd_opt(2024, 4, 29).unwrap(); // Monday /// let start = NaiveDate::from_ymd_opt(2024, 4, 29).unwrap(); // Monday
/// let freq = BDateFreq::Daily; /// let freq = BDateFreq::Daily;
/// let n_periods = 5; /// let n_periods = 5;
@ -494,8 +494,8 @@ impl BDatesList {
/// ]; /// ];
/// ///
/// assert_eq!(dates, expected_dates); /// assert_eq!(dates, expected_dates);
/// # Ok(()) /// Ok(())
/// # } /// }
/// ``` /// ```
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct BDatesGenerator { pub struct BDatesGenerator {

View File

@ -164,7 +164,7 @@ enum GroupKey {
/// ```rust /// ```rust
/// use chrono::NaiveDate; /// use chrono::NaiveDate;
/// use std::error::Error; /// use std::error::Error;
/// # use dates::{DatesList, DateFreq}; // Assuming the crate/module is named 'dates' /// # use rustframe::utils::{DatesList, DateFreq}; // Assuming the crate/module is named 'dates'
/// ///
/// # fn main() -> Result<(), Box<dyn Error>> { /// # fn main() -> Result<(), Box<dyn Error>> {
/// let start_date = "2023-11-01".to_string(); // Wednesday /// let start_date = "2023-11-01".to_string(); // Wednesday
@ -194,9 +194,9 @@ enum GroupKey {
/// ```rust /// ```rust
/// use chrono::NaiveDate; /// use chrono::NaiveDate;
/// use std::error::Error; /// use std::error::Error;
/// # use dates::{DatesList, DateFreq}; /// use rustframe::utils::{DatesList, DateFreq};
/// ///
/// # fn main() -> Result<(), Box<dyn Error>> { /// fn main() -> Result<(), Box<dyn Error>> {
/// let start_date = "2024-02-28".to_string(); // Wednesday /// let start_date = "2024-02-28".to_string(); // Wednesday
/// let freq = DateFreq::WeeklyFriday; /// let freq = DateFreq::WeeklyFriday;
/// let n_periods = 3; /// let n_periods = 3;
@ -224,9 +224,9 @@ enum GroupKey {
/// ```rust /// ```rust
/// use chrono::NaiveDate; /// use chrono::NaiveDate;
/// use std::error::Error; /// use std::error::Error;
/// # use dates::{DatesList, DateFreq}; /// use rustframe::utils::{DatesList, DateFreq};
/// ///
/// # fn main() -> Result<(), Box<dyn Error>> { /// fn main() -> Result<(), Box<dyn Error>> {
/// let start_date = "2023-11-20".to_string(); // Mon, Week 47 /// let start_date = "2023-11-20".to_string(); // Mon, Week 47
/// let end_date = "2023-12-08".to_string(); // Fri, Week 49 /// let end_date = "2023-12-08".to_string(); // Fri, Week 49
/// let freq = DateFreq::MonthEnd; // Find month-ends /// let freq = DateFreq::MonthEnd; // Find month-ends
@ -238,8 +238,8 @@ enum GroupKey {
/// ///
/// assert_eq!(groups.len(), 1); // Only November's end date falls in the range /// assert_eq!(groups.len(), 1); // Only November's end date falls in the range
/// assert_eq!(groups[0], vec![NaiveDate::from_ymd_opt(2023, 11, 30).unwrap()]); // Nov 2023 group /// assert_eq!(groups[0], vec![NaiveDate::from_ymd_opt(2023, 11, 30).unwrap()]); // Nov 2023 group
/// # Ok(()) /// Ok(())
/// # } /// }
/// ``` /// ```
impl DatesList { impl DatesList {
/// Creates a new `DatesList` instance defined by a start and end date. /// Creates a new `DatesList` instance defined by a start and end date.
@ -422,10 +422,9 @@ impl DatesList {
/// ```rust /// ```rust
/// use chrono::NaiveDate; /// use chrono::NaiveDate;
/// use std::error::Error; /// use std::error::Error;
/// # // Replace 'your_crate_name' with the actual name if this is in a library /// use rustframe::utils::{DatesGenerator, DateFreq};
/// # use dates::{DatesGenerator, DateFreq};
/// ///
/// # fn main() -> Result<(), Box<dyn Error>> { /// fn main() -> Result<(), Box<dyn Error>> {
/// let start = NaiveDate::from_ymd_opt(2023, 12, 28).unwrap(); // Thursday /// let start = NaiveDate::from_ymd_opt(2023, 12, 28).unwrap(); // Thursday
/// let freq = DateFreq::MonthEnd; /// let freq = DateFreq::MonthEnd;
/// let n_periods = 4; // Dec '23, Jan '24, Feb '24, Mar '24 /// let n_periods = 4; // Dec '23, Jan '24, Feb '24, Mar '24
@ -438,8 +437,8 @@ impl DatesList {
/// assert_eq!(generator.next(), Some(NaiveDate::from_ymd_opt(2024, 2, 29).unwrap())); // Leap year /// assert_eq!(generator.next(), Some(NaiveDate::from_ymd_opt(2024, 2, 29).unwrap())); // Leap year
/// assert_eq!(generator.next(), Some(NaiveDate::from_ymd_opt(2024, 3, 31).unwrap())); /// assert_eq!(generator.next(), Some(NaiveDate::from_ymd_opt(2024, 3, 31).unwrap()));
/// assert_eq!(generator.next(), None); // Exhausted /// assert_eq!(generator.next(), None); // Exhausted
/// # Ok(()) /// Ok(())
/// # } /// }
/// ``` /// ```
/// ///
/// **2. Collecting into a Vec (Daily):** /// **2. Collecting into a Vec (Daily):**
@ -447,9 +446,9 @@ impl DatesList {
/// ```rust /// ```rust
/// use chrono::NaiveDate; /// use chrono::NaiveDate;
/// use std::error::Error; /// use std::error::Error;
/// # use dates::{DatesGenerator, DateFreq}; /// use rustframe::utils::{DatesGenerator, DateFreq};
/// ///
/// # fn main() -> Result<(), Box<dyn Error>> { /// fn main() -> Result<(), Box<dyn Error>> {
/// let start = NaiveDate::from_ymd_opt(2024, 4, 29).unwrap(); // Monday /// let start = NaiveDate::from_ymd_opt(2024, 4, 29).unwrap(); // Monday
/// let freq = DateFreq::Daily; /// let freq = DateFreq::Daily;
/// let n_periods = 5; /// let n_periods = 5;
@ -466,8 +465,8 @@ impl DatesList {
/// ]; /// ];
/// ///
/// assert_eq!(dates, expected_dates); /// assert_eq!(dates, expected_dates);
/// # Ok(()) /// Ok(())
/// # } /// }
/// ``` /// ```
/// ///
/// **3. Starting on the Exact Day (Weekly Monday):** /// **3. Starting on the Exact Day (Weekly Monday):**
@ -475,9 +474,9 @@ impl DatesList {
/// ```rust /// ```rust
/// use chrono::NaiveDate; /// use chrono::NaiveDate;
/// use std::error::Error; /// use std::error::Error;
/// # use dates::{DatesGenerator, DateFreq}; /// use rustframe::utils::{DatesGenerator, DateFreq};
/// ///
/// # fn main() -> Result<(), Box<dyn Error>> { /// fn main() -> Result<(), Box<dyn Error>> {
/// let start = NaiveDate::from_ymd_opt(2024, 1, 1).unwrap(); // Monday /// let start = NaiveDate::from_ymd_opt(2024, 1, 1).unwrap(); // Monday
/// let freq = DateFreq::WeeklyMonday; /// let freq = DateFreq::WeeklyMonday;
/// let n_periods = 3; /// let n_periods = 3;
@ -488,8 +487,8 @@ impl DatesList {
/// assert_eq!(generator.next(), Some(NaiveDate::from_ymd_opt(2024, 1, 8).unwrap())); /// assert_eq!(generator.next(), Some(NaiveDate::from_ymd_opt(2024, 1, 8).unwrap()));
/// assert_eq!(generator.next(), Some(NaiveDate::from_ymd_opt(2024, 1, 15).unwrap())); /// assert_eq!(generator.next(), Some(NaiveDate::from_ymd_opt(2024, 1, 15).unwrap()));
/// assert_eq!(generator.next(), None); /// assert_eq!(generator.next(), None);
/// # Ok(()) /// Ok(())
/// # } /// }
/// ``` /// ```
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct DatesGenerator { pub struct DatesGenerator {