mirror of
https://github.com/Magnus167/rustframe.git
synced 2025-08-20 04:00:01 +00:00
Make fields in DatesGenerator public for improved accessibility
This commit is contained in:
parent
e5d8f4386c
commit
f4d52f0ce8
@ -492,10 +492,10 @@ impl DatesList {
|
|||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct DatesGenerator {
|
pub struct DatesGenerator {
|
||||||
freq: DateFreq,
|
pub freq: DateFreq,
|
||||||
periods_remaining: usize,
|
pub periods_remaining: usize,
|
||||||
// Stores the *next* date to be yielded by the iterator.
|
// Stores the *next* date to be yielded by the iterator.
|
||||||
next_date_candidate: Option<NaiveDate>,
|
pub next_date_candidate: Option<NaiveDate>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DatesGenerator {
|
impl DatesGenerator {
|
||||||
@ -745,7 +745,6 @@ pub fn get_dates_list_with_freq_from_naive_date(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// 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,
|
||||||
@ -964,7 +963,10 @@ 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>> {
|
pub 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()
|
||||||
@ -1498,7 +1500,8 @@ mod tests {
|
|||||||
// And trying to move *past* it should fail
|
// And trying to move *past* it should fail
|
||||||
let day_before = NaiveDate::MAX - Duration::days(1);
|
let day_before = NaiveDate::MAX - Duration::days(1);
|
||||||
let target_day_after = NaiveDate::MAX.weekday().succ(); // Day after MAX's weekday
|
let target_day_after = NaiveDate::MAX.weekday().succ(); // Day after MAX's weekday
|
||||||
assert!(move_to_day_of_week_on_or_after(day_before, target_day_after).is_err()); // Moving past MAX fails
|
assert!(move_to_day_of_week_on_or_after(day_before, target_day_after).is_err());
|
||||||
|
// Moving past MAX fails
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -1910,13 +1913,11 @@ mod tests {
|
|||||||
assert!(find_next_date(NaiveDate::MAX, DateFreq::MonthEnd).is_err());
|
assert!(find_next_date(NaiveDate::MAX, DateFreq::MonthEnd).is_err());
|
||||||
|
|
||||||
// Test finding next quarter start after Q4 MAX_YEAR -> Q1 (MAX_YEAR+1) (fail)
|
// Test finding next quarter start after Q4 MAX_YEAR -> Q1 (MAX_YEAR+1) (fail)
|
||||||
assert!(
|
assert!(find_next_date(
|
||||||
find_next_date(
|
|
||||||
first_day_of_quarter(NaiveDate::MAX.year(), 4)?,
|
first_day_of_quarter(NaiveDate::MAX.year(), 4)?,
|
||||||
DateFreq::QuarterStart
|
DateFreq::QuarterStart
|
||||||
)
|
)
|
||||||
.is_err()
|
.is_err());
|
||||||
);
|
|
||||||
|
|
||||||
// Test finding next quarter end after Q3 MAX_YEAR -> Q4 MAX_YEAR (fails because last_day_of_quarter(MAX, 4) fails)
|
// Test finding next quarter end after Q3 MAX_YEAR -> Q4 MAX_YEAR (fails because last_day_of_quarter(MAX, 4) fails)
|
||||||
let q3_end_max_year = last_day_of_quarter(NaiveDate::MAX.year(), 3)?;
|
let q3_end_max_year = last_day_of_quarter(NaiveDate::MAX.year(), 3)?;
|
||||||
@ -1927,22 +1928,18 @@ mod tests {
|
|||||||
assert!(find_next_date(NaiveDate::MAX, DateFreq::QuarterEnd).is_err());
|
assert!(find_next_date(NaiveDate::MAX, DateFreq::QuarterEnd).is_err());
|
||||||
|
|
||||||
// Test finding next year start after Jan 1 MAX_YEAR -> Jan 1 (MAX_YEAR+1) (fail)
|
// Test finding next year start after Jan 1 MAX_YEAR -> Jan 1 (MAX_YEAR+1) (fail)
|
||||||
assert!(
|
assert!(find_next_date(
|
||||||
find_next_date(
|
|
||||||
first_day_of_year(NaiveDate::MAX.year())?,
|
first_day_of_year(NaiveDate::MAX.year())?,
|
||||||
DateFreq::YearStart
|
DateFreq::YearStart
|
||||||
)
|
)
|
||||||
.is_err()
|
.is_err());
|
||||||
);
|
|
||||||
|
|
||||||
// Test finding next year end after Dec 31 (MAX_YEAR-1) -> Dec 31 MAX_YEAR (ok)
|
// Test finding next year end after Dec 31 (MAX_YEAR-1) -> Dec 31 MAX_YEAR (ok)
|
||||||
assert!(
|
assert!(find_next_date(
|
||||||
find_next_date(
|
|
||||||
last_day_of_year(NaiveDate::MAX.year() - 1)?,
|
last_day_of_year(NaiveDate::MAX.year() - 1)?,
|
||||||
DateFreq::YearEnd
|
DateFreq::YearEnd
|
||||||
)
|
)
|
||||||
.is_ok()
|
.is_ok());
|
||||||
);
|
|
||||||
|
|
||||||
// Test finding next year end after Dec 31 MAX_YEAR -> Dec 31 (MAX_YEAR+1) (fail)
|
// Test finding next year end after Dec 31 MAX_YEAR -> Dec 31 (MAX_YEAR+1) (fail)
|
||||||
assert!(
|
assert!(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user