mirror of
https://github.com/Magnus167/rustframe.git
synced 2025-08-20 04:19:59 +00:00
Merge branch 'main' into frame_update
This commit is contained in:
commit
006a9f6ce2
@ -165,9 +165,9 @@ enum GroupKey {
|
||||
/// ```rust
|
||||
/// use chrono::NaiveDate;
|
||||
/// 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 end_date = "2023-11-07".to_string(); // Tuesday
|
||||
/// let freq = BDateFreq::Daily;
|
||||
@ -184,8 +184,8 @@ enum GroupKey {
|
||||
///
|
||||
/// assert_eq!(bdates.list()?, expected_dates);
|
||||
/// assert_eq!(bdates.count()?, 5);
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// **2. Using `from_n_periods` (Start Date and Count):**
|
||||
@ -193,9 +193,9 @@ enum GroupKey {
|
||||
/// ```rust
|
||||
/// use chrono::NaiveDate;
|
||||
/// 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 freq = BDateFreq::WeeklyFriday;
|
||||
/// let n_periods = 3;
|
||||
@ -214,8 +214,8 @@ enum GroupKey {
|
||||
/// assert_eq!(bdates.count()?, 3);
|
||||
/// 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
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// **3. Using `groups()`:**
|
||||
@ -223,9 +223,9 @@ enum GroupKey {
|
||||
/// ```rust
|
||||
/// use chrono::NaiveDate;
|
||||
/// 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 end_date = "2023-12-08".to_string(); // Fri, Week 49
|
||||
/// 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[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
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
impl BDatesList {
|
||||
/// Creates a new `BDatesList` instance defined by a start and end date.
|
||||
@ -451,9 +451,9 @@ impl BDatesList {
|
||||
/// ```rust
|
||||
/// use chrono::NaiveDate;
|
||||
/// 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 freq = BDateFreq::MonthEnd;
|
||||
/// 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, 3, 29).unwrap())); // Mar 31 is Sun
|
||||
/// assert_eq!(generator.next(), None); // Exhausted
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// **2. Collecting into a Vec:**
|
||||
@ -475,9 +475,9 @@ impl BDatesList {
|
||||
/// ```rust
|
||||
/// use chrono::NaiveDate;
|
||||
/// 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 freq = BDateFreq::Daily;
|
||||
/// let n_periods = 5;
|
||||
@ -494,8 +494,8 @@ impl BDatesList {
|
||||
/// ];
|
||||
///
|
||||
/// assert_eq!(dates, expected_dates);
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct BDatesGenerator {
|
||||
|
@ -164,7 +164,7 @@ enum GroupKey {
|
||||
/// ```rust
|
||||
/// use chrono::NaiveDate;
|
||||
/// 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>> {
|
||||
/// let start_date = "2023-11-01".to_string(); // Wednesday
|
||||
@ -194,9 +194,9 @@ enum GroupKey {
|
||||
/// ```rust
|
||||
/// use chrono::NaiveDate;
|
||||
/// 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 freq = DateFreq::WeeklyFriday;
|
||||
/// let n_periods = 3;
|
||||
@ -224,9 +224,9 @@ enum GroupKey {
|
||||
/// ```rust
|
||||
/// use chrono::NaiveDate;
|
||||
/// 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 end_date = "2023-12-08".to_string(); // Fri, Week 49
|
||||
/// 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[0], vec![NaiveDate::from_ymd_opt(2023, 11, 30).unwrap()]); // Nov 2023 group
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
impl DatesList {
|
||||
/// Creates a new `DatesList` instance defined by a start and end date.
|
||||
@ -422,10 +422,9 @@ impl DatesList {
|
||||
/// ```rust
|
||||
/// use chrono::NaiveDate;
|
||||
/// use std::error::Error;
|
||||
/// # // Replace 'your_crate_name' with the actual name if this is in a library
|
||||
/// # 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(2023, 12, 28).unwrap(); // Thursday
|
||||
/// let freq = DateFreq::MonthEnd;
|
||||
/// 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, 3, 31).unwrap()));
|
||||
/// assert_eq!(generator.next(), None); // Exhausted
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// **2. Collecting into a Vec (Daily):**
|
||||
@ -447,9 +446,9 @@ impl DatesList {
|
||||
/// ```rust
|
||||
/// use chrono::NaiveDate;
|
||||
/// 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 freq = DateFreq::Daily;
|
||||
/// let n_periods = 5;
|
||||
@ -466,8 +465,8 @@ impl DatesList {
|
||||
/// ];
|
||||
///
|
||||
/// assert_eq!(dates, expected_dates);
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// **3. Starting on the Exact Day (Weekly Monday):**
|
||||
@ -475,9 +474,9 @@ impl DatesList {
|
||||
/// ```rust
|
||||
/// use chrono::NaiveDate;
|
||||
/// 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 freq = DateFreq::WeeklyMonday;
|
||||
/// 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, 15).unwrap()));
|
||||
/// assert_eq!(generator.next(), None);
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DatesGenerator {
|
||||
|
@ -1,6 +1,6 @@
|
||||
pub mod bdates;
|
||||
pub use bdates::{BDateFreq, BDatesList};
|
||||
pub use bdates::{BDateFreq, BDatesList, BDatesGenerator};
|
||||
|
||||
pub mod dates;
|
||||
pub use dates::{DateFreq, DatesList};
|
||||
pub use dates::{DateFreq, DatesList, DatesGenerator};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user