summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@plataformatec.com.br>2018-12-04 18:06:51 +0100
committerJosé Valim <jose.valim@plataformatec.com.br>2018-12-04 18:06:51 +0100
commitc96264c2af202200e9aa374ca3002e0d5a0b9768 (patch)
treeb11ece9422d4eefcf93b87b04d47e289d1f8583b
parentc82f8b60e1f2f7105eea499593f80fcc33a907b5 (diff)
downloadelixir-jv-week-of-year.tar.gz
Simplify next week year detectionjv-week-of-year
-rw-r--r--lib/elixir/lib/calendar/iso.ex10
1 files changed, 4 insertions, 6 deletions
diff --git a/lib/elixir/lib/calendar/iso.ex b/lib/elixir/lib/calendar/iso.ex
index 1242cf203..c48535482 100644
--- a/lib/elixir/lib/calendar/iso.ex
+++ b/lib/elixir/lib/calendar/iso.ex
@@ -426,19 +426,17 @@ defmodule Calendar.ISO do
@impl true
def week_of_year(year, month, day) do
true = day <= days_in_month(year, month)
-
{first_day_of_year, first_week_day_of_year} = first_day_and_week_day_of_year_in_iso_days(year)
- leap_day_offset = leap_day_offset(year, month)
- day_of_year = days_before_month(month) + leap_day_offset + day
- iso_days = first_day_of_year + day_of_year - 1
+ iso_days =
+ first_day_of_year + days_before_month(month) + leap_day_offset(year, month) + day - 1
+
day_of_week = iso_days_to_day_of_week(iso_days)
- maybe_next_year_week_limit = @days_per_nonleap_year + leap_day_offset - 3
cond do
# If we are in a monday, tuesday or wednesday where the thursday
# is in the next year, so we are already in the next year week.
- month == 12 and day_of_year > maybe_next_year_week_limit and day_of_week < 4 ->
+ month == 12 and day >= 29 and day_of_week < 4 ->
{year + 1, 1, day_of_week}
# If we are in a friday, saturday, sunday as one of the first