From e668881c18b84d63a793c6f1775460d1de1f696f Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Sun, 26 Dec 2021 16:48:33 -0500 Subject: [PATCH] Fix leap year search bug --- lib/philomena/search/date_parser.ex | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/philomena/search/date_parser.ex b/lib/philomena/search/date_parser.ex index 4b3bf72a..5c8a8cb1 100644 --- a/lib/philomena/search/date_parser.ex +++ b/lib/philomena/search/date_parser.ex @@ -30,6 +30,13 @@ defmodule Philomena.Search.DateParser do defp timezone_bounds([tz_off, tz_hour]), do: [tz_off, tz_hour, 0] defp timezone_bounds([tz_off, tz_hour, tz_minute]), do: [tz_off, tz_hour, tz_minute] + defp days_in_year(year) do + case Calendar.ISO.leap_year?(year) do + true -> 366 + _ -> 365 + end + end + defp days_in_month(year, month) when month in 1..12 do Calendar.ISO.days_in_month(year, month) end @@ -50,7 +57,8 @@ defmodule Philomena.Search.DateParser do end defp date_bounds([year]) do - lower_upper({{year, 1, 1}, {0, 0, 0}}, 31_536_000) + days = days_in_year(year) + lower_upper({{year, 1, 1}, {0, 0, 0}}, 86_400 * days) end defp date_bounds([year, month]) do