Skip to content

Commit 7df5683

Browse files
author
Phil Peble
committed
Issue-24: Specify ruby source for custom methods
1 parent 488652a commit 7df5683

22 files changed

+160
-133
lines changed

METHODS.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
methods:
3+
easter:
4+
arguments: year
5+
orthodox_easter:
6+
arguments: year
7+
orthodox_easter_julian:
8+
arguments: year
9+
to_monday_if_sunday:
10+
arguments: date
11+
to_monday_if_weekend:
12+
arguments: date
13+
to_weekday_if_boxing_weekend:
14+
arguments: date
15+
to_weekday_if_boxing_weekend_from_year:
16+
arguments: year
17+
to_weekday_if_weekend:
18+
arguments: date
19+
calculate_day_of_month:
20+
arguments: year, month, day, wday
21+
to_weekday_if_boxing_weekend_from_year_or_to_tuesday_if_monday:
22+
arguments: year
23+
to_tuesday_if_sunday_or_monday_if_saturday:
24+
arguments: date
25+
lunar_to_solar:
26+
arguments: year, month, day, region

SYNTAX.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ For example, Canada celebrates Victoria Day, which falls on the Monday on or bef
236236
methods:
237237
ca_victoria_day:
238238
arguments: year
239-
source: |
239+
ruby: |
240240
date = Date.civil(year, 5, 24)
241241
if date.wday > 1
242242
date -= (date.wday - 1)

au.yaml

Lines changed: 36 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -178,101 +178,84 @@ months:
178178
methods:
179179
afl_grand_final:
180180
arguments: year
181-
logic:
182-
if:
183-
condition: year == 2015
184-
result: '2015-10-2'
185-
condition: year == 2016
186-
result: '2016-9-30'
187-
condition: year == 2017
188-
result: '2017-9-29'
189-
181+
ruby: |
182+
case year
183+
when 2015
184+
Date.civil(2015, 10, 2)
185+
when 2016
186+
Date.civil(2016, 9, 30)
187+
when 2017
188+
Date.civil(2017, 9, 29)
189+
end
190190
qld_queens_bday_october:
191191
# http://www.justice.qld.gov.au/fair-and-safe-work/industrial-relations/public-holidays/dates
192192
# celebrated twice in 2012
193193
# in october again from 2016
194194
arguments: year
195-
logic:
196-
if:
197-
condition: year >= 2016
198-
function: day_of_month(year, 10, 1, 1) # This is a problem, it just returns a single integer, should we return a date?
199-
condition: year == 2012
200-
result: 1 #TODO Same here?
201-
else:
202-
result: null
203-
195+
ruby: |
196+
if year >= 2016
197+
%{CALCULATE_DAY_OF_MONTH}(year, 10, 1, 1)
198+
elsif year == 2012
199+
1
200+
else
201+
nil
202+
end
204203
qld_queens_birthday_june:
205204
# http://www.justice.qld.gov.au/fair-and-safe-work/industrial-relations/public-holidays/dates
206205
# in june until 2015
207206
arguments: year
208-
logic:
209-
if:
210-
condition: year <= 2015
211-
result: day_of_month(year, 6, 1, 1)
212-
207+
ruby: |
208+
if year <= 2015
209+
%{CALCULATE_DAY_OF_MONTH}(year, 6, 2, 1)
210+
end
213211
qld_labour_day_may:
214212
# http://www.justice.qld.gov.au/fair-and-safe-work/industrial-relations/public-holidays/dates
215213
# for 2013 to 2016 it was in October, otherwise it's in May
216214
arguments: year
217-
logic:
218-
if:
219-
condition: year < 2013 || year >= 2016
220-
function: day_of_month(year, 5, 1, 1)
221-
215+
ruby: |
216+
if year < 2013 || year >= 2016
217+
%{CALCULATE_DAY_OF_MONTH}(year, 5, 1, 1)
218+
end
222219
qld_labour_day_october:
223220
# http://www.justice.qld.gov.au/fair-and-safe-work/industrial-relations/public-holidays/dates
224221
# for 2013 to 2016 it was in October, otherwise it's in May
225222
arguments: year
226-
logic:
227-
if:
228-
condition: year >= 2013 && year < 2016
229-
function: day_of_month(year, 10, 1, 1)
230-
223+
ruby: |
224+
if year >= 2013 && year < 2016
225+
%{CALCULATE_DAY_OF_MONTH}(year, 10, 1, 1)
226+
end
231227
g20_day_2014_only:
232228
# http://www.justice.qld.gov.au/fair-and-safe-work/industrial-relations/public-holidays/dates
233229
# G20 day in brisbane, in 2014, on november 14
234230
arguments: year
235-
logic:
236-
if:
237-
condition: year == 2014
238-
result: 14
239-
else:
240-
result: null
241-
231+
ruby: |
232+
year == 2014 ? 14 : nil
242233
hobart_show_day:
243234
# http://worksafe.tas.gov.au/__data/assets/pdf_file/0008/287036/Public_Holidays_2014.pdf
244235
# The Thursday before the fourth Saturday in October.
245236
arguments: year
246-
logic:
247-
function: day_of_month(year, 10, 4, :saturday)
248-
function_modifier: -2 # the thursday before
249-
237+
ruby: |
250238
fourth_sat_in_oct = Date.civil(year, 10, Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 10, 4, :saturday))
251239
fourth_sat_in_oct - 2 # the thursday before
252-
253-
source: |
254-
fourth_sat_in_oct = Date.civil(year, 10, Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 10, 4, :saturday))
255-
fourth_sat_in_oct - 2 # the thursday before
256-
257240
march_pub_hol_sa:
258241
# http://www.safework.sa.gov.au/show_page.jsp?id=2483#.VQ9Mfmb8-8E
259242
# The Holidays Act 1910 provides for the third Monday in May to be a public holiday. Since 2006 this public holiday has been observed on the second Monday in March through the issuing of a special Proclamation by the Governor.
260243
arguments: year
261-
source: |
244+
ruby: |
262245
if year < 2006
263246
nil
264247
else
265-
Date.civil(year, 3, Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 3, :second, :monday))
248+
Date.civil(year, 3, %{CALCULATE_DAY_OF_MONTH}(year, 3, :second, :monday))
266249
end
267250
may_pub_hol_sa:
268251
# http://www.safework.sa.gov.au/show_page.jsp?id=2483#.VQ9Mfmb8-8E
269252
# The Holidays Act 1910 provides for the third Monday in May to be a public holiday. Since 2006 this public holiday has been observed on the second Monday in March through the issuing of a special Proclamation by the Governor.
270253
arguments: year
271-
source: |
254+
ruby: |
272255
if year >= 2006
273256
nil
274257
else
275-
Date.civil(year, 5, Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 5, :third, :monday))
258+
Date.civil(year, 5, %{CALCULATE_DAY_OF_MONTH}(year, 5, :third, :monday))
276259
end
277260
278261
tests:

ca.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ months:
188188
methods:
189189
ca_victoria_day:
190190
# Monday on or before May 24
191-
arguments: year
192-
source: |
191+
arguments: year, month, day
192+
ruby: |
193193
date = Date.civil(year,5,24)
194194
if date.wday > 1
195195
date -= (date.wday - 1)

ch.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ methods:
130130
ch_vd_lundi_du_jeune_federal:
131131
# Monday after the third Sunday of September
132132
arguments: year
133-
source: |
133+
ruby: |
134134
date = Date.civil(year,9,1)
135135
# Find the first Sunday of September
136136
until date.wday.eql? 0 do
@@ -142,7 +142,7 @@ methods:
142142
ch_ge_jeune_genevois:
143143
# Thursday after the first Sunday of September
144144
arguments: year
145-
source: |
145+
ruby: |
146146
date = Date.civil(year,9,1)
147147
# Find the first Sunday of September
148148
until date.wday.eql? 0 do
@@ -153,14 +153,14 @@ methods:
153153
ch_gl_naefelser_fahrt:
154154
# First Thursday of April. If the first Thursday of April is in the week before easter, then a week later.
155155
arguments: year
156-
source: |
156+
ruby: |
157157
date = Date.civil(year,4,1)
158158
# Find the first Thursday of April
159159
until date.wday.eql? 4 do
160160
date += 1
161161
end
162162
163-
if date.eql?(Holidays::Factory::DateCalculator::Easter::Gregorian.easter_calculator.calculate_easter_for(year)-3)
163+
if date.eql?(%{EASTER}(year)-3)
164164
date += 7
165165
end
166166
date

cl.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ methods:
8686
st_peter_st_paul_cl:
8787
arguments: year
8888
# Nearest monday
89-
source: |
89+
ruby: |
9090
date = Date.civil(year, 6, 29)
9191
if [2,3,4].include?(date.wday)
9292
date -= (date.wday - 1)
@@ -97,7 +97,7 @@ methods:
9797
columbus_day_cl:
9898
arguments: year
9999
# Nearest monday
100-
source: |
100+
ruby: |
101101
date = Date.civil(year, 10, 12)
102102
if [2,3,4].include?(date.wday)
103103
date -= (date.wday - 1)
@@ -108,7 +108,7 @@ methods:
108108
other_churches_day_cl:
109109
arguments: year
110110
# If on tuesday, friday before, if on wednesday, next friday
111-
source: |
111+
ruby: |
112112
date = Date.civil(year, 10, 31)
113113
if date.wday == 2
114114
date -= 4

de.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ methods:
139139
de_buss_und_bettag:
140140
# Germany: Wednesday before November 23
141141
arguments: year
142-
source: |
142+
ruby: |
143143
date = Date.civil(year,11,23)
144144
if date.wday > 3
145145
date -= (date.wday - 3)

fedex.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ months:
4242
- name: New Year's Eve
4343
regions: [fedex]
4444
mday: 31
45+
4546
methods:
4647
day_after_thanksgiving:
4748
arguments: year
48-
source: |
49-
Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 11, 4, 4) + 1
49+
ruby: |
50+
%{CALCULATE_DAY_OF_MONTH}(year, 11, 4, 4) + 1
5051
5152
tests:
5253
- given:

fi.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,12 @@ months:
5959
- name: Tapaninpäivä
6060
regions: [fi]
6161
mday: 26
62+
6263
methods:
6364
fi_juhannusaatto:
6465
# Finland: Mid-summer eve (Friday between June 19–25)
6566
arguments: year
66-
source: |
67+
ruby: |
6768
date = Date.civil(year,6,19)
6869
if date.wday > 5 #if 19.6 is saturday
6970
date += 6
@@ -74,14 +75,14 @@ methods:
7475
fi_juhannuspaiva:
7576
# Finland: Mid-summer (Saturday between June 20–26)
7677
arguments: year
77-
source: |
78+
ruby: |
7879
date = Date.civil(year,6,20)
7980
date += (6 - date.wday)
8081
date
8182
fi_pyhainpaiva:
8283
# Finland: All Saint's Day (Saturday between Oct 31 and Nov 6)
8384
arguments: year
84-
source: |
85+
ruby: |
8586
date = Date.civil(year,10,31)
8687
date += (6 - date.wday)
8788
date

hk.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ months:
7171
methods:
7272
cn_new_lunar_day:
7373
arguments: year
74-
source: |
74+
ruby: |
7575
month_day = case year
7676
when 1930, 1949, 1987, 2025, 2063, 2082, 2101, 2112, 2131, 2150, 2207, 2245, 2253, 2283, 2321
7777
[1, 29]

is.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ methods:
114114
is_sumardagurinn_fyrsti:
115115
# Iceland: first day of summer (Thursday after 18 April)
116116
arguments: year
117-
source: |
117+
ruby: |
118118
date = Date.civil(year,4,18)
119119
if date.wday < 4
120120
date += (4 - date.wday)

0 commit comments

Comments
 (0)