diff --git a/Gemfile b/Gemfile index 1278d367..fa19d0a6 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,7 @@ source 'https://rubygems.org' gem 'rspec', '~> 3' +gem 'countries' gem 'pry', :require => false gem 'spoon', :require => false gem 'simplecov', :require => false diff --git a/ar.yaml b/ar.yaml index 3edd721a..1a7a6bdd 100644 --- a/ar.yaml +++ b/ar.yaml @@ -8,6 +8,8 @@ # - https://www.argentina.gob.ar/interior/feriados-nacionales-2020 # - https://www.argentina.gob.ar/interior/feriados-nacionales-2021 --- +region_names: + ar: "Argentina" methods: to_nearest_monday: arguments: date diff --git a/at.yaml b/at.yaml index f683c8da..8ca6aa2c 100644 --- a/at.yaml +++ b/at.yaml @@ -6,6 +6,8 @@ # - http://www.timeanddate.com/calendar/index.html?country=8 # - http://www.germany.info/relaunch/welcome/travel/holidays.html --- +region_names: + at: "Austria" months: 0: - name: Ostermontag diff --git a/au.yaml b/au.yaml index d976ff09..597ec714 100644 --- a/au.yaml +++ b/au.yaml @@ -6,6 +6,21 @@ # - http://www.wst.tas.gov.au/employment_info/public_holidays # - https://www.fairwork.gov.au/leave/public-holidays/list-of-public-holidays --- +region_names: + au: "Australia" + au_act: "Australian Capital Territory" + au_nsw: "New South Wales" + au_nt: "Northern Territory" + au_qld: "Queensland" + au_qld_brisbane: "Brisbane" + au_qld_cairns: "Cairns" + au_sa: "South Australia" + au_tas: "Tasmania" + au_tas_north: "Northern Tasmania" + au_tas_south: "Southern Tasmania" + au_vic: "Victoria" + au_vic_melbourne: "Melbourne" + au_wa: "Western Australia" months: 0: - name: Good Friday diff --git a/be_fr.yaml b/be_fr.yaml index 4ef6aeb3..269ba2ef 100644 --- a/be_fr.yaml +++ b/be_fr.yaml @@ -4,6 +4,8 @@ # Sources: # - http://en.wikipedia.org/wiki/Public_holidays_in_Belgium --- +region_names: + be_fr: "Belgium (French)" months: 0: - name: Pâques diff --git a/be_nl.yaml b/be_nl.yaml index 20dd4d63..137e5aea 100644 --- a/be_nl.yaml +++ b/be_nl.yaml @@ -4,6 +4,8 @@ # Sources: # - http://en.wikipedia.org/wiki/Public_holidays_in_Belgium --- +region_names: + be_nl: "Belgium (Dutch)" months: 0: - name: Pasen diff --git a/bg.yaml b/bg.yaml index 86a8c168..9f8e6d9e 100644 --- a/bg.yaml +++ b/bg.yaml @@ -3,6 +3,9 @@ # Updated: 2015-04-01. # Source: http://en.wikipedia.org/wiki/Public_holidays_in_Bulgaria --- +region_names: + bg_bg: "Bulgaria" + bg_en: "Bulgaria" months: 0: - name: Good Friday diff --git a/br.yaml b/br.yaml index decc6e88..aa0f9fac 100644 --- a/br.yaml +++ b/br.yaml @@ -6,6 +6,8 @@ # - http://pt.wikipedia.org/wiki/Feriados_no_Brasil --- +region_names: + br: "Brazil" months: 0: - name: Carnaval # same as Shrove Tuesday diff --git a/ca.yaml b/ca.yaml index 73d8aee9..ee8dabd8 100644 --- a/ca.yaml +++ b/ca.yaml @@ -8,6 +8,21 @@ # - 'Nunavut’s legislative assembly voted to pass Bill 29 making Nunavut Day', July 9, an officially statutory holiday across the territory. https://www.gov.nu.ca/human-resources/information/public-service-holidays # - 'According to Manitoba labour standards, Terry Fox Day is not a formal holiday. https://www.gov.mb.ca/labour/standards/doc,gen-holidays-after-april-30-07,factsheet.html#q13' --- +region_names: + ca: "Canada" + ca_ab: "Alberta" + ca_bc: "British Columbia" + ca_mb: "Manitoba" + ca_nb: "New Brunswick" + ca_nl: "Newfoundland and Labrador" + ca_ns: "Nova Scotia" + ca_nt: "Northwest Territories" + ca_nu: "Nunavut" + ca_on: "Ontario" + ca_pe: "Prince Edward Island" + ca_qc: "Quebec" + ca_sk: "Saskatchewan" + ca_yt: "Yukon" months: 0: - name: Good Friday diff --git a/ch.yaml b/ch.yaml index 81e7cd51..0fd8c6fb 100644 --- a/ch.yaml +++ b/ch.yaml @@ -25,6 +25,34 @@ # - 26th of December is not celebrated in case the 25th is a Monday or a Friday. # * ch_ne: 26th of December and 2nd of January are only celebrated in case 25th of December and 1st of January are Sundays --- +region_names: + ch: "Switzerland" + ch_ag: "Aargau" + ch_ai: "Appenzell Innerrhoden" + ch_ar: "Appenzell Ausserrhoden" + ch_be: "Bern" + ch_bl: "Basel-Landschaft" + ch_bs: "Basel-Stadt" + ch_fr: "Fribourg" + ch_ge: "Genève" + ch_gl: "Glarus" + ch_gr: "Graubünden" + ch_ju: "Jura" + ch_lu: "Luzern" + ch_ne: "Neuchâtel" + ch_nw: "Nidwalden" + ch_ow: "Obwalden" + ch_sg: "Sankt Gallen" + ch_sh: "Schaffhausen" + ch_so: "Solothurn" + ch_sz: "Schwyz" + ch_tg: "Thurgau" + ch_ti: "Ticino" + ch_ur: "Uri" + ch_vd: "Vaud" + ch_vs: "Valais" + ch_zg: "Zug" + ch_zh: "Zürich" months: 0: - name: Karfreitag diff --git a/cl.yaml b/cl.yaml index 1e9160b9..3f026bae 100644 --- a/cl.yaml +++ b/cl.yaml @@ -7,6 +7,8 @@ # - http://www.feriadoschilenos.cl # --- +region_names: + cl: "Chile" months: 0: - name: Viernes Santo diff --git a/co.yaml b/co.yaml index 08c54df5..45936ad0 100644 --- a/co.yaml +++ b/co.yaml @@ -10,6 +10,8 @@ # - https://www.timeanddate.com/holidays/colombia/ # - http://www.bank-holidays.com/country/Colombia_42.htm --- +region_names: + co: "Colombia" methods: # Movable holiday: when they do not fall on a Monday, these holidays are observed the following Monday. to_following_monday_if_not_monday: diff --git a/cr.yaml b/cr.yaml index c6f9e500..08314cd0 100644 --- a/cr.yaml +++ b/cr.yaml @@ -6,6 +6,9 @@ # Sources: # - http://en.wikipedia.org/wiki/Public_holidays_in_Costa_Rica # +--- +region_names: + cr: "Costa Rica" months: 0: - name: Jueves Santo diff --git a/cy.yaml b/cy.yaml index 8724212b..4bf106b3 100644 --- a/cy.yaml +++ b/cy.yaml @@ -5,6 +5,8 @@ # https://el.wikipedia.org/wiki/%CE%94%CE%B7%CE%BC%CF%8C%CF%83%CE%B9%CE%B5%CF%82_%CE%B1%CF%81%CE%B3%CE%AF%CE%B5%CF%82_%CF%83%CF%84%CE%B7%CE%BD_%CE%9A%CF%8D%CF%80%CF%81%CE%BF # https://www.centralbank.cy/the-bank/working-hours-bank-holidays --- +region_names: + cy: "Cyprus" months: 0: - name: Μεγάλη Παρασκευή diff --git a/cz.yaml b/cz.yaml index 9e90b149..12c56ed4 100644 --- a/cz.yaml +++ b/cz.yaml @@ -5,6 +5,8 @@ # - http://cs.wikipedia.org/wiki/%C4%8Cesk%C3%BD_st%C3%A1tn%C3%AD_sv%C3%A1tek # - http://www.mpsv.cz/cs/74 --- +region_names: + cz: "Czechia" months: 0: - name: Velký pátek diff --git a/de.yaml b/de.yaml index 75eb1a37..06db7bd8 100644 --- a/de.yaml +++ b/de.yaml @@ -40,6 +40,28 @@ # - https://www.statistik.bayern.de/statistik/bevoelkerungsstand/00141.php # - http://www.thueringen.de/mam/th3/tim/verwaltungsrecht/fronleichnam_gemeindeschluesselzahlen.pdf --- +region_names: + de: "Germany" + de_bb: "Brandenburg" + de_be: "Berlin" + de_bw: "Baden-Württemberg" + de_by: "Bayern" + de_by_augsburg: "Augsburg (Bayern)" + de_by_cath: "Bayern (Catholic regions)" + de_hb: "Bremen" + de_he: "Hessen" + de_hh: "Hamburg" + de_mv: "Mecklenburg-Vorpommern" + de_ni: "Niedersachsen" + de_nw: "Nordrhein-Westfalen" + de_rp: "Rheinland-Pfalz" + de_sh: "Schleswig-Holstein" + de_sl: "Saarland" + de_sn: "Sachsen" + de_sn_sorbian: "Sachsen (Sorbian regions)" + de_st: "Sachsen-Anhalt" + de_th: "Thüringen" + de_th_cath: "Thüringen (Catholic regions)" months: 0: - name: Karfreitag diff --git a/dk.yaml b/dk.yaml index 101ad367..cc0707ba 100644 --- a/dk.yaml +++ b/dk.yaml @@ -6,6 +6,8 @@ # - http://www.amblondon.um.dk/en/menu/AboutDenmark/PublicHolidaysInDK/PublicHolidaysinDenmark-until2010.htm # - http://borger.dk/forside/kirke-og-tro/folkekirken/officielle-helligdage --- +region_names: + dk: "Denmark" months: 0: - name: Fastelavn diff --git a/doc/SYNTAX.md b/doc/SYNTAX.md index b6978190..b648aafc 100644 --- a/doc/SYNTAX.md +++ b/doc/SYNTAX.md @@ -1,12 +1,13 @@ # Holiday Definition Syntax -The definition syntax is a custom format developed over the life of this project. All holidays are defined in these YAML files. These definition files have three main top-level properties: +The definition syntax is a custom format developed over the life of this project. All holidays are defined in these YAML files. These definition files have four top-level properties: +* `region_names` - human-readable English names for each region defined in this file * `months` - this is the meat! All definitions for months 1-12 are defined here * `methods` - this contains any custom logic that your definitions require * `tests` - this contains the tests for your definitions -The `months` property is required. The two other properties are not strictly required but are almost always used. +The `months` property is required. The remaining properties are not strictly required but are almost always used. In fact, if you leave out `tests` your PR will probably not be accepted unless there is a very, very good reason for leaving it out. @@ -47,6 +48,35 @@ We recognize that these definitions can be highly subjective. If you disagree wi There are certain holidays that can be legally observed on different days than they occur. For example, if a holiday falls on a Saturday but it is legally observed on the following Monday then you can define it as `observed` on the Monday. Please see the section below for more details and examples. +## Region Names + +Each definition file should include a `region_names` section mapping every region symbol used in that file to its English name. Names use the common English name from [ISO 3166](https://en.wikipedia.org/wiki/ISO_3166) wherever a standard exists. Using the ISO standard as the source of truth means that i18n libraries can translate these names into other languages without requiring this project to maintain its own translations. + +```yaml +region_names: + gb: "United Kingdom" + gb_eng: "England" + gb_wls: "Wales" + gb_sct: "Scotland" + gb_nir: "Northern Ireland" +``` + +### Naming conventions + +- **ISO 3166-1 countries** (e.g. `:gb`, `:fr`): use the ISO 3166-1 common English name (e.g. `gb` is `"United Kingdom"`, not `"United Kingdom of Great Britain and Northern Ireland"`) +- **ISO 3166-2 subdivisions** (e.g. `:gb_eng`, `:de_by`): use the ISO 3166-2 official name, note that ISO 3166-2 names are in the official language of the country, not necessarily English (e.g. `de_by` is `"Bayern"`, not `"Bavaria"`) +- **Non-geographic regions** (e.g. `:nyse`, `:federalreserve`): use a clear English descriptive name +- **Gem-specific composite regions** with no ISO counterpart (e.g. `:gb_eaw`): use a reasonable English descriptive name + +### YAML quoting note + +Region symbols that are YAML reserved words must be quoted. For example, `no` (Norway) is interpreted as a boolean by YAML parsers and must be written as `"no"`: + +```yaml +region_names: + "no": "Norway" +``` + ## Months Holidays are grouped by month from 1 through 12. Each entry within a month can have several properties depending on the behavior of the holiday. Each section below lays out the various different ways you can define your holiday. diff --git a/ecbtarget.yaml b/ecbtarget.yaml index 636ead0e..d82da4b8 100644 --- a/ecbtarget.yaml +++ b/ecbtarget.yaml @@ -1,74 +1,76 @@ -# ECB TARGET Closing Days -# -# Updated: 2014-01-04. -# Sources: -# - http://www.ecb.europa.eu/home/html/holidays.en.html -# - http://www.ecb.europa.eu/press/pr/date/2000/html/pr001214_4.en.html ---- -months: - 0: - - name: Good Friday - regions: [ecbtarget] - function: easter(year) - function_modifier: -2 - - name: Easter Monday - regions: [ecbtarget] - function: easter(year) - function_modifier: 1 - 1: - - name: New Year's Day - regions: [ecbtarget] - mday: 1 - 5: - - name: Labour Day - regions: [ecbtarget] - mday: 1 - 12: - - name: Christmas Day - regions: [ecbtarget] - mday: 25 - - name: Christmas Holiday - regions: [ecbtarget] - mday: 26 - -tests: - - given: - date: '2013-01-01' - regions: ["ecbtarget"] - expect: - name: "New Year's Day" - - given: - date: '2013-05-01' - regions: ["ecbtarget"] - expect: - name: "Labour Day" - - given: - date: '2013-03-29' - regions: ["ecbtarget"] - expect: - name: "Good Friday" - - given: - date: '2013-04-01' - regions: ["ecbtarget"] - expect: - name: "Easter Monday" - - given: - date: '2013-12-25' - regions: ["ecbtarget"] - expect: - name: "Christmas Day" - - given: - date: '2013-12-26' - regions: ["ecbtarget"] - expect: - name: "Christmas Holiday" - - given: - date: '2013-03-29' - regions: ["ecbtarget"] - expect: - name: "Good Friday" - - given: - date: '2013-04-01' - regions: ["ecbtarget"] - expect: - name: "Easter Monday" +# ECB TARGET Closing Days +# +# Updated: 2014-01-04. +# Sources: +# - http://www.ecb.europa.eu/home/html/holidays.en.html +# - http://www.ecb.europa.eu/press/pr/date/2000/html/pr001214_4.en.html +--- +region_names: + ecbtarget: "ECB TARGET (European Central Bank)" +months: + 0: + - name: Good Friday + regions: [ecbtarget] + function: easter(year) + function_modifier: -2 + - name: Easter Monday + regions: [ecbtarget] + function: easter(year) + function_modifier: 1 + 1: + - name: New Year's Day + regions: [ecbtarget] + mday: 1 + 5: + - name: Labour Day + regions: [ecbtarget] + mday: 1 + 12: + - name: Christmas Day + regions: [ecbtarget] + mday: 25 + - name: Christmas Holiday + regions: [ecbtarget] + mday: 26 + +tests: + - given: + date: '2013-01-01' + regions: ["ecbtarget"] + expect: + name: "New Year's Day" + - given: + date: '2013-05-01' + regions: ["ecbtarget"] + expect: + name: "Labour Day" + - given: + date: '2013-03-29' + regions: ["ecbtarget"] + expect: + name: "Good Friday" + - given: + date: '2013-04-01' + regions: ["ecbtarget"] + expect: + name: "Easter Monday" + - given: + date: '2013-12-25' + regions: ["ecbtarget"] + expect: + name: "Christmas Day" + - given: + date: '2013-12-26' + regions: ["ecbtarget"] + expect: + name: "Christmas Holiday" + - given: + date: '2013-03-29' + regions: ["ecbtarget"] + expect: + name: "Good Friday" + - given: + date: '2013-04-01' + regions: ["ecbtarget"] + expect: + name: "Easter Monday" diff --git a/ee.yaml b/ee.yaml index c5bd5dc3..72054b59 100644 --- a/ee.yaml +++ b/ee.yaml @@ -13,6 +13,8 @@ # - https://en.wikipedia.org/wiki/Public_holidays_in_Estonia # - https://www.riigiteataja.ee/akt/13276841?leiaKehtiv --- +region_names: + ee: "Estonia" months: 0: - name: suur reede # Good Friday diff --git a/es.yaml b/es.yaml index 263c4f7a..10f31b61 100644 --- a/es.yaml +++ b/es.yaml @@ -10,6 +10,27 @@ # # Notes: # - Valencia is encoded as both es_v and es_vc +--- +region_names: + es: "Spain" + es_an: "Andalucía" + es_ar: "Aragón" + es_ce: "Ceuta" + es_cl: "Castilla y León" + es_cm: "Castilla-La Mancha" + es_cn: "Canary Islands" + es_ct: "Cataluña" + es_ex: "Extremadura" + es_ga: "Galicia" + es_ib: "Islas Baleares" + es_lo: "Rioja, La" + es_m: "Madrid" + es_mu: "Murcia" + es_na: "Navarra" + es_o: "Asturias" + es_pv: "País Vasco" + es_v: "Valencia/València" + es_vc: "Comunidad Valenciana" months: 0: - name: Jueves Santo diff --git a/federalreserve.yaml b/federalreserve.yaml index 35bcec2c..6112fe3a 100644 --- a/federalreserve.yaml +++ b/federalreserve.yaml @@ -5,6 +5,8 @@ # Sources: # - http://www.federalreserve.gov/aboutthefed/k8.htm --- +region_names: + federalreserve: "Federal Reserve" months: 1: - name: New Year's Day diff --git a/federalreservebanks.yaml b/federalreservebanks.yaml index 8259a21e..ac40cb19 100644 --- a/federalreservebanks.yaml +++ b/federalreservebanks.yaml @@ -9,6 +9,8 @@ # Sources: # - http://www.federalreserve.gov/aboutthefed/k8.htm --- +region_names: + federalreservebanks: "Federal Reserve Banks" months: 1: - name: New Year's Day diff --git a/fedex.yaml b/fedex.yaml index 4b70880f..bef2f860 100644 --- a/fedex.yaml +++ b/fedex.yaml @@ -5,6 +5,8 @@ # Updated: 2015-03-09. # Source: http://www.fedex.com/us/service-guide/holiday-schedule.html --- +region_names: + fedex: "FedEx" months: 1: - name: New Year's Day diff --git a/fi.yaml b/fi.yaml index 0a7447f3..42b7e8d8 100644 --- a/fi.yaml +++ b/fi.yaml @@ -4,6 +4,8 @@ # Sources: # - http://en.wikipedia.org/wiki/Public_holidays_in_Finland --- +region_names: + fi: "Finland" months: 0: - name: Pitkäperjantai diff --git a/fr.yaml b/fr.yaml index 0d44402b..a3d5153d 100644 --- a/fr.yaml +++ b/fr.yaml @@ -10,6 +10,10 @@ # - http://vosdroits.service-public.fr/particuliers/F2405.xhtml # - https://en.wikipedia.org/wiki/Public_holidays_in_France --- +region_names: + fr: "France" + fr_a: "Alsace" + fr_m: "Moselle" months: 0: - name: Vendredi saint diff --git a/gb.yaml b/gb.yaml index 6b1f55b7..18e2c7af 100644 --- a/gb.yaml +++ b/gb.yaml @@ -12,6 +12,20 @@ # - England and Wales together should be encoded as [gb_eng, gb_wls, gb_eaw...] # - For :gb_sct, St. Andrew's Day is 'informal' 2006 and earlier but a bank holiday from 2007 on. --- +region_names: + gb: "United Kingdom" + gb_con: "Cornwall" + gb_eaw: "England and Wales" + gb_eng: "England" + gb_gsy: "Guernsey" + gb_iom: "Isle of Man" + gb_jsy: "Jersey" + gb_nir: "Northern Ireland" + gb_sct: "Scotland" + gb_wls: "Wales" + gg: "Guernsey" + im: "Isle of Man" + je: "Jersey" months: 0: - name: Mothering Sunday diff --git a/ge.yaml b/ge.yaml index cb23e091..97475e13 100644 --- a/ge.yaml +++ b/ge.yaml @@ -6,6 +6,8 @@ # - https://de.wikipedia.org/wiki/Feiertage_in_Georgien # - https://translate.yandex.com/?lang=ka-en --- +region_names: + ge: "Georgia" months: 0: - name: დიდი პარასკევი # Good Friday diff --git a/gr.yaml b/gr.yaml index d1556a85..2e855f68 100644 --- a/gr.yaml +++ b/gr.yaml @@ -9,6 +9,8 @@ # http://el.wikipedia.org/wiki/Επίσημες_αργίες_στην_Ελλάδα - for holidays # http://www.eortologio.gr/arthra/pasxa.php - for holidays --- +region_names: + gr: "Greece" months: 0: - name: Μεγάλη Παρασκευή diff --git a/hk.yaml b/hk.yaml index c06df601..bf48689f 100644 --- a/hk.yaml +++ b/hk.yaml @@ -4,6 +4,9 @@ # http://www.gov.hk/en/about/abouthk/holiday/ # https://en.wikipedia.org/wiki/Public_holidays_in_Hong_Kong +--- +region_names: + hk: "Hong Kong" months: 0: - name: Good Friday diff --git a/hr.yaml b/hr.yaml index 64d21987..14baaf75 100644 --- a/hr.yaml +++ b/hr.yaml @@ -4,6 +4,8 @@ # Sources: # http://en.wikipedia.org/wiki/Public_holidays_in_Croatia --- +region_names: + hr: "Croatia" months: 0: - name: Uskrs diff --git a/hu.yaml b/hu.yaml index 8721028f..9ce80b7e 100644 --- a/hu.yaml +++ b/hu.yaml @@ -2,6 +2,8 @@ # # Updated: 2012-03-01 by spap --- +region_names: + hu: "Hungary" months: 0: - name: Nagypéntek diff --git a/ie.yaml b/ie.yaml index 793ea3c6..bb6ff261 100644 --- a/ie.yaml +++ b/ie.yaml @@ -6,6 +6,8 @@ # - http://www.citizensinformation.ie/categories/employment/employment-rights-and-conditions/leave-and-holidays/public-holidays-in-ireland # While there is mention that Jan 2 2012 was not officially a bank holiday, in reality very few businesses will not observe that date as a bank holiday --- +region_names: + ie: "Ireland" months: 0: - name: Easter Monday diff --git a/il.yaml b/il.yaml index 91aa2d92..01cc8add 100644 --- a/il.yaml +++ b/il.yaml @@ -9,6 +9,8 @@ # - Israel has its own way of calculation holidays (different calendar). # - In case of holidays being out of date - message voiteh322@gmail.com to update. --- +region_names: + il: "Israel" months: 3: - name: Exodus from Egypt diff --git a/in.yaml b/in.yaml index 69d8361a..0470a3cf 100644 --- a/in.yaml +++ b/in.yaml @@ -4,6 +4,32 @@ # Sources: # - https://en.wikipedia.org/wiki/Public_holidays_in_India --- +region_names: + in: "India" + in_ap: "Andhra Pradesh" + in_ar: "Arunachal Pradesh" + in_as: "Assam" + in_br: "Bihar" + in_cg: "Chhattisgarh" + in_ga: "Goa" + in_gj: "Gujarat" + in_hp: "Himachal Pradesh" + in_hr: "Haryana" + in_jh: "Jharkhand" + in_jk: "Jammu and Kashmir" + in_ka: "Karnataka" + in_kl: "Kerala" + in_mh: "Maharashtra" + in_mp: "Madhya Pradesh" + in_mz: "Mizoram" + in_nl: "Nagaland" + in_od: "Odisha" + in_pb: "Punjab" + in_py: "Pondicherry" + in_sk: "Sikkim" + in_tr: "Tripura" + in_ts: "तेलंगाना" + in_wb: "West Bengal" months: 0: - name: Good Friday diff --git a/is.yaml b/is.yaml index cb101a52..384f5e03 100644 --- a/is.yaml +++ b/is.yaml @@ -7,6 +7,8 @@ # - http://en.wikipedia.org/wiki/Public_holidays_in_Iceland # - http://www.qppstudio.net/publicholidays2007/iceland.htm --- +region_names: + is: "Iceland" months: 0: - name: Bolludagur diff --git a/it.yaml b/it.yaml index 50a99d4c..463cf9c1 100644 --- a/it.yaml +++ b/it.yaml @@ -26,6 +26,19 @@ # Sources: # - https://it.wikipedia.org/wiki/Santi_patroni_cattolici_delle_citt%C3%A0_capoluogo_di_provincia_italiane --- +region_names: + it: "Italy" + it_bl: "Belluno" + it_fi: "Firenze" + it_ge: "Genova" + it_pd: "Padova" + it_rm: "Roma" + it_ro: "Rovigo" + it_to: "Torino" + it_tv: "Treviso" + it_ve: "Venezia" + it_vi: "Vicenza" + it_vr: "Verona" months: 0: - name: Pasqua diff --git a/jp.yaml b/jp.yaml index 0e8c06c9..5abe5dc3 100644 --- a/jp.yaml +++ b/jp.yaml @@ -24,6 +24,8 @@ # It is overly verbose and not easy to follow. It will be a target for refactoring # in the near future. --- +region_names: + jp: "Japan" months: 1: - name: 元日 diff --git a/ke.yaml b/ke.yaml index e6b9d6d3..4e020eef 100644 --- a/ke.yaml +++ b/ke.yaml @@ -6,6 +6,8 @@ # - https://www.timeanddate.com/holidays/kenya/ # - http://www.kenyalaw.org/kl/fileadmin/pdfdownloads/Acts/PublicHolidaysActCap110.pdf --- +region_names: + ke: "Kenya" months: 0: - name: Good Friday diff --git a/kr.yaml b/kr.yaml index 0cf2b7c4..dd1c867b 100644 --- a/kr.yaml +++ b/kr.yaml @@ -9,6 +9,8 @@ # For Korean/English translations of each holiday: # - https://ko.wikipedia.org/wiki/%EB%8C%80%ED%95%9C%EB%AF%BC%EA%B5%AD%EC%9D%98_%EA%B3%B5%ED%9C%B4%EC%9D%BC --- +region_names: + kr: "South Korea" months: 1: - name: 설날 diff --git a/kz.yaml b/kz.yaml index 670b185f..46346c73 100644 --- a/kz.yaml +++ b/kz.yaml @@ -5,6 +5,8 @@ # - https://www.officeholidays.com/countries/kazakhstan/2020 # - https://en.wikipedia.org/wiki/Public_holidays_in_Kazakhstan --- +region_names: + kz: "Kazakhstan" months: 1: - name: Jańa jyl # New Year's Day diff --git a/li.yaml b/li.yaml index 59cb4c52..645f6e51 100644 --- a/li.yaml +++ b/li.yaml @@ -4,6 +4,8 @@ # Sources: # http://www.tourismus.li/de/navpage-RegionLI-InformationLI-44728.html --- +region_names: + li: "Liechtenstein" months: 0: - name: Fasnachtsdienstag diff --git a/lib/validation/definition_validator.rb b/lib/validation/definition_validator.rb index 247db6de..cda69230 100644 --- a/lib/validation/definition_validator.rb +++ b/lib/validation/definition_validator.rb @@ -3,33 +3,21 @@ module Definitions module Validation class Definition - def initialize(custom_method_validator, months_validator, test_validator) + def initialize(region_names_validator, custom_method_validator, months_validator, test_validator) + @region_names_validator = region_names_validator @custom_method_validator = custom_method_validator @months_validator = months_validator @test_validator = test_validator end def call(definition) - validate_months!(definition['months']) - validate_methods!(definition['methods']) - validate_tests!(definition['tests']) + @region_names_validator.call(definition['region_names'], definition['months']) + @months_validator.call(definition['months']) + @custom_method_validator.call(definition['methods']) unless definition['methods'].nil? + @test_validator.call(definition['tests']) unless definition['tests'].nil? true end - - private - - def validate_months!(months) - @months_validator.call(months) - end - - def validate_methods!(methods) - @custom_method_validator.call(methods) unless methods.nil? - end - - def validate_tests!(tests) - @test_validator.call(tests) unless tests.nil? - end end end end diff --git a/lib/validation/error.rb b/lib/validation/error.rb index d3095bef..ea7ea08c 100644 --- a/lib/validation/error.rb +++ b/lib/validation/error.rb @@ -7,5 +7,6 @@ class InvalidMethod < Error; end class InvalidRegions < Error; end class InvalidCustomMethod < Error; end class InvalidTest < Error; end + class InvalidRegionNames < Error; end end end diff --git a/lib/validation/region_names_validator.rb b/lib/validation/region_names_validator.rb new file mode 100644 index 00000000..fa9edf57 --- /dev/null +++ b/lib/validation/region_names_validator.rb @@ -0,0 +1,84 @@ +require_relative 'error' + +module Definitions + module Validation + class RegionNames + # :vi is a non-standard gem code for Vietnam (ISO 3166-1 VI = US Virgin Islands). + # Skip ISO validation until the breaking rename :vi -> :vn is made. + # See: https://github.com/holidays/definitions/issues/177 + NON_ISO_REGIONS = %w[vi].freeze + + def initialize(iso_names = {}) + @iso_names = iso_names + end + + def call(region_names, months) + validate_presence!(region_names) + validate_coverage!(region_names, months) + validate_iso_names!(region_names) + end + + private + + def validate_presence!(region_names) + raise Errors::InvalidRegionNames.new("region_names is required") if region_names.nil? + raise Errors::InvalidRegionNames.new("region_names must be a hash, received: '#{region_names}'") unless region_names.is_a?(Hash) + raise Errors::InvalidRegionNames.new("region_names must not be empty") if region_names.empty? + end + + def validate_coverage!(region_names, months) + regions_in_months = extract_regions(months) + region_name_keys = region_names.keys.map(&:to_s) + + missing = regions_in_months - region_name_keys + extra = region_name_keys - regions_in_months + + unless missing.empty? + raise Errors::InvalidRegionNames.new( + "region_names is missing entries for regions: #{missing.sort.join(', ')}" + ) + end + + unless extra.empty? + raise Errors::InvalidRegionNames.new( + "region_names has entries for regions not found in months: #{extra.sort.join(', ')}" + ) + end + + true + end + + def validate_iso_names!(region_names) + mismatches = [] + + region_names.each do |code, name| + code_str = code.to_s + next if NON_ISO_REGIONS.include?(code_str) + + expected = @iso_names[code_str] + next if expected.nil? + + mismatches << "#{code}: expected '#{expected}' but got '#{name}'" unless name == expected + end + + unless mismatches.empty? + raise Errors::InvalidRegionNames.new( + "region_names has incorrect ISO names:\n#{mismatches.join("\n")}\nSee doc/SYNTAX.md for naming conventions." + ) + end + + true + end + + def extract_regions(months) + months.each_with_object([]) do |(_, month_defs), regions| + month_defs.each do |month_def| + Array(month_def['regions']).each do |region| + regions << region.to_s unless region.nil? || region.empty? + end + end + end.uniq + end + end + end +end diff --git a/lib/validation/run.rb b/lib/validation/run.rb index 99e4d1d5..9c86af3a 100644 --- a/lib/validation/run.rb +++ b/lib/validation/run.rb @@ -1,9 +1,11 @@ ## encoding: utf-8 require 'yaml' +require 'countries' require_relative 'error' require_relative 'definition_validator' +require_relative 'region_names_validator' require_relative 'custom_method_validator' require_relative 'month_validator' require_relative 'test_validator' @@ -56,9 +58,21 @@ def validate!(definition) end end +# Build a flat lookup of region code -> ISO common name for all countries and their +# subdivisions. Injected into RegionNames validator so the validator itself has no +# direct dependency on the countries gem. +iso_names = {} +ISO3166::Country.all.each do |country| + iso_names[country.alpha2.downcase] = country.common_name + country.subdivisions.each do |sub_code, sub| + iso_names["#{country.alpha2.downcase}_#{sub_code.downcase}"] = sub.name.gsub(/ \([a-z]{2,3}\)$/, '') + end +end + Definitions::Validate.new( definitions_path, Definitions::Validation::Definition.new( + Definitions::Validation::RegionNames.new(iso_names), Definitions::Validation::CustomMethod.new, Definitions::Validation::Month.new, Definitions::Validation::Test.new, diff --git a/lt.yaml b/lt.yaml index 92073b31..ee0258fe 100644 --- a/lt.yaml +++ b/lt.yaml @@ -5,6 +5,8 @@ # - http://en.wikipedia.org/wiki/Public_holidays_in_Lithuania # - http://day.lt/sventes/nedarbo --- +region_names: + lt: "Lithuania" months: 0: - name: Šv. Velykos diff --git a/lu.yaml b/lu.yaml index 7595e512..84f67488 100644 --- a/lu.yaml +++ b/lu.yaml @@ -4,6 +4,8 @@ # Sources: # - https://en.wikipedia.org/wiki/Public_holidays_in_Luxembourg --- +region_names: + lu: "Luxembourg" months: 0: - name: Ouschterméindeg diff --git a/lv.yaml b/lv.yaml index d0b27c0a..fbb9c114 100644 --- a/lv.yaml +++ b/lv.yaml @@ -4,6 +4,8 @@ # Sources: # - https://likumi.lv/ta/id/72608 (Likums "Par svētku, atceres un atzīmējamām dienām") --- +region_names: + lv: "Latvia" months: 0: - name: Lielā Piektdiena # Good Friday diff --git a/ma.yaml b/ma.yaml index 8f67f6db..b3b5cfd6 100644 --- a/ma.yaml +++ b/ma.yaml @@ -5,6 +5,8 @@ # Sources: # - http://en.wikipedia.org/wiki/Public_holidays_in_Morocco --- +region_names: + ma: "Morocco" months: 1: - name: Ras l' âm diff --git a/mt_en.yaml b/mt_en.yaml index a00f6630..792331fd 100644 --- a/mt_en.yaml +++ b/mt_en.yaml @@ -4,6 +4,8 @@ # Sources: # - https://en.wikipedia.org/wiki/Public_holidays_in_Malta --- +region_names: + mt_en: "Malta" months: 0: - name: Good Friday # Il-Ġimgħa l-Kbira diff --git a/mt_mt.yaml b/mt_mt.yaml index 7d69dc0e..83089153 100644 --- a/mt_mt.yaml +++ b/mt_mt.yaml @@ -4,6 +4,8 @@ # Sources: # - https://en.wikipedia.org/wiki/Public_holidays_in_Malta --- +region_names: + mt_mt: "Malta" months: 0: - name: Il-Ġimgħa l-Kbira # Good Friday diff --git a/mx.yaml b/mx.yaml index 7e9fc68c..b9877102 100644 --- a/mx.yaml +++ b/mx.yaml @@ -4,6 +4,9 @@ # - http://www.britishembassy.gov.uk/servlet/Front?pagename=OpenMarket/Xcelerate/ShowPage&c=Page&cid=1125561634963 # - http://www.usembassy-mexico.gov/eng/holidays.html --- +region_names: + mx: "Mexico" + mx_pue: "Puebla" months: 1: - name: Año nuevo diff --git a/my.yaml b/my.yaml index d73a2dcf..34296fbc 100644 --- a/my.yaml +++ b/my.yaml @@ -9,6 +9,9 @@ # Source: # http://publicholidays.com.my/ +--- +region_names: + my: "Malaysia" months: 1: - name: New Year's Day diff --git a/nerc.yaml b/nerc.yaml index 34a1cac3..0565cdee 100644 --- a/nerc.yaml +++ b/nerc.yaml @@ -5,6 +5,8 @@ # # Updated 2013-01-03. --- +region_names: + nerc: "North American Electric Reliability Corporation" months: 1: - name: New Year's Day diff --git a/ng.yaml b/ng.yaml index 4932e58a..659ba0ed 100644 --- a/ng.yaml +++ b/ng.yaml @@ -3,6 +3,8 @@ # Sources: # - https://en.wikipedia.org/wiki/Public_holidays_in_Nigeria --- +region_names: + ng: "Nigeria" months: 0: - name: Good Friday diff --git a/nl.yaml b/nl.yaml index 521252f6..0fd9ca28 100644 --- a/nl.yaml +++ b/nl.yaml @@ -4,6 +4,8 @@ # Sources: # - http://en.wikipedia.org/wiki/Public_holidays_in_the_Netherlands --- +region_names: + nl: "Netherlands" months: 0: - name: Goede Vrijdag diff --git a/no.yaml b/no.yaml index 66f640a9..4148f4fa 100644 --- a/no.yaml +++ b/no.yaml @@ -5,6 +5,8 @@ # - http://no.wikipedia.org/wiki/Offentlig_fridag # - http://www.timeanddate.com/norsk/kalender.html --- +region_names: + "no": "Norway" months: 0: - name: Fastelavn diff --git a/northamericainformal.yaml b/northamericainformal.yaml index 71d31f6f..edf13d91 100644 --- a/northamericainformal.yaml +++ b/northamericainformal.yaml @@ -1,6 +1,9 @@ # Informal North American holiday definitions for the Ruby Holiday gem. # Updated 2008-11-22. --- +region_names: + ca: "Canada" + us: "United States" months: 2: - name: Groundhog Day diff --git a/nyse.yaml b/nyse.yaml index 356b0226..7e4fcc3d 100644 --- a/nyse.yaml +++ b/nyse.yaml @@ -8,6 +8,8 @@ # Source: https://www.nyse.com/markets/hours-calendars # Updated 2017-03-14 By Vassilios Liatsos --- +region_names: + nyse: "New York Stock Exchange" months: 0: - name: Good Friday diff --git a/nz.yaml b/nz.yaml index b29fdc6c..d2700eb5 100644 --- a/nz.yaml +++ b/nz.yaml @@ -4,6 +4,21 @@ # - http://en.wikipedia.org/wiki/Public_holidays_in_New_Zealand # - Matariki https://www.mbie.govt.nz/business-and-employment/employment-and-skills/employment-legislation-reviews/matariki/matariki-public-holiday/ --- +region_names: + nz: "New Zealand" + nz_ak: "Auckland" + nz_ca: "Canterbury" + nz_ch: "Chatham Islands" + nz_hb: "Hawke's Bay" + nz_mb: "Marlborough" + nz_ne: "Nelson" + nz_nl: "Northland" + nz_ot: "Otago" + nz_sc: "South Canterbury" + nz_sl: "Southland" + nz_ta: "Taranaki" + nz_we: "Wellington" + nz_wl: "Westland" months: 0: - name: Good Friday diff --git a/pe.yaml b/pe.yaml index 2e949f4a..a156cf17 100644 --- a/pe.yaml +++ b/pe.yaml @@ -17,6 +17,9 @@ # Christmas day observed # New year's eve # +--- +region_names: + pe: "Peru" months: 0: - name: Jueves Santo diff --git a/ph.yaml b/ph.yaml index 2fff251a..86a56579 100644 --- a/ph.yaml +++ b/ph.yaml @@ -5,6 +5,8 @@ # - http://www.gov.ph/2014/07/23/list-of-nationwide-holidays-for-2015/ # - http://www.timeanddate.com/holidays/philippines/ --- +region_names: + ph: "Philippines" months: 0: - name: Maundy Thursday diff --git a/pl.yaml b/pl.yaml index 7edc7c91..dc76186c 100644 --- a/pl.yaml +++ b/pl.yaml @@ -3,6 +3,8 @@ # Updated: 2011-09-12. # Source: http://pl.wikipedia.org/wiki/Dni_wolne_od_pracy_w_Polsce --- +region_names: + pl: "Poland" months: 0: - name: Tłusty Czwartek diff --git a/pt.yaml b/pt.yaml index 61faa5ad..f005a821 100644 --- a/pt.yaml +++ b/pt.yaml @@ -13,6 +13,10 @@ # Changes 2017-05-31: # - Add additional holidays for Porto (pt_po) and Lisbon (pt_li) --- +region_names: + pt: "Portugal" + pt_li: "Lisbon" + pt_po: "Porto" months: 0: - name: Carnaval # same as Shrove Tuesday diff --git a/ro.yaml b/ro.yaml index a614ddfc..631915a7 100644 --- a/ro.yaml +++ b/ro.yaml @@ -23,6 +23,8 @@ # - https://www.avocatnet.ro/articol_68582/Zile-libere-2025-Cate-dintre-liberele-legale-de-anul-viitor-vor-pica-in-timpul-s%C4%83pt%C4%83manii.html # - https://www.mediafax.ro/social/calendarul-sarbatorilor-legale-2025-de-cate-zile-libere-se-bucura-angajatii-din-romania-iata-cand-sunt-urmatoarele-zile-libere-pentru-romani-22630313 --- +region_names: + ro: "Romania" months: 0: - name: Paștele - Vinerea Mare # Good Friday diff --git a/rs_cyrl.yaml b/rs_cyrl.yaml index 0e9d97b0..a7593918 100644 --- a/rs_cyrl.yaml +++ b/rs_cyrl.yaml @@ -8,6 +8,8 @@ # - https://www.wko.at/service/aussenwirtschaft/Serbien:-Feiertage-2016.html # - http://www.lexilogos.com/keyboard/serbian_conversion.htm --- +region_names: + rs_cyrl: "Serbia" months: 0: - name: Велики петак # Good Friday diff --git a/rs_la.yaml b/rs_la.yaml index b8630e51..368297b0 100644 --- a/rs_la.yaml +++ b/rs_la.yaml @@ -8,6 +8,8 @@ # - https://www.wko.at/service/aussenwirtschaft/Serbien:-Feiertage-2016.html # - http://www.lexilogos.com/keyboard/serbian_conversion.htm --- +region_names: + rs_la: "Serbia" months: 0: - name: Veliki Petak # Good Friday diff --git a/ru.yaml b/ru.yaml index d370135e..d62ba5d4 100644 --- a/ru.yaml +++ b/ru.yaml @@ -7,6 +7,8 @@ # - https://translate.yandex.com/?lang=en-ru # - https://ru.wikipedia.org/wiki/День_Государственного_флага_Российской_Федерации --- +region_names: + ru: "Russian Federation" months: 1: - name: Новый год # New Year's Day diff --git a/se.yaml b/se.yaml index 33e8e9f8..70bee2d1 100644 --- a/se.yaml +++ b/se.yaml @@ -7,6 +7,8 @@ # - http://hem.passagen.se/farila/midsum.htm # - http://www.timeanddate.com/calendar/?country=21 --- +region_names: + se: "Sweden" months: 0: - name: Långfredagen diff --git a/sg.yaml b/sg.yaml index c1e5b055..378f61f9 100644 --- a/sg.yaml +++ b/sg.yaml @@ -9,6 +9,9 @@ # Source: # http://publicholidays.sg/ +--- +region_names: + sg: "Singapore" months: 0: - name: Good Friday diff --git a/si.yaml b/si.yaml index 2603f1c8..8fc1b07c 100644 --- a/si.yaml +++ b/si.yaml @@ -4,6 +4,9 @@ # Sources: # - http://en.wikipedia.org/wiki/Public_holidays_in_Slovenia +--- +region_names: + si: "Slovenia" months: 0: - name: velikonočna nedelja diff --git a/sk.yaml b/sk.yaml index 0aa1092d..040ca487 100644 --- a/sk.yaml +++ b/sk.yaml @@ -4,6 +4,8 @@ # Sources: # - https://www.vlada.gov.sk/slovensko/statne-sviatky/ --- +region_names: + sk: "Slovakia" months: 0: - name: Veľkonočný pondelok diff --git a/spec/data/valid/simple.yaml b/spec/data/valid/simple.yaml index 3282ceac..07883e5f 100644 --- a/spec/data/valid/simple.yaml +++ b/spec/data/valid/simple.yaml @@ -1,4 +1,6 @@ --- +region_names: + test: "Test Region" months: 1: - name: Test Holiday diff --git a/spec/validation/definition_validator_spec.rb b/spec/validation/definition_validator_spec.rb index 43ae94e5..d2b12cd1 100644 --- a/spec/validation/definition_validator_spec.rb +++ b/spec/validation/definition_validator_spec.rb @@ -2,17 +2,19 @@ require 'validation/definition_validator' describe Definitions::Validation::Definition do + let(:region_names_validator) { double(:region_names_validator, :call => true) } let(:custom_method_validator) { double(:custom_method_validator, :call => true) } let(:months_validator) { double(:months_validator, :call => nil) } let(:test_validator) { double(:test_validator, :call => true) } let(:definition) { { + "region_names" => { "test" => "Test Region" }, "months" => { 1 => [{"name"=>"Test Holiday", "regions"=>["test"], "mday"=>1}] }, "methods" =>{ "test" => {"arguments"=>"year", "source"=>"true"} }, "tests" => "test" } } - subject { described_class.new(custom_method_validator, months_validator, test_validator) } + subject { described_class.new(region_names_validator, custom_method_validator, months_validator, test_validator) } context 'definition is valid' do it 'reports success' do @@ -20,6 +22,13 @@ end end + context 'invalid region_names' do + it 'raises error if region_names validator raises error' do + expect(region_names_validator).to receive(:call).with(definition['region_names'], definition['months']).and_raise(StandardError) + expect { subject.call(definition) }.to raise_error(StandardError) + end + end + context 'invalid months' do it 'raises error if months validator raises error' do expect(months_validator).to receive(:call).with(definition['months']).and_raise(StandardError) diff --git a/spec/validation/region_names_validator_spec.rb b/spec/validation/region_names_validator_spec.rb new file mode 100644 index 00000000..5cff051e --- /dev/null +++ b/spec/validation/region_names_validator_spec.rb @@ -0,0 +1,97 @@ +require 'spec_helper' +require 'validation/region_names_validator' + +describe Definitions::Validation::RegionNames do + let(:iso_names) { {} } + subject { described_class.new(iso_names) } + + let(:months) { { 1 => [{"name" => "Test Holiday", "regions" => ["us"], "mday" => 1}] } } + let(:region_names) { { "us" => "United States" } } + + context 'valid' do + it 'returns true when region_names matches regions in months' do + expect(subject.call(region_names, months)).to be true + end + + it 'returns true with multiple regions across multiple months' do + months = { + 1 => [{"name" => "Holiday A", "regions" => ["us", "ca"], "mday" => 1}], + 7 => [{"name" => "Holiday B", "regions" => ["ca"], "mday" => 1}], + } + region_names = { "us" => "United States", "ca" => "Canada" } + expect(subject.call(region_names, months)).to be true + end + + it 'returns true when ISO name matches the injected lookup' do + iso_names = { "gb" => "United Kingdom" } + months = { 1 => [{"name" => "Holiday", "regions" => ["gb"], "mday" => 1}] } + region_names = { "gb" => "United Kingdom" } + expect(described_class.new(iso_names).call(region_names, months)).to be true + end + + it 'skips ISO validation for regions not in the lookup' do + iso_names = {} + months = { 1 => [{"name" => "Holiday", "regions" => ["nyse"], "mday" => 1}] } + region_names = { "nyse" => "New York Stock Exchange" } + expect(described_class.new(iso_names).call(region_names, months)).to be true + end + + it 'skips ISO validation for regions in NON_ISO_REGIONS' do + iso_names = { "vi" => "Virgin Islands (U.S.)" } + months = { 1 => [{"name" => "Holiday", "regions" => ["vi"], "mday" => 1}] } + region_names = { "vi" => "Viet Nam" } + expect(described_class.new(iso_names).call(region_names, months)).to be true + end + + it 'validates subdivision names correctly' do + iso_names = { "de_by" => "Bayern" } + months = { 1 => [{"name" => "Holiday", "regions" => ["de_by"], "mday" => 1}] } + region_names = { "de_by" => "Bayern" } + expect(described_class.new(iso_names).call(region_names, months)).to be true + end + end + + context 'invalid' do + it 'raises error if region_names is nil' do + expect { subject.call(nil, months) }.to raise_error(Definitions::Errors::InvalidRegionNames) { |e| + expect(e.message).to eq("region_names is required") + } + end + + it 'raises error if region_names is not a hash' do + expect { subject.call("bad", months) }.to raise_error(Definitions::Errors::InvalidRegionNames) { |e| + expect(e.message).to eq("region_names must be a hash, received: 'bad'") + } + end + + it 'raises error if region_names is empty' do + expect { subject.call({}, months) }.to raise_error(Definitions::Errors::InvalidRegionNames) { |e| + expect(e.message).to eq("region_names must not be empty") + } + end + + it 'raises error if a region in months is missing from region_names' do + months = { 1 => [{"name" => "Holiday", "regions" => ["us", "ca"], "mday" => 1}] } + expect { subject.call(region_names, months) }.to raise_error(Definitions::Errors::InvalidRegionNames) { |e| + expect(e.message).to eq("region_names is missing entries for regions: ca") + } + end + + it 'raises error if region_names contains a region not in months' do + region_names = { "us" => "United States", "ca" => "Canada" } + expect { subject.call(region_names, months) }.to raise_error(Definitions::Errors::InvalidRegionNames) { |e| + expect(e.message).to eq("region_names has entries for regions not found in months: ca") + } + end + + it 'raises error if a name does not match the ISO lookup' do + iso_names = { "gb" => "United Kingdom" } + months = { 1 => [{"name" => "Holiday", "regions" => ["gb"], "mday" => 1}] } + region_names = { "gb" => "Great Britain" } + expect { described_class.new(iso_names).call(region_names, months) }.to raise_error(Definitions::Errors::InvalidRegionNames) { |e| + expect(e.message).to include("gb: expected 'United Kingdom' but got 'Great Britain'") + expect(e.message).to include("See doc/SYNTAX.md for naming conventions.") + } + end + end +end diff --git a/th.yaml b/th.yaml index c7bb7a36..3e26efaa 100644 --- a/th.yaml +++ b/th.yaml @@ -4,6 +4,8 @@ # Sources: # - https://en.wikipedia.org/wiki/Public_holidays_in_Thailand --- +region_names: + th: "Thailand" months: 1: - name: วันขึ้นปีใหม่ diff --git a/tn.yaml b/tn.yaml index b192148f..0fd3e0a6 100644 --- a/tn.yaml +++ b/tn.yaml @@ -7,6 +7,8 @@ # - https://fr.wikipedia.org/wiki/Fêtes_et_jours_fériés_en_Tunisie#F.C3.AAtes_officielles # --- +region_names: + tn: "Tunisia" months: 1: - name: Jour de l'an diff --git a/tr.yaml b/tr.yaml index e5e0e96f..816b0fc7 100644 --- a/tr.yaml +++ b/tr.yaml @@ -16,6 +16,8 @@ # - https://de.wikibooks.org/wiki/Türkisch:_Zahlen # - https://en.wikipedia.org/wiki/Democracy_and_National_Unity_Day --- +region_names: + tr: "Türkiye" months: 0: - name: Ramazan Bayramı # Ramadan Feast diff --git a/tsx.yaml b/tsx.yaml index ea98d6a5..13722d78 100644 --- a/tsx.yaml +++ b/tsx.yaml @@ -2,6 +2,8 @@ # # Source: https://www.tsx.com/trading/calendars-and-trading-hours/calendar --- +region_names: + tsx: "Toronto Stock Exchange" months: 0: - name: Good Friday diff --git a/ua.yaml b/ua.yaml index 1a14e5b0..2f49d9a5 100644 --- a/ua.yaml +++ b/ua.yaml @@ -5,6 +5,8 @@ # - https://en.wikipedia.org/wiki/Public_holidays_in_Ukraine # - https://uk.wikipedia.org/wiki/%D0%9D%D0%B5%D1%80%D0%BE%D0%B1%D0%BE%D1%87%D1%96_%D0%B4%D0%BD%D1%96_%D0%B2_%D0%A3%D0%BA%D1%80%D0%B0%D1%97%D0%BD%D1%96 --- +region_names: + ua: "Ukraine" months: 0: - name: Великдень # Easter Sunday diff --git a/unitednations.yaml b/unitednations.yaml index 43291472..84b792e6 100644 --- a/unitednations.yaml +++ b/unitednations.yaml @@ -1,6 +1,8 @@ # United Nationas holiday definitions for the Ruby Holiday gem. # Updated 2008-11-21. --- +region_names: + unitednations: "United Nations" months: 2: - name: International Mother Language Day diff --git a/ups.yaml b/ups.yaml index 8c8c3285..cb1a437c 100644 --- a/ups.yaml +++ b/ups.yaml @@ -5,6 +5,8 @@ # Updated: 2025-01-21. # Source: https://www.ups.com/us/en/support/shipping-support/shipping-services/holiday-shipping-schedule.page --- +region_names: + ups: "UPS" months: 1: - name: New Year's Day diff --git a/us.yaml b/us.yaml index 8341898b..70a33fa6 100644 --- a/us.yaml +++ b/us.yaml @@ -66,7 +66,62 @@ # - https://publicholidays.us/independence-day/ --- - +region_names: + us: "United States" + us_ak: "Alaska" + us_al: "Alabama" + us_ar: "Arkansas" + us_az: "Arizona" + us_ca: "California" + us_co: "Colorado" + us_ct: "Connecticut" + us_dc: "District of Columbia" + us_de: "Delaware" + us_fl: "Florida" + us_ga: "Georgia" + us_gu: "Guam" + us_hi: "Hawaii" + us_ia: "Iowa" + us_id: "Idaho" + us_il: "Illinois" + us_in: "Indiana" + us_ks: "Kansas" + us_ky: "Kentucky" + us_la: "Louisiana" + us_ma: "Massachusetts" + us_md: "Maryland" + us_me: "Maine" + us_mi: "Michigan" + us_mn: "Minnesota" + us_mo: "Missouri" + us_ms: "Mississippi" + us_mt: "Montana" + us_nc: "North Carolina" + us_nd: "North Dakota" + us_ne: "Nebraska" + us_nh: "New Hampshire" + us_nj: "New Jersey" + us_nm: "New Mexico" + us_nv: "Nevada" + us_ny: "New York" + us_oh: "Ohio" + us_ok: "Oklahoma" + us_or: "Oregon" + us_pa: "Pennsylvania" + us_pr: "Puerto Rico" + us_ri: "Rhode Island" + us_sc: "South Carolina" + us_sd: "South Dakota" + us_tn: "Tennessee" + us_tx: "Texas" + us_ut: "Utah" + us_va: "Virginia" + us_vi: "Virgin Islands, U.S." + us_vt: "Vermont" + us_wa: "Washington" + us_wi: "Wisconsin" + us_wv: "West Virginia" + us_wy: "Wyoming" months: 0: - name: Shrove Tuesday diff --git a/ve.yaml b/ve.yaml index 18268821..76df1074 100644 --- a/ve.yaml +++ b/ve.yaml @@ -5,6 +5,8 @@ # Updated: 2012-09-14. # Source: http://venciclopedia.com/index.php?title=D%C3%ADas_feriados_de_Venezuela --- +region_names: + ve: "Venezuela" months: 0: - name: Lunes Carnaval diff --git a/vi.yaml b/vi.yaml index d3f88538..ab7212f3 100644 --- a/vi.yaml +++ b/vi.yaml @@ -3,6 +3,8 @@ # Updated: 2014-07-17. # Source: http://en.wikipedia.org/wiki/Public_holidays_in_Vietnam --- +region_names: + vi: "Viet Nam" months: 1: - name: Tết dương lịch diff --git a/za.yaml b/za.yaml index f351d453..ce3340c3 100644 --- a/za.yaml +++ b/za.yaml @@ -5,6 +5,8 @@ # - http://en.wikipedia.org/wiki/Public_holidays_in_South_Africa # - http://www.info.gov.za/aboutsa/holidays.htm --- +region_names: + za: "South Africa" months: 0: - name: Good Friday