mirror of
https://github.com/Magnus167/rustframe.git
synced 2025-08-20 23:40:01 +00:00
Compare commits
26 Commits
9f96d280de
...
c35926fc27
Author | SHA1 | Date | |
---|---|---|---|
![]() |
c35926fc27 | ||
2bc375f950 | |||
![]() |
37d10cbc7d | ||
![]() |
1c41d387ef | ||
![]() |
38baf0c648 | ||
![]() |
2e6c4bd6bb | ||
![]() |
6bb1c2a0de | ||
![]() |
d670ab4a5c | ||
![]() |
eb09593b0a | ||
![]() |
29c304d512 | ||
![]() |
7c96439550 | ||
![]() |
76b8824ce3 | ||
![]() |
00befe7ee4 | ||
![]() |
41349e2dba | ||
![]() |
9ab3a7c2c1 | ||
![]() |
88a08e1063 | ||
4a5485cddd | |||
97e8f3d55c | |||
88b608ea1b | |||
80779ac6e5 | |||
d42da5ad7b | |||
e2db5eb315 | |||
bdef7f1732 | |||
2b4ef8a371 | |||
![]() |
1213d588ec | ||
![]() |
a76963ec2e |
25
.github/workflows/docs-and-testcov.yml
vendored
25
.github/workflows/docs-and-testcov.yml
vendored
@ -44,6 +44,14 @@ jobs:
|
||||
toolchain: stable
|
||||
override: true
|
||||
|
||||
- name: Replace logo URL in README.md
|
||||
env:
|
||||
LOGO_URL: ${{ secrets.LOGO_URL }}
|
||||
run: |
|
||||
# replace with EXAMPLE.COM/LOGO
|
||||
|
||||
sed -i 's|.github/rustframe_logo.png|rustframe_logo.png|g' README.md
|
||||
|
||||
- name: Build documentation
|
||||
run: cargo doc --no-deps --release
|
||||
|
||||
@ -96,16 +104,25 @@ jobs:
|
||||
run: |
|
||||
# mkdir docs
|
||||
mkdir -p target/doc/docs
|
||||
cp -r target/doc/rustframe/* target/doc/docs/
|
||||
mv target/doc/rustframe/* target/doc/docs/
|
||||
|
||||
mkdir output
|
||||
cp tarpaulin-report.html target/doc/docs/
|
||||
cp tarpaulin-report.json target/doc/docs/
|
||||
cp tarpaulin-badge.json target/doc/docs/
|
||||
cp last-commit-date.json target/doc/docs/
|
||||
mkdir -p target/doc/.github
|
||||
cp .github/rustframe_logo.png target/doc/.github/rustframe_logo.png
|
||||
# cp -r .github target/doc/docs
|
||||
cp .github/rustframe_logo.png target/doc/docs/
|
||||
echo "<meta http-equiv=\"refresh\" content=\"0; url=docs\">" > target/doc/index.html
|
||||
touch target/doc/.nojekyll
|
||||
|
||||
# verify that logo exists in the output directory
|
||||
- name: Verify logo directory
|
||||
run: |
|
||||
if [ ! -f target/doc/docs/rustframe_logo.png ]; then
|
||||
echo "Logo not found in output directory!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Upload Pages artifact
|
||||
# if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
|
||||
@ -115,4 +132,4 @@ jobs:
|
||||
|
||||
- name: Deploy to GitHub Pages
|
||||
# if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
|
||||
uses: actions/deploy-pages@v4
|
||||
uses: actions/deploy-pages@v4
|
||||
|
@ -648,8 +648,13 @@ fn collect_monthly(
|
||||
let mut year = start_date.year();
|
||||
let mut month = start_date.month();
|
||||
|
||||
let next_month =
|
||||
|(yr, mo): (i32, u32)| -> (i32, u32) { if mo == 12 { (yr + 1, 1) } else { (yr, mo + 1) } };
|
||||
let next_month = |(yr, mo): (i32, u32)| -> (i32, u32) {
|
||||
if mo == 12 {
|
||||
(yr + 1, 1)
|
||||
} else {
|
||||
(yr, mo + 1)
|
||||
}
|
||||
};
|
||||
|
||||
loop {
|
||||
let candidate = if want_first_day {
|
||||
@ -873,6 +878,25 @@ fn last_day_of_year(year: i32) -> Result<NaiveDate, Box<dyn Error>> {
|
||||
|
||||
// --- Generator Helper Functions ---
|
||||
|
||||
fn get_first_date_helper(freq: DateFreq) -> fn(i32, u32) -> Result<NaiveDate, Box<dyn Error>> {
|
||||
if matches!(
|
||||
freq,
|
||||
DateFreq::Daily | DateFreq::WeeklyMonday | DateFreq::WeeklyFriday
|
||||
) {
|
||||
panic!("Daily, WeeklyMonday, and WeeklyFriday frequencies are not supported here");
|
||||
}
|
||||
|
||||
match freq {
|
||||
DateFreq::MonthStart => first_day_of_month,
|
||||
DateFreq::MonthEnd => last_day_of_month,
|
||||
DateFreq::QuarterStart => first_day_of_quarter,
|
||||
DateFreq::QuarterEnd => last_day_of_quarter,
|
||||
DateFreq::YearStart => |year, _| first_day_of_year(year),
|
||||
DateFreq::YearEnd => |year, _| last_day_of_year(year),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Finds the *first* valid date according to the frequency,
|
||||
/// starting the search *on or after* the given `start_date`.
|
||||
fn find_first_date_on_or_after(
|
||||
@ -883,69 +907,42 @@ fn find_first_date_on_or_after(
|
||||
DateFreq::Daily => Ok(start_date), // The first daily date is the start date itself
|
||||
DateFreq::WeeklyMonday => move_to_day_of_week_on_or_after(start_date, Weekday::Mon),
|
||||
DateFreq::WeeklyFriday => move_to_day_of_week_on_or_after(start_date, Weekday::Fri),
|
||||
DateFreq::MonthStart => {
|
||||
let mut candidate = first_day_of_month(start_date.year(), start_date.month())?;
|
||||
|
||||
DateFreq::MonthStart | DateFreq::MonthEnd => {
|
||||
// let mut candidate = first_day_of_month(start_date.year(), start_date.month())?;
|
||||
let get_cand_func = get_first_date_helper(freq);
|
||||
let mut candidate = get_cand_func(start_date.year(), start_date.month())?;
|
||||
if candidate < start_date {
|
||||
let (next_y, next_m) = if start_date.month() == 12 {
|
||||
(start_date.year().checked_add(1).ok_or("Year overflow")?, 1)
|
||||
} else {
|
||||
(start_date.year(), start_date.month() + 1)
|
||||
};
|
||||
candidate = first_day_of_month(next_y, next_m)?;
|
||||
candidate = get_cand_func(next_y, next_m)?;
|
||||
}
|
||||
Ok(candidate)
|
||||
}
|
||||
DateFreq::MonthEnd => {
|
||||
let mut candidate = last_day_of_month(start_date.year(), start_date.month())?;
|
||||
if candidate < start_date {
|
||||
let (next_y, next_m) = if start_date.month() == 12 {
|
||||
(start_date.year().checked_add(1).ok_or("Year overflow")?, 1)
|
||||
} else {
|
||||
(start_date.year(), start_date.month() + 1)
|
||||
};
|
||||
candidate = last_day_of_month(next_y, next_m)?;
|
||||
}
|
||||
Ok(candidate)
|
||||
}
|
||||
DateFreq::QuarterStart => {
|
||||
DateFreq::QuarterStart | DateFreq::QuarterEnd => {
|
||||
let current_q = month_to_quarter(start_date.month());
|
||||
let mut candidate = first_day_of_quarter(start_date.year(), current_q)?;
|
||||
let get_cand_func = get_first_date_helper(freq);
|
||||
let mut candidate = get_cand_func(start_date.year(), current_q)?;
|
||||
if candidate < start_date {
|
||||
let (next_y, next_q) = if current_q == 4 {
|
||||
(start_date.year().checked_add(1).ok_or("Year overflow")?, 1)
|
||||
} else {
|
||||
(start_date.year(), current_q + 1)
|
||||
};
|
||||
candidate = first_day_of_quarter(next_y, next_q)?;
|
||||
candidate = get_cand_func(next_y, next_q)?;
|
||||
}
|
||||
Ok(candidate)
|
||||
}
|
||||
DateFreq::QuarterEnd => {
|
||||
let current_q = month_to_quarter(start_date.month());
|
||||
let mut candidate = last_day_of_quarter(start_date.year(), current_q)?;
|
||||
if candidate < start_date {
|
||||
let (next_y, next_q) = if current_q == 4 {
|
||||
(start_date.year().checked_add(1).ok_or("Year overflow")?, 1)
|
||||
} else {
|
||||
(start_date.year(), current_q + 1)
|
||||
};
|
||||
candidate = last_day_of_quarter(next_y, next_q)?;
|
||||
}
|
||||
Ok(candidate)
|
||||
}
|
||||
DateFreq::YearStart => {
|
||||
let mut candidate = first_day_of_year(start_date.year())?;
|
||||
|
||||
DateFreq::YearStart | DateFreq::YearEnd => {
|
||||
let get_cand_func = get_first_date_helper(freq);
|
||||
let mut candidate = get_cand_func(start_date.year(), 0)?;
|
||||
if candidate < start_date {
|
||||
candidate =
|
||||
first_day_of_year(start_date.year().checked_add(1).ok_or("Year overflow")?)?;
|
||||
}
|
||||
Ok(candidate)
|
||||
}
|
||||
DateFreq::YearEnd => {
|
||||
let mut candidate = last_day_of_year(start_date.year())?;
|
||||
if candidate < start_date {
|
||||
candidate =
|
||||
last_day_of_year(start_date.year().checked_add(1).ok_or("Year overflow")?)?;
|
||||
get_cand_func(start_date.year().checked_add(1).ok_or("Year overflow")?, 0)?;
|
||||
}
|
||||
Ok(candidate)
|
||||
}
|
||||
@ -962,7 +959,8 @@ fn find_next_date(current_date: NaiveDate, freq: DateFreq) -> Result<NaiveDate,
|
||||
DateFreq::WeeklyMonday | DateFreq::WeeklyFriday => current_date
|
||||
.checked_add_signed(Duration::days(7))
|
||||
.ok_or_else(|| "Date overflow adding 7 days".into()),
|
||||
DateFreq::MonthStart => {
|
||||
DateFreq::MonthStart | DateFreq::MonthEnd => {
|
||||
let get_cand_func = get_first_date_helper(freq);
|
||||
let (next_y, next_m) = if current_date.month() == 12 {
|
||||
(
|
||||
current_date.year().checked_add(1).ok_or("Year overflow")?,
|
||||
@ -971,21 +969,11 @@ fn find_next_date(current_date: NaiveDate, freq: DateFreq) -> Result<NaiveDate,
|
||||
} else {
|
||||
(current_date.year(), current_date.month() + 1)
|
||||
};
|
||||
first_day_of_month(next_y, next_m)
|
||||
get_cand_func(next_y, next_m)
|
||||
}
|
||||
DateFreq::MonthEnd => {
|
||||
let (next_y, next_m) = if current_date.month() == 12 {
|
||||
(
|
||||
current_date.year().checked_add(1).ok_or("Year overflow")?,
|
||||
1,
|
||||
)
|
||||
} else {
|
||||
(current_date.year(), current_date.month() + 1)
|
||||
};
|
||||
last_day_of_month(next_y, next_m)
|
||||
}
|
||||
DateFreq::QuarterStart => {
|
||||
DateFreq::QuarterStart | DateFreq::QuarterEnd => {
|
||||
let current_q = month_to_quarter(current_date.month());
|
||||
let get_cand_func = get_first_date_helper(freq);
|
||||
let (next_y, next_q) = if current_q == 4 {
|
||||
(
|
||||
current_date.year().checked_add(1).ok_or("Year overflow")?,
|
||||
@ -994,25 +982,14 @@ fn find_next_date(current_date: NaiveDate, freq: DateFreq) -> Result<NaiveDate,
|
||||
} else {
|
||||
(current_date.year(), current_q + 1)
|
||||
};
|
||||
first_day_of_quarter(next_y, next_q)
|
||||
get_cand_func(next_y, next_q)
|
||||
}
|
||||
DateFreq::QuarterEnd => {
|
||||
let current_q = month_to_quarter(current_date.month());
|
||||
let (next_y, next_q) = if current_q == 4 {
|
||||
(
|
||||
current_date.year().checked_add(1).ok_or("Year overflow")?,
|
||||
1,
|
||||
)
|
||||
} else {
|
||||
(current_date.year(), current_q + 1)
|
||||
};
|
||||
last_day_of_quarter(next_y, next_q)
|
||||
}
|
||||
DateFreq::YearStart => {
|
||||
first_day_of_year(current_date.year().checked_add(1).ok_or("Year overflow")?)
|
||||
}
|
||||
DateFreq::YearEnd => {
|
||||
last_day_of_year(current_date.year().checked_add(1).ok_or("Year overflow")?)
|
||||
DateFreq::YearStart | DateFreq::YearEnd => {
|
||||
let get_cand_func = get_first_date_helper(freq);
|
||||
get_cand_func(
|
||||
current_date.year().checked_add(1).ok_or("Year overflow")?,
|
||||
0,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
6
src/utils/dateutils/mod.rs
Normal file
6
src/utils/dateutils/mod.rs
Normal file
@ -0,0 +1,6 @@
|
||||
pub mod bdates;
|
||||
pub use bdates::{BDateFreq, BDatesList, BDatesGenerator};
|
||||
|
||||
pub mod dates;
|
||||
pub use dates::{DateFreq, DatesList, DatesGenerator};
|
||||
|
@ -1,6 +1,3 @@
|
||||
pub mod bdates;
|
||||
pub use bdates::{BDateFreq, BDatesList, BDatesGenerator};
|
||||
|
||||
pub mod dates;
|
||||
pub use dates::{DateFreq, DatesList, DatesGenerator};
|
||||
|
||||
pub mod dateutils;
|
||||
pub use dateutils::{BDateFreq, BDatesGenerator, BDatesList};
|
||||
pub use dateutils::{DateFreq, DatesGenerator, DatesList};
|
||||
|
Loading…
x
Reference in New Issue
Block a user