Compare commits

...

26 Commits

Author SHA1 Message Date
Palash Tyagi
c35926fc27
Merge 4a5485cddd8d61db61652e291d04b4a076382c98 into 2bc375f95009e600ba8d584a88a2b59da7c0e8ef 2025-05-05 03:50:55 +01:00
2bc375f950
Merge pull request #42 from Magnus167/fix_docs
Update docs-and-testcov workflow
2025-05-05 03:44:02 +01:00
Palash Tyagi
37d10cbc7d Remove 'fix_docs' branch from push trigger in workflow configuration 2025-05-05 03:42:52 +01:00
Palash Tyagi
1c41d387ef Update verification step to check for logo presence in output directory 2025-05-05 03:32:57 +01:00
Palash Tyagi
38baf0c648 Fix logo URL replacement in README.md and adjust documentation copying step 2025-05-05 03:30:58 +01:00
Palash Tyagi
2e6c4bd6bb Add step to replace logo URL in README.md during workflow 2025-05-05 03:26:25 +01:00
Palash Tyagi
6bb1c2a0de testing w .nojekyll 2025-05-05 03:18:22 +01:00
Palash Tyagi
d670ab4a5c Fix .github directory path in documentation output and add verification step 2025-05-05 03:07:47 +01:00
Palash Tyagi
eb09593b0a Update push trigger branches for docs-and-testcov workflow 2025-05-05 03:01:36 +01:00
Palash Tyagi
29c304d512 testing changes 2025-05-05 03:00:51 +01:00
Palash Tyagi
7c96439550 Fix .github directory path in documentation output and add verification step 2025-05-05 02:53:16 +01:00
Palash Tyagi
76b8824ce3 Refactor documentation file copying to include entire .github directory 2025-05-05 02:49:07 +01:00
Palash Tyagi
00befe7ee4 Fix file path for rustframe logo in documentation output 2025-05-05 02:44:17 +01:00
Palash Tyagi
41349e2dba Update push trigger branch for docs-and-testcov workflow 2025-05-05 02:40:27 +01:00
Palash Tyagi
9ab3a7c2c1 Update branch trigger and fix documentation file handling in workflow 2025-05-05 02:39:19 +01:00
Palash Tyagi
88a08e1063 Update push trigger branches in docs-and-testcov workflow 2025-05-05 02:24:48 +01:00
4a5485cddd
Merge branch 'main' into date_utils 2025-05-05 02:13:21 +01:00
97e8f3d55c
Merge branch 'main' into date_utils 2025-05-05 02:01:53 +01:00
88b608ea1b
Merge branch 'main' into date_utils 2025-05-04 02:29:18 +01:00
80779ac6e5
Merge branch 'main' into date_utils 2025-05-04 02:11:14 +01:00
d42da5ad7b
Merge branch 'main' into date_utils 2025-05-04 01:08:08 +01:00
e2db5eb315
Merge branch 'main' into date_utils 2025-05-03 01:32:47 +01:00
bdef7f1732
Merge branch 'main' into date_utils 2025-05-02 23:38:53 +01:00
2b4ef8a371
Merge branch 'main' into date_utils 2025-05-01 01:03:32 +01:00
Palash Tyagi
1213d588ec Refactor date frequency handling in DatesList to improve clarity and reduce code duplication 2025-04-29 23:43:12 +01:00
Palash Tyagi
a76963ec2e move bdates and dates modules into dateutils module 2025-04-29 00:03:06 +01:00
5 changed files with 83 additions and 86 deletions

View File

@ -44,6 +44,14 @@ jobs:
toolchain: stable toolchain: stable
override: true 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 - name: Build documentation
run: cargo doc --no-deps --release run: cargo doc --no-deps --release
@ -96,16 +104,25 @@ jobs:
run: | run: |
# mkdir docs # mkdir docs
mkdir -p target/doc/docs mkdir -p target/doc/docs
cp -r target/doc/rustframe/* target/doc/docs/ mv target/doc/rustframe/* target/doc/docs/
mkdir output mkdir output
cp tarpaulin-report.html target/doc/docs/ cp tarpaulin-report.html target/doc/docs/
cp tarpaulin-report.json target/doc/docs/ cp tarpaulin-report.json target/doc/docs/
cp tarpaulin-badge.json target/doc/docs/ cp tarpaulin-badge.json target/doc/docs/
cp last-commit-date.json target/doc/docs/ cp last-commit-date.json target/doc/docs/
mkdir -p target/doc/.github # cp -r .github target/doc/docs
cp .github/rustframe_logo.png target/doc/.github/rustframe_logo.png cp .github/rustframe_logo.png target/doc/docs/
echo "<meta http-equiv=\"refresh\" content=\"0; url=docs\">" > target/doc/index.html 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 - name: Upload Pages artifact
# if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' # if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'

View File

@ -648,8 +648,13 @@ fn collect_monthly(
let mut year = start_date.year(); let mut year = start_date.year();
let mut month = start_date.month(); let mut month = start_date.month();
let next_month = let next_month = |(yr, mo): (i32, u32)| -> (i32, u32) {
|(yr, mo): (i32, u32)| -> (i32, u32) { if mo == 12 { (yr + 1, 1) } else { (yr, mo + 1) } }; if mo == 12 {
(yr + 1, 1)
} else {
(yr, mo + 1)
}
};
loop { loop {
let candidate = if want_first_day { 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 --- // --- 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, /// 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`.
fn find_first_date_on_or_after( 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::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::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::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 { if candidate < start_date {
let (next_y, next_m) = if start_date.month() == 12 { let (next_y, next_m) = if start_date.month() == 12 {
(start_date.year().checked_add(1).ok_or("Year overflow")?, 1) (start_date.year().checked_add(1).ok_or("Year overflow")?, 1)
} else { } else {
(start_date.year(), start_date.month() + 1) (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) Ok(candidate)
} }
DateFreq::MonthEnd => { DateFreq::QuarterStart | DateFreq::QuarterEnd => {
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 => {
let current_q = month_to_quarter(start_date.month()); 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 { if candidate < start_date {
let (next_y, next_q) = if current_q == 4 { let (next_y, next_q) = if current_q == 4 {
(start_date.year().checked_add(1).ok_or("Year overflow")?, 1) (start_date.year().checked_add(1).ok_or("Year overflow")?, 1)
} else { } else {
(start_date.year(), current_q + 1) (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) Ok(candidate)
} }
DateFreq::QuarterEnd => {
let current_q = month_to_quarter(start_date.month()); DateFreq::YearStart | DateFreq::YearEnd => {
let mut candidate = last_day_of_quarter(start_date.year(), current_q)?; let get_cand_func = get_first_date_helper(freq);
if candidate < start_date { let mut candidate = get_cand_func(start_date.year(), 0)?;
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())?;
if candidate < start_date { if candidate < start_date {
candidate = candidate =
first_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)
}
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")?)?;
} }
Ok(candidate) Ok(candidate)
} }
@ -962,7 +959,8 @@ fn find_next_date(current_date: NaiveDate, freq: DateFreq) -> Result<NaiveDate,
DateFreq::WeeklyMonday | DateFreq::WeeklyFriday => current_date DateFreq::WeeklyMonday | DateFreq::WeeklyFriday => current_date
.checked_add_signed(Duration::days(7)) .checked_add_signed(Duration::days(7))
.ok_or_else(|| "Date overflow adding 7 days".into()), .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 { let (next_y, next_m) = if current_date.month() == 12 {
( (
current_date.year().checked_add(1).ok_or("Year overflow")?, 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 { } else {
(current_date.year(), current_date.month() + 1) (current_date.year(), current_date.month() + 1)
}; };
first_day_of_month(next_y, next_m) get_cand_func(next_y, next_m)
} }
DateFreq::MonthEnd => { DateFreq::QuarterStart | DateFreq::QuarterEnd => {
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 => {
let current_q = month_to_quarter(current_date.month()); 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 { let (next_y, next_q) = if current_q == 4 {
( (
current_date.year().checked_add(1).ok_or("Year overflow")?, 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 { } else {
(current_date.year(), current_q + 1) (current_date.year(), current_q + 1)
}; };
first_day_of_quarter(next_y, next_q) get_cand_func(next_y, next_q)
} }
DateFreq::QuarterEnd => { DateFreq::YearStart | DateFreq::YearEnd => {
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 { get_cand_func(
(
current_date.year().checked_add(1).ok_or("Year overflow")?, current_date.year().checked_add(1).ok_or("Year overflow")?,
1, 0,
) )
} 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")?)
} }
} }
} }

View File

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

View File

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