feature/memories #35
@@ -17,6 +17,7 @@ use crate::state::AppState;
|
|||||||
pub enum MemoriesSpan {
|
pub enum MemoriesSpan {
|
||||||
Day,
|
Day,
|
||||||
Week,
|
Week,
|
||||||
|
Month,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
@@ -147,6 +148,7 @@ fn is_memories_match(
|
|||||||
match span {
|
match span {
|
||||||
MemoriesSpan::Day => same_month_day_any_year(file_date, today),
|
MemoriesSpan::Day => same_month_day_any_year(file_date, today),
|
||||||
MemoriesSpan::Week => same_week_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())
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
@@ -189,6 +196,31 @@ mod tests {
|
|||||||
assert!(same_week_any_year(a, b));
|
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]
|
#[test]
|
||||||
fn test_years_back_limit() {
|
fn test_years_back_limit() {
|
||||||
let today = NaiveDate::from_ymd_opt(2025, 8, 8).unwrap();
|
let today = NaiveDate::from_ymd_opt(2025, 8, 8).unwrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user