From 222a2139e50457701ae3fcfb5e189d548c08ae6e Mon Sep 17 00:00:00 2001 From: Philip Becker Date: Thu, 12 Sep 2024 17:01:50 -0400 Subject: [PATCH 1/8] add Juneteenth for UT --- us.yaml | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/us.yaml b/us.yaml index 3eea10d..c3e963b 100644 --- a/us.yaml +++ b/us.yaml @@ -199,6 +199,11 @@ months: observed: to_weekday_if_weekend(date) year_ranges: from: 2021 + - name: Juneteenth National Freedom Day + regions: [us_ut] + function: juneteenth_national_freedom_day(year) + year_ranges: + from: 2022 - name: Emancipation Day in Texas # fixed regions: [us_tx] mday: 19 @@ -360,6 +365,22 @@ methods: beginning_of_month = Date.civil(year, month, 1) king_day = Date.civil(year, month, day_of_holiday) king_day.downto(beginning_of_month).find {|date| date if date.wday == 5 } + juneteenth_national_freedom_day: + # If Saturday or Sunday, it's on next Monday + # If it's Tuesday through Friday, it's on the preceeding Monday + arguments: year + ruby: | + date = Date.civil(year, 6, 19) + case date.wday + when 1 + date + when 2,3,4,5 + date - (date.wday - 1) + when 6 + date + 2 + when 0 + date + 1 + end election_day: # Tuesday after the first Monday of November arguments: year @@ -706,7 +727,13 @@ tests: date: ['2017-6-19'] regions: ["us_tx"] expect: - name: "Emancipation Day in Texas" + name: "Emancipation Day in Texas" + - given: + date: ['2024-06-17', '2027-06-21', '2028-06-19', '2033-06-20'] + regions: ["us_ut"] + expect: + name: "Juneteenth National Freedom Day" + - given: date: ['2017-6-20', '2020-6-19', '2021-6-21'] From d17103f37a5f6ec633c15b48fde65974b5992cae Mon Sep 17 00:00:00 2001 From: Philip Becker Date: Thu, 12 Sep 2024 17:14:55 -0400 Subject: [PATCH 2/8] two holidays will come back on 6-19 --- us.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/us.yaml b/us.yaml index c3e963b..afd0e46 100644 --- a/us.yaml +++ b/us.yaml @@ -729,10 +729,15 @@ tests: expect: name: "Emancipation Day in Texas" - given: - date: ['2024-06-17', '2027-06-21', '2028-06-19', '2033-06-20'] + date: ['2024-06-17', '2027-06-21', '2033-06-20'] regions: ["us_ut"] expect: name: "Juneteenth National Freedom Day" + - given: + date: ['2028-06-19'] + regions: ["us_ut"] + expect: + name: ["Juneteenth National Freedom Day", "Juneteenth National Independence Day"] - given: From 1d1d0eab530c9b5296daa44964f6498100f4ab92 Mon Sep 17 00:00:00 2001 From: Philip Becker Date: Thu, 12 Sep 2024 17:18:50 -0400 Subject: [PATCH 3/8] don't try to have two holidays on the same day --- us.yaml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/us.yaml b/us.yaml index afd0e46..209fd62 100644 --- a/us.yaml +++ b/us.yaml @@ -729,16 +729,10 @@ tests: expect: name: "Emancipation Day in Texas" - given: - date: ['2024-06-17', '2027-06-21', '2033-06-20'] + date: ['2024-06-17', '2027-06-21', '2028-06-19', '2033-06-20'] regions: ["us_ut"] expect: name: "Juneteenth National Freedom Day" - - given: - date: ['2028-06-19'] - regions: ["us_ut"] - expect: - name: ["Juneteenth National Freedom Day", "Juneteenth National Independence Day"] - - given: date: ['2017-6-20', '2020-6-19', '2021-6-21'] From 83c190a0c5b591bb4183fbfefbdcdac0932201ad Mon Sep 17 00:00:00 2001 From: Philip Becker Date: Thu, 12 Sep 2024 17:31:04 -0400 Subject: [PATCH 4/8] calculate observed juneteenth in UT --- us.yaml | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/us.yaml b/us.yaml index 209fd62..f4fa7c8 100644 --- a/us.yaml +++ b/us.yaml @@ -196,14 +196,9 @@ months: - name: Juneteenth National Independence Day regions: [us] mday: 19 - observed: to_weekday_if_weekend(date) + observed: juneteenth_national_independence_day(date, region) year_ranges: from: 2021 - - name: Juneteenth National Freedom Day - regions: [us_ut] - function: juneteenth_national_freedom_day(year) - year_ranges: - from: 2022 - name: Emancipation Day in Texas # fixed regions: [us_tx] mday: 19 @@ -365,22 +360,32 @@ methods: beginning_of_month = Date.civil(year, month, 1) king_day = Date.civil(year, month, day_of_holiday) king_day.downto(beginning_of_month).find {|date| date if date.wday == 5 } - juneteenth_national_freedom_day: - # If Saturday or Sunday, it's on next Monday - # If it's Tuesday through Friday, it's on the preceeding Monday - arguments: year + juneteenth_national_independence_day: + # In Utah... + # When Saturday or Sunday, it's on next Monday + # When Tuesday through Friday, it's on the preceeding Monday + # all other states it's observed like "to_weekday_if_weekend" + arguments: date, region ruby: | - date = Date.civil(year, 6, 19) - case date.wday - when 1 - date - when 2,3,4,5 - date - (date.wday - 1) - when 6 - date + 2 - when 0 + if region == 'us_ut' + case date.wday + when 1 + date + when 2,3,4,5 + date - (date.wday - 1) + when 6 + date + 2 + when 0 + date + 1 + end + elsif date.wday == 0 date + 1 + elsif date.wday == 6 + date - 1 + else + date end + election_day: # Tuesday after the first Monday of November arguments: year @@ -731,8 +736,9 @@ tests: - given: date: ['2024-06-17', '2027-06-21', '2028-06-19', '2033-06-20'] regions: ["us_ut"] + options: ["observed"] expect: - name: "Juneteenth National Freedom Day" + name: "Juneteenth National Independence Day" - given: date: ['2017-6-20', '2020-6-19', '2021-6-21'] From f220c4cfc83ea820531597c16a3c772c8e408242 Mon Sep 17 00:00:00 2001 From: Philip Becker Date: Thu, 12 Sep 2024 17:43:11 -0400 Subject: [PATCH 5/8] reformat method and fix validator --- lib/validation/custom_method_validator.rb | 2 +- us.yaml | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/validation/custom_method_validator.rb b/lib/validation/custom_method_validator.rb index ad643ef..6993265 100644 --- a/lib/validation/custom_method_validator.rb +++ b/lib/validation/custom_method_validator.rb @@ -3,7 +3,7 @@ module Definitions module Validation class CustomMethod - VALID_ARGUMENTS = ["date", "year", "month", "day"] + VALID_ARGUMENTS = ["date", "year", "month", "day", "region"] def call(methods) methods.each do |name, method| diff --git a/us.yaml b/us.yaml index f4fa7c8..1de3697 100644 --- a/us.yaml +++ b/us.yaml @@ -367,7 +367,7 @@ methods: # all other states it's observed like "to_weekday_if_weekend" arguments: date, region ruby: | - if region == 'us_ut' + if region == "us_ut" case date.wday when 1 date @@ -385,7 +385,6 @@ methods: else date end - election_day: # Tuesday after the first Monday of November arguments: year From b9c23e5e1c386b228a2c757cffe3e3af091ce3c0 Mon Sep 17 00:00:00 2001 From: Philip Becker Date: Thu, 12 Sep 2024 18:02:54 -0400 Subject: [PATCH 6/8] intentionally include exception for debugging --- us.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/us.yaml b/us.yaml index 1de3697..44b8a3d 100644 --- a/us.yaml +++ b/us.yaml @@ -368,6 +368,7 @@ methods: arguments: date, region ruby: | if region == "us_ut" + raise "it's utah, baby!" case date.wday when 1 date From f90664b361d3669aa030eb5e49647b7765534429 Mon Sep 17 00:00:00 2001 From: Philip Becker Date: Thu, 12 Sep 2024 18:05:53 -0400 Subject: [PATCH 7/8] adding an exception didn't get the desired affect --- us.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/us.yaml b/us.yaml index 44b8a3d..1de3697 100644 --- a/us.yaml +++ b/us.yaml @@ -368,7 +368,6 @@ methods: arguments: date, region ruby: | if region == "us_ut" - raise "it's utah, baby!" case date.wday when 1 date From 0c6edc20d622864f81d521f44195d2ef6ed2439e Mon Sep 17 00:00:00 2001 From: Philip Becker Date: Thu, 12 Sep 2024 18:20:22 -0400 Subject: [PATCH 8/8] reverse args because region was showing up nil --- us.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/us.yaml b/us.yaml index 1de3697..9587e13 100644 --- a/us.yaml +++ b/us.yaml @@ -196,7 +196,7 @@ months: - name: Juneteenth National Independence Day regions: [us] mday: 19 - observed: juneteenth_national_independence_day(date, region) + observed: juneteenth_national_independence_day(region, date) year_ranges: from: 2021 - name: Emancipation Day in Texas # fixed @@ -365,9 +365,9 @@ methods: # When Saturday or Sunday, it's on next Monday # When Tuesday through Friday, it's on the preceeding Monday # all other states it's observed like "to_weekday_if_weekend" - arguments: date, region + arguments: region, date ruby: | - if region == "us_ut" + if region == :us_ut case date.wday when 1 date