Add Month memory filter span
This commit is contained in:
@@ -17,6 +17,7 @@ use crate::state::AppState;
|
||||
pub enum MemoriesSpan {
|
||||
Day,
|
||||
Week,
|
||||
Month,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@@ -147,6 +148,7 @@ fn is_memories_match(
|
||||
match span {
|
||||
MemoriesSpan::Day => same_month_day_any_year(file_date, today),
|
||||
MemoriesSpan::Week => same_week_any_year(file_date, today),
|
||||
MemoriesSpan::Month => same_month_any_year(file_date, today),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,6 +164,11 @@ fn same_week_any_year(a: NaiveDate, b: NaiveDate) -> bool {
|
||||
a.iso_week().week().eq(&b.iso_week().week())
|
||||
}
|
||||
|
||||
// Match same month (ignoring day and year)
|
||||
fn same_month_any_year(a: NaiveDate, b: NaiveDate) -> bool {
|
||||
a.month() == b.month()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -189,6 +196,31 @@ mod tests {
|
||||
assert!(same_week_any_year(a, b));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_same_month_any_year() {
|
||||
let today = NaiveDate::from_ymd_opt(2025, 8, 8).unwrap();
|
||||
// Same month, different year and day - should match
|
||||
assert!(same_month_any_year(
|
||||
NaiveDate::from_ymd_opt(2019, 8, 1).unwrap(),
|
||||
today
|
||||
));
|
||||
// Different month - should not match
|
||||
assert!(!same_month_any_year(
|
||||
NaiveDate::from_ymd_opt(2019, 9, 8).unwrap(),
|
||||
today
|
||||
));
|
||||
// Same month, same year, different day - should match
|
||||
assert!(same_month_any_year(
|
||||
NaiveDate::from_ymd_opt(2025, 8, 15).unwrap(),
|
||||
today
|
||||
));
|
||||
// Test January vs December
|
||||
assert!(!same_month_any_year(
|
||||
NaiveDate::from_ymd_opt(2020, 1, 1).unwrap(),
|
||||
NaiveDate::from_ymd_opt(2025, 12, 31).unwrap()
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_years_back_limit() {
|
||||
let today = NaiveDate::from_ymd_opt(2025, 8, 8).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user