Skip to content

A platform for community discussion. Free, open, simple.

6.1 KB
Raw Blame
# Chilean holiday definitions for the Ruby Holiday gem.
#
# Updated: 2019-02-10
#
# Sources:
# - http://www.feriados.cl
# - http://www.feriadoschilenos.cl
#
---
months:
  0:
  - name: Viernes Santo
    regions: [cl]
    function: easter(year)
    function_modifier: -2
  - name: Sábado Santo
    regions: [cl]
    function: easter(year)
    function_modifier: -1
  - name: San Pedro y San Pablo
    regions: [cl]
    function: st_peter_st_paul_cl(year)
    year_ranges:
      from: 2000
  - name: Día de las Iglesias Evangélicas y Protestantes
    regions: [cl]
    function: other_churches_day_cl(year)
    year_ranges:
      from: 2008
  1:
  - name: Año Nuevo
    regions: [cl]
    mday: 1
  5:
  - name: Día del Trabajo
    regions: [cl]
    mday: 1
  - name: Día de las Glorias Navales
    regions: [cl]
    mday: 21
  6:
  - name: San Pedro y San Pablo
    regions: [cl]
    mday: 29
    year_ranges:
      until: 1999
  7:
  - name: Día de la Virgen del Carmen
    regions: [cl]
    mday: 16
  8:
  - name: Asunción de la Virgen
    regions: [cl]
    mday: 15
  9:
  - name: Independencia Nacional
    regions: [cl]
    mday: 18
  - name: Día de las Glorias del Ejército
    regions: [cl]
    mday: 19
  10:
  - name: Encuentro de Dos Mundos
    regions: [cl]
    mday: 12
    year_ranges:
      until: 1999
  - name: Encuentro de Dos Mundos
    regions: [cl]
    year_ranges:
      from: 2000
    function: columbus_day_cl(year)
  11:
  - name: Día de Todos los Santos
    regions: [cl]
    mday: 1
  12:
  - name: Inmaculada Concepción de María
    regions: [cl]
    mday: 8
  - name: Navidad
    regions: [cl]
    mday: 25

methods:
  st_peter_st_paul_cl:
    arguments: year
    # Nearest monday
    ruby: |
      date = Date.civil(year, 6, 29)
      if [2,3,4].include?(date.wday)
        date -= (date.wday - 1)
      elsif date.wday == 5
        date += 3
      end
      date
  columbus_day_cl:
    arguments: year
    # Nearest monday
    ruby: |
      date = Date.civil(year, 10, 12)
      if [2,3,4].include?(date.wday)
        date -= (date.wday - 1)
      elsif date.wday == 5
        date += 3
      end
      date
  other_churches_day_cl:
    arguments: year
    # If on tuesday, friday before, if on wednesday, next friday
    ruby: |
      date = Date.civil(year, 10, 31)
      if date.wday == 2
        date -= 4
      elsif date.wday == 3
        date += 2
      end
      date

tests:
  - given:
      date: '2014-01-01'
      regions: ["cl"]
      options: ["informal"]
    expect:
      name: "Año Nuevo"
  - given:
      date: '2011-04-22'
      regions: ["cl"]
      options: ["informal"]
    expect:
      name: "Viernes Santo"
  - given:
      date: '2011-04-23'
      regions: ["cl"]
      options: ["informal"]
    expect:
      name: "Sábado Santo"
  - given:
      date: '2012-04-06'
      regions: ["cl"]
      options: ["informal"]
    expect:
      name: "Viernes Santo"
  - given:
      date: '2012-04-07'
      regions: ["cl"]
      options: ["informal"]
    expect:
      name: "Sábado Santo"
  - given:
      date: '2013-03-29'
      regions: ["cl"]
      options: ["informal"]
    expect:
      name: "Viernes Santo"
  - given:
      date: '2013-03-30'
      regions: ["cl"]
      options: ["informal"]
    expect:
      name: "Sábado Santo"
  - given:
      date: '2014-04-18'
      regions: ["cl"]
      options: ["informal"]
    expect:
      name: "Viernes Santo"
  - given:
      date: '2014-04-19'
      regions: ["cl"]
      options: ["informal"]
    expect:
      name: "Sábado Santo"
  - given:
      date: '2015-04-03'
      regions: ["cl"]
      options: ["informal"]
    expect:
      name: "Viernes Santo"
  - given:
      date: '2015-04-04'
      regions: ["cl"]
      options: ["informal"]
    expect:
      name: "Sábado Santo"
  - given:
      date: '2016-03-25'
      regions: ["cl"]
      options: ["informal"]
    expect:
      name: "Viernes Santo"
  - given:
      date: '2016-03-26'
      regions: ["cl"]
      options: ["informal"]
    expect:
      name: "Sábado Santo"
  - given:
      date: '2014-05-01'
      regions: ["cl"]
      options: ["informal"]
    expect:
      name: "Día del Trabajo"
  - given:
      date: '2014-05-21'
      regions: ["cl"]
      options: ["informal"]
    expect:
      name: "Día de las Glorias Navales"
  - given:
      date: '1999-06-29'
      regions: ["cl"]
      options: ["informal"]
    expect:
      name: "San Pedro y San Pablo"
  - given:
      date: '2000-06-26'
      regions: ["cl"]
      options: ["informal"]
    expect:
      name: "San Pedro y San Pablo"
  - given:
      date: '2017-06-26'
      regions: ["cl"]
      options: ["informal"]
    expect:
      name: "San Pedro y San Pablo"
  - given:
      date: '2018-07-2'
      regions: ["cl"]
      options: ["informal"]
    expect:
      name: "San Pedro y San Pablo"
  - given:
      date: '2014-07-16'
      regions: ["cl"]
      options: ["informal"]
    expect:
      name: "Día de la Virgen del Carmen"
  - given:
      date: '2014-08-15'
      regions: ["cl"]
      options: ["informal"]
    expect:
      name: "Asunción de la Virgen"
  - given:
      date: '2014-09-18'
      regions: ["cl"]
      options: ["informal"]
    expect:
      name: "Independencia Nacional"
  - given:
      date: '2014-09-19'
      regions: ["cl"]
      options: ["informal"]
    expect:
      name: "Día de las Glorias del Ejército"
  - given:
      date: '1999-10-12'
      regions: ["cl"]
      options: ["informal"]
    expect:
      name: "Encuentro de Dos Mundos"
  - given:
      date: '2017-10-9'
      regions: ["cl"]
      options: ["informal"]
    expect:
      name: "Encuentro de Dos Mundos"
  - given:
      date: '2017-10-27'
      regions: ["cl"]
      options: ["informal"]
    expect:
      name: "Día de las Iglesias Evangélicas y Protestantes"
  - given:
      date: '2014-11-01'
      regions: ["cl"]
      options: ["informal"]
    expect:
      name: "Día de Todos los Santos"
  - given:
      date: '2014-12-08'
      regions: ["cl"]
      options: ["informal"]
    expect:
      name: "Inmaculada Concepción de María"
  - given:
      date: '2014-12-25'
      regions: ["cl"]
      options: ["informal"]
    expect:
      name: "Navidad"