Add 'all_time' period option to Period model (#279)

* Add 'all_time' period option to Period model

Introduces an 'all_time' period to the Period model, which spans from the family's oldest entry date to the current date. Includes tests to verify correct creation and date range calculation for the new period.

* Update test/models/period_test.rb

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Mark Hendriksen <hendriksen-mark@hotmail.com>

* Improve 'all_time' period fallback logic

Updates the 'all_time' period to use a 5-year fallback range when no family or entries exist, or when the oldest entry date is today. Adds tests to verify correct behavior for these edge cases.

* Update period.rb

---------

Signed-off-by: Mark Hendriksen <hendriksen-mark@hotmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
This commit is contained in:
Mark Hendriksen
2025-11-10 23:07:07 +01:00
committed by GitHub
parent c6771ebaab
commit 7f5cf4c082
2 changed files with 54 additions and 0 deletions

View File

@@ -69,6 +69,22 @@ class Period
label_short: "10Y",
label: "Last 10 Years",
comparison_label: "vs. 10 years ago"
},
"all_time" => {
date_range: -> {
oldest_date = Current.family&.oldest_entry_date
# If no family or no entries exist, use a reasonable historical fallback
# to ensure "All Time" represents a meaningful range, not just today
start_date = if oldest_date && oldest_date < Date.current
oldest_date
else
5.years.ago.to_date
end
[ start_date, Date.current ]
},
label_short: "All",
label: "All Time",
comparison_label: "vs. beginning"
}
}