Compare commits

..

1 Commits

5 changed files with 1395 additions and 234 deletions

View File

@ -44,7 +44,7 @@ use chrono::NaiveDate;
use rustframe::{ use rustframe::{
frame::{Frame, RowIndex}, frame::{Frame, RowIndex},
matrix::{BoolOps, Matrix, SeriesOps}, matrix::{BoolOps, Matrix, SeriesOps},
utils::{DateFreq, BDatesList}, utils::{BDateFreq, BDatesList},
}; };
let n_periods = 4; let n_periods = 4;
@ -53,7 +53,8 @@ let n_periods = 4;
let dates: Vec<NaiveDate> = let dates: Vec<NaiveDate> =
BDatesList::from_n_periods("2024-01-02".to_string(), BDateFreq::Daily, n_periods) BDatesList::from_n_periods("2024-01-02".to_string(), BDateFreq::Daily, n_periods)
.unwrap() .unwrap()
.list().unwrap(); .list()
.unwrap();
let col_names: Vec<String> = vec!["a".to_string(), "b".to_string()]; let col_names: Vec<String> = vec!["a".to_string(), "b".to_string()];

File diff suppressed because it is too large Load Diff

View File

@ -565,7 +565,7 @@ impl Iterator for DatesGenerator {
/// Generates the flat list of dates for the given range and frequency. /// Generates the flat list of dates for the given range and frequency.
/// Assumes the `collect_*` functions return sorted dates. /// Assumes the `collect_*` functions return sorted dates.
pub fn get_dates_list_with_freq( fn get_dates_list_with_freq(
start_date_str: &str, start_date_str: &str,
end_date_str: &str, end_date_str: &str,
freq: DateFreq, freq: DateFreq,
@ -733,19 +733,6 @@ fn collect_quarterly(
Ok(result) Ok(result)
} }
pub fn get_dates_list_with_freq_from_naive_date(
start_date: NaiveDate,
end_date: NaiveDate,
freq: DateFreq,
) -> Result<Vec<NaiveDate>, Box<dyn Error>> {
get_dates_list_with_freq(
&start_date.format("%Y-%m-%d").to_string(),
&end_date.format("%Y-%m-%d").to_string(),
freq,
)
}
/// Return either the first or last calendar day in each year of the range. /// Return either the first or last calendar day in each year of the range.
fn collect_yearly( fn collect_yearly(
start_date: NaiveDate, start_date: NaiveDate,
@ -832,7 +819,7 @@ fn last_day_of_month(year: i32, month: u32) -> Result<NaiveDate, Box<dyn Error>>
/// Converts a month number (1-12) to a quarter number (1-4). /// Converts a month number (1-12) to a quarter number (1-4).
/// Panics if month is invalid (should not happen with valid NaiveDate). /// Panics if month is invalid (should not happen with valid NaiveDate).
pub fn month_to_quarter(m: u32) -> u32 { fn month_to_quarter(m: u32) -> u32 {
match m { match m {
1..=3 => 1, 1..=3 => 1,
4..=6 => 2, 4..=6 => 2,
@ -912,7 +899,7 @@ fn get_first_date_helper(freq: DateFreq) -> fn(i32, u32) -> Result<NaiveDate, Bo
/// Finds the *first* valid date according to the frequency, /// Finds the *first* valid date according to the frequency,
/// starting the search *on or after* the given `start_date`. /// starting the search *on or after* the given `start_date`.
pub fn find_first_date_on_or_after( fn find_first_date_on_or_after(
start_date: NaiveDate, start_date: NaiveDate,
freq: DateFreq, freq: DateFreq,
) -> Result<NaiveDate, Box<dyn Error>> { ) -> Result<NaiveDate, Box<dyn Error>> {
@ -964,7 +951,7 @@ pub fn find_first_date_on_or_after(
/// Finds the *next* valid date according to the frequency, /// Finds the *next* valid date according to the frequency,
/// given the `current_date` (which is assumed to be a valid date previously generated). /// given the `current_date` (which is assumed to be a valid date previously generated).
pub fn find_next_date(current_date: NaiveDate, freq: DateFreq) -> Result<NaiveDate, Box<dyn Error>> { fn find_next_date(current_date: NaiveDate, freq: DateFreq) -> Result<NaiveDate, Box<dyn Error>> {
match freq { match freq {
DateFreq::Daily => current_date DateFreq::Daily => current_date
.succ_opt() .succ_opt()

View File

@ -1,8 +1,6 @@
pub mod bdates; pub mod bdates;
// pub use bdates::{BDateFreq, BDatesList, BDatesGenerator}; pub use bdates::{BDateFreq, BDatesList, BDatesGenerator};
pub mod dates; pub mod dates;
// pub use dates::{DateFreq, DatesList, DatesGenerator}; pub use dates::{DateFreq, DatesList, DatesGenerator};
// pub mod base;
// pub use base::{BDatesGenerator, BDatesList};
// pub use base::{DateFreq, DatesGenerator, DatesList};

View File

@ -1,5 +1,3 @@
pub mod dateutils; pub mod dateutils;
pub use dateutils::bdates::{BDatesGenerator, BDatesList}; pub use dateutils::{BDateFreq, BDatesGenerator, BDatesList};
pub use dateutils::dates::{DateFreq, DatesGenerator, DatesList}; pub use dateutils::{DateFreq, DatesGenerator, DatesList};
// pub use dateutils::{BDatesGenerator, BDatesList};
// pub use dateutils::{DateFreq, DatesGenerator, DatesList};