Module: Holidays
- Defined in:
- lib/holidays/definition/context/generator.rb,
lib/holidays.rb,
lib/holidays/errors.rb,
lib/holidays/version.rb,
lib/holidays/factory/finder.rb,
lib/generated_definitions/ar.rb,
lib/generated_definitions/at.rb,
lib/generated_definitions/au.rb,
lib/generated_definitions/be.rb,
lib/generated_definitions/bg.rb,
lib/generated_definitions/br.rb,
lib/generated_definitions/ca.rb,
lib/generated_definitions/ch.rb,
lib/generated_definitions/cl.rb,
lib/generated_definitions/co.rb,
lib/generated_definitions/cr.rb,
lib/generated_definitions/cz.rb,
lib/generated_definitions/de.rb,
lib/generated_definitions/dk.rb,
lib/generated_definitions/ee.rb,
lib/generated_definitions/el.rb,
lib/generated_definitions/es.rb,
lib/generated_definitions/fi.rb,
lib/generated_definitions/fr.rb,
lib/generated_definitions/gb.rb,
lib/generated_definitions/ge.rb,
lib/generated_definitions/gr.rb,
lib/generated_definitions/hk.rb,
lib/generated_definitions/hr.rb,
lib/generated_definitions/hu.rb,
lib/generated_definitions/ie.rb,
lib/generated_definitions/is.rb,
lib/generated_definitions/it.rb,
lib/generated_definitions/jp.rb,
lib/generated_definitions/ke.rb,
lib/generated_definitions/kr.rb,
lib/generated_definitions/kz.rb,
lib/generated_definitions/li.rb,
lib/generated_definitions/lt.rb,
lib/generated_definitions/lu.rb,
lib/generated_definitions/lv.rb,
lib/generated_definitions/ma.rb,
lib/generated_definitions/mx.rb,
lib/generated_definitions/my.rb,
lib/generated_definitions/ng.rb,
lib/generated_definitions/nl.rb,
lib/generated_definitions/no.rb,
lib/generated_definitions/nz.rb,
lib/generated_definitions/pe.rb,
lib/generated_definitions/ph.rb,
lib/generated_definitions/pl.rb,
lib/generated_definitions/pt.rb,
lib/generated_definitions/ro.rb,
lib/generated_definitions/ru.rb,
lib/generated_definitions/se.rb,
lib/generated_definitions/sg.rb,
lib/generated_definitions/si.rb,
lib/generated_definitions/sk.rb,
lib/generated_definitions/th.rb,
lib/generated_definitions/tn.rb,
lib/generated_definitions/tr.rb,
lib/generated_definitions/ua.rb,
lib/generated_definitions/us.rb,
lib/generated_definitions/ve.rb,
lib/generated_definitions/vi.rb,
lib/generated_definitions/za.rb,
lib/generated_definitions/ups.rb,
lib/generated_definitions/nerc.rb,
lib/generated_definitions/nyse.rb,
lib/generated_definitions/be_fr.rb,
lib/generated_definitions/be_nl.rb,
lib/generated_definitions/fedex.rb,
lib/generated_definitions/mt_en.rb,
lib/generated_definitions/mt_mt.rb,
lib/generated_definitions/rs_la.rb,
lib/holidays/factory/definition.rb,
lib/generated_definitions/europe.rb,
lib/generated_definitions/REGIONS.rb,
lib/generated_definitions/rs_cyrl.rb,
lib/holidays/core_extensions/date.rb,
lib/holidays/core_extensions/time.rb,
lib/holidays/load_all_definitions.rb,
lib/holidays/finder/context/search.rb,
lib/generated_definitions/ecbtarget.rb,
lib/holidays/date_calculator/easter.rb,
lib/holidays/definition/entity/test.rb,
lib/holidays/definition/parser/test.rb,
lib/holidays/finder/context/between.rb,
lib/holidays/finder/rules/in_region.rb,
lib/holidays/definition/context/load.rb,
lib/holidays/factory/date_calculator.rb,
lib/holidays/finder/rules/year_range.rb,
lib/generated_definitions/scandinavia.rb,
lib/generated_definitions/northamerica.rb,
lib/generated_definitions/southamerica.rb,
lib/holidays/definition/context/merger.rb,
lib/holidays/definition/decorator/test.rb,
lib/holidays/definition/generator/test.rb,
lib/holidays/definition/validator/test.rb,
lib/generated_definitions/unitednations.rb,
lib/holidays/date_calculator/lunar_date.rb,
lib/generated_definitions/federalreserve.rb,
lib/holidays/definition/generator/module.rb,
lib/holidays/definition/repository/cache.rb,
lib/holidays/definition/validator/region.rb,
lib/holidays/finder/context/next_holiday.rb,
lib/holidays/finder/context/year_holiday.rb,
lib/holidays/date_calculator/day_of_month.rb,
lib/holidays/definition/generator/regions.rb,
lib/holidays/finder/context/parse_options.rb,
lib/holidays/definition/repository/regions.rb,
lib/holidays/definition/entity/custom_method.rb,
lib/holidays/definition/parser/custom_method.rb,
lib/generated_definitions/federalreservebanks.rb,
lib/holidays/date_calculator/weekend_modifier.rb,
lib/holidays/definition/validator/custom_method.rb,
lib/holidays/finder/context/dates_driver_builder.rb,
lib/holidays/definition/repository/custom_methods.rb,
lib/holidays/definition/context/function_processor.rb,
lib/holidays/definition/decorator/custom_method_proc.rb,
lib/holidays/definition/repository/holidays_by_month.rb,
lib/holidays/definition/repository/proc_result_cache.rb,
lib/holidays/definition/decorator/custom_method_source.rb
Overview
This context builds a hash that contains => [<array of months>]. The idea is that we will iterate over each year and then over each month internally and check to see if the supplied dates match any holidays for the region and date. So if we supply start_date of 2015/1/1 and end_date of 2015/6/1 then we will return a date driver of => [0, 1, 2, 5, 6, 7]. In the logic in the various other ‘finder’ contexts we will iterate over this and compare dates in these months to the supplied range to determine whether they should be returned to the user.
Defined Under Namespace
Modules: AR, AT, AU, BE, BE_FR, BE_NL, BG, BR, CA, CH, CL, CO, CR, CZ, CoreExtensions, DE, DK, DateCalculator, Definition, ECBTARGET, EE, EL, ES, EUROPE, FEDERALRESERVE, FEDERALRESERVEBANKS, FEDEX, FI, FR, Factory, Finder, GB, GE, GR, HK, HR, HU, IE, IS, IT, JP, KE, KR, KZ, LI, LT, LU, LV, MA, MT_EN, MT_MT, MX, MY, NERC, NG, NL, NO, NORTHAMERICA, NYSE, NZ, PE, PH, PL, PT, RO, RS_CYRL, RS_LA, RU, SCANDINAVIA, SE, SG, SI, SK, SOUTHAMERICA, TH, TN, TR, UA, UNITEDNATIONS, UPS, US, VE, VI, ZA Classes: DefinitionTestError, Error, FunctionNotFound, InvalidFunctionResponse, InvalidRegion, LoadAllDefinitions, UnknownRegionError
Constant Summary collapse
- WEEKS =
{:first => 1, :second => 2, :third => 3, :fourth => 4, :fifth => 5, :last => -1, :second_last => -2, :third_last => -3}
- MONTH_LENGTHS =
[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
- DAY_SYMBOLS =
Date::DAYNAMES.collect { |n| n.downcase.intern }
- DEFINITIONS_PATH =
'generated_definitions'
- FULL_DEFINITIONS_PATH =
File.(File.dirname(__FILE__) + "/#{DEFINITIONS_PATH}")
- VERSION =
'8.8.0'
- REGIONS =
[:ar, :at, :au, :au_nsw, :au_vic, :au_qld, :au_nt, :au_act, :au_sa, :au_wa, :au_tas, :au_tas_south, :au_qld_cairns, :au_qld_brisbane, :au_tas_north, :au_vic_melbourne, :be_fr, :be_nl, :br, :bg_en, :bg_bg, :ca, :ca_qc, :ca_ab, :ca_sk, :ca_on, :ca_bc, :ca_nb, :ca_mb, :ca_ns, :ca_pe, :ca_nl, :ca_nt, :ca_nu, :ca_yt, :us, :ch_zh, :ch_be, :ch_lu, :ch_ur, :ch_sz, :ch_ow, :ch_nw, :ch_gl, :ch_zg, :ch_fr, :ch_so, :ch_bs, :ch_bl, :ch_sh, :ch_ar, :ch_ai, :ch_sg, :ch_gr, :ch_ag, :ch_tg, :ch_ti, :ch_vd, :ch_ne, :ch_ge, :ch_ju, :ch_vs, :ch, :cl, :co, :cr, :cz, :dk, :de, :de_bw, :de_by, :de_he, :de_nw, :de_rp, :de_sl, :de_sn_sorbian, :de_th_cath, :de_sn, :de_st, :de_be, :de_mv, :de_by_cath, :de_by_augsburg, :de_th, :de_bb, :de_hb, :de_hh, :de_ni, :de_sh, :ecbtarget, :ee, :es_pv, :es_na, :es_an, :es_ib, :es_cm, :es_mu, :es_m, :es_ar, :es_cl, :es_cn, :es_lo, :es_ga, :es_ce, :es_o, :es_ex, :es, :es_ct, :es_v, :es_vc, :federalreserve, :federalreservebanks, :fedex, :fi, :fr_a, :fr_m, :fr, :gb, :gb_eng, :gb_wls, :gb_eaw, :gb_nir, :je, :gb_jsy, :gg, :gb_gsy, :gb_sct, :gb_con, :im, :gb_iom, :ge, :gr, :hr, :hk, :hu, :ie, :is, :it, :it_ve, :it_tv, :it_vr, :it_pd, :it_fi, :it_ge, :it_to, :it_rm, :it_vi, :it_bl, :it_ro, :ke, :kr, :kz, :li, :lt, :lv, :ma, :mt_mt, :mt_en, :mx, :mx_pue, :nerc, :nl, :lu, :no, :nyse, :nz, :nz_sl, :nz_we, :nz_ak, :nz_nl, :nz_ne, :nz_ot, :nz_ta, :nz_sc, :nz_hb, :nz_mb, :nz_ca, :nz_ch, :nz_wl, :pe, :ph, :pl, :pt, :pt_li, :pt_po, :ro, :rs_cyrl, :rs_la, :ru, :se, :tn, :tr, :ua, :us_fl, :us_la, :us_ct, :us_de, :us_gu, :us_hi, :us_in, :us_ky, :us_nj, :us_nc, :us_nd, :us_pr, :us_tn, :us_ms, :us_id, :us_ar, :us_tx, :us_dc, :us_md, :us_va, :us_vt, :us_ak, :us_ca, :us_me, :us_ma, :us_al, :us_ga, :us_ne, :us_mo, :us_sc, :us_wv, :us_vi, :us_ut, :us_ri, :us_az, :us_co, :us_il, :us_mt, :us_nm, :us_ny, :us_oh, :us_pa, :us_mi, :us_mn, :us_nv, :us_or, :us_sd, :us_wa, :us_wi, :us_wy, :us_ia, :us_ks, :us_nh, :us_ok, :unitednations, :ups, :za, :ve, :sk, :si, :jp, :vi, :sg, :my, :th, :ng]
- PARENT_REGION_LOOKUP =
{:ar=>:ar, :at=>:at, :au=>:au, :au_nsw=>:au, :au_vic=>:au, :au_qld=>:au, :au_nt=>:au, :au_act=>:au, :au_sa=>:au, :au_wa=>:au, :au_tas=>:au, :au_tas_south=>:au, :au_qld_cairns=>:au, :au_qld_brisbane=>:au, :au_tas_north=>:au, :au_vic_melbourne=>:au, :be_fr=>:be_fr, :be_nl=>:be_nl, :br=>:br, :bg_en=>:bg, :bg_bg=>:bg, :ca=>:ca, :ca_qc=>:ca, :ca_ab=>:ca, :ca_sk=>:ca, :ca_on=>:ca, :ca_bc=>:ca, :ca_nb=>:ca, :ca_mb=>:ca, :ca_ns=>:ca, :ca_pe=>:ca, :ca_nl=>:ca, :ca_nt=>:ca, :ca_nu=>:ca, :ca_yt=>:ca, :us=>:us, :ch_zh=>:ch, :ch_be=>:ch, :ch_lu=>:ch, :ch_ur=>:ch, :ch_sz=>:ch, :ch_ow=>:ch, :ch_nw=>:ch, :ch_gl=>:ch, :ch_zg=>:ch, :ch_fr=>:ch, :ch_so=>:ch, :ch_bs=>:ch, :ch_bl=>:ch, :ch_sh=>:ch, :ch_ar=>:ch, :ch_ai=>:ch, :ch_sg=>:ch, :ch_gr=>:ch, :ch_ag=>:ch, :ch_tg=>:ch, :ch_ti=>:ch, :ch_vd=>:ch, :ch_ne=>:ch, :ch_ge=>:ch, :ch_ju=>:ch, :ch_vs=>:ch, :ch=>:ch, :cl=>:cl, :co=>:co, :cr=>:cr, :cz=>:cz, :dk=>:dk, :de=>:de, :de_bw=>:de, :de_by=>:de, :de_he=>:de, :de_nw=>:de, :de_rp=>:de, :de_sl=>:de, :de_sn_sorbian=>:de, :de_th_cath=>:de, :de_sn=>:de, :de_st=>:de, :de_be=>:de, :de_mv=>:de, :de_by_cath=>:de, :de_by_augsburg=>:de, :de_th=>:de, :de_bb=>:de, :de_hb=>:de, :de_hh=>:de, :de_ni=>:de, :de_sh=>:de, :ecbtarget=>:ecbtarget, :ee=>:ee, :es_pv=>:es, :es_na=>:es, :es_an=>:es, :es_ib=>:es, :es_cm=>:es, :es_mu=>:es, :es_m=>:es, :es_ar=>:es, :es_cl=>:es, :es_cn=>:es, :es_lo=>:es, :es_ga=>:es, :es_ce=>:es, :es_o=>:es, :es_ex=>:es, :es=>:es, :es_ct=>:es, :es_v=>:es, :es_vc=>:es, :federalreserve=>:federalreserve, :federalreservebanks=>:federalreservebanks, :fedex=>:fedex, :fi=>:fi, :fr_a=>:fr, :fr_m=>:fr, :fr=>:fr, :gb=>:gb, :gb_eng=>:gb, :gb_wls=>:gb, :gb_eaw=>:gb, :gb_nir=>:gb, :je=>:gb, :gb_jsy=>:gb, :gg=>:gb, :gb_gsy=>:gb, :gb_sct=>:gb, :gb_con=>:gb, :im=>:gb, :gb_iom=>:gb, :ge=>:ge, :gr=>:gr, :hr=>:hr, :hk=>:hk, :hu=>:hu, :ie=>:ie, :is=>:is, :it=>:it, :it_ve=>:it, :it_tv=>:it, :it_vr=>:it, :it_pd=>:it, :it_fi=>:it, :it_ge=>:it, :it_to=>:it, :it_rm=>:it, :it_vi=>:it, :it_bl=>:it, :it_ro=>:it, :ke=>:ke, :kr=>:kr, :kz=>:kz, :li=>:li, :lt=>:lt, :lv=>:lv, :ma=>:ma, :mt_mt=>:mt_mt, :mt_en=>:mt_en, :mx=>:mx, :mx_pue=>:mx, :nerc=>:nerc, :nl=>:nl, :lu=>:lu, :no=>:no, :nyse=>:nyse, :nz=>:nz, :nz_sl=>:nz, :nz_we=>:nz, :nz_ak=>:nz, :nz_nl=>:nz, :nz_ne=>:nz, :nz_ot=>:nz, :nz_ta=>:nz, :nz_sc=>:nz, :nz_hb=>:nz, :nz_mb=>:nz, :nz_ca=>:nz, :nz_ch=>:nz, :nz_wl=>:nz, :pe=>:pe, :ph=>:ph, :pl=>:pl, :pt=>:pt, :pt_li=>:pt, :pt_po=>:pt, :ro=>:ro, :rs_cyrl=>:rs_cyrl, :rs_la=>:rs_la, :ru=>:ru, :se=>:se, :tn=>:tn, :tr=>:tr, :ua=>:ua, :us_fl=>:us, :us_la=>:us, :us_ct=>:us, :us_de=>:us, :us_gu=>:us, :us_hi=>:us, :us_in=>:us, :us_ky=>:us, :us_nj=>:us, :us_nc=>:us, :us_nd=>:us, :us_pr=>:us, :us_tn=>:us, :us_ms=>:us, :us_id=>:us, :us_ar=>:us, :us_tx=>:us, :us_dc=>:us, :us_md=>:us, :us_va=>:us, :us_vt=>:us, :us_ak=>:us, :us_ca=>:us, :us_me=>:us, :us_ma=>:us, :us_al=>:us, :us_ga=>:us, :us_ne=>:us, :us_mo=>:us, :us_sc=>:us, :us_wv=>:us, :us_vi=>:us, :us_ut=>:us, :us_ri=>:us, :us_az=>:us, :us_co=>:us, :us_il=>:us, :us_mt=>:us, :us_nm=>:us, :us_ny=>:us, :us_oh=>:us, :us_pa=>:us, :us_mi=>:us, :us_mn=>:us, :us_nv=>:us, :us_or=>:us, :us_sd=>:us, :us_wa=>:us, :us_wi=>:us, :us_wy=>:us, :us_ia=>:us, :us_ks=>:us, :us_nh=>:us, :us_ok=>:us, :unitednations=>:unitednations, :ups=>:ups, :za=>:za, :ve=>:southamerica, :sk=>:europe, :si=>:europe, :jp=>:jp, :vi=>:vi, :sg=>:sg, :my=>:my, :th=>:th, :ng=>:ng}
Class Method Summary collapse
- .any_holidays_during_work_week?(date, *options) ⇒ Boolean
- .available_regions ⇒ Object
- .between(start_date, end_date, *options) ⇒ Object
- .cache_between(start_date, end_date, *options) ⇒ Object
- .load_all ⇒ Object
- .load_custom(*files) ⇒ Object
-
.next_holidays(holidays_count, options, from_date = Date.today) ⇒ Object
FIXME All other methods start with a date and require a date.
- .on(date, *options) ⇒ Object
-
.year_holidays(options, from_date = Date.today) ⇒ Object
FIXME All other methods start with a date and require a date.
Class Method Details
.any_holidays_during_work_week?(date, *options) ⇒ Boolean
21 22 23 24 25 26 27 28 |
# File 'lib/holidays.rb', line 21 def any_holidays_during_work_week?(date, *) monday = date - (date.wday - 1) friday = date + (5 - date.wday) holidays = between(monday, friday, *) holidays && holidays.count > 0 end |
.available_regions ⇒ Object
89 90 91 |
# File 'lib/holidays.rb', line 89 def available_regions Holidays::REGIONS end |
.between(start_date, end_date, *options) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/holidays.rb', line 34 def between(start_date, end_date, *) raise ArgumentError unless start_date && end_date # remove the timezone start_date = start_date.new_offset(0) + start_date.offset if start_date.respond_to?(:new_offset) end_date = end_date.new_offset(0) + end_date.offset if end_date.respond_to?(:new_offset) start_date, end_date = get_date(start_date), get_date(end_date) raise ArgumentError if end_date < start_date if cached_holidays = Factory::Definition.cache_repository.find(start_date, end_date, ) return cached_holidays end Factory::Finder.between.call(start_date, end_date, ) end |
.cache_between(start_date, end_date, *options) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/holidays.rb', line 82 def cache_between(start_date, end_date, *) start_date, end_date = get_date(start_date), get_date(end_date) cache_data = between(start_date, end_date, *) Factory::Definition.cache_repository.cache_between(start_date, end_date, cache_data, ) end |
.load_all ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/holidays.rb', line 105 def load_all path = FULL_DEFINITIONS_PATH + "/" Dir.foreach(path) do |item| next if item == '.' or item == '..' target = path+item next if File.extname(target) != '.rb' require target end end |
.load_custom(*files) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/holidays.rb', line 93 def load_custom(*files) regions, rules_by_month, custom_methods, _ = Factory::Definition.file_parser.parse_definition_files(files) custom_methods.each do |method_key, method_entity| custom_methods[method_key] = Factory::Definition.custom_method_proc_decorator.call(method_entity) end Factory::Definition.merger.call(regions, rules_by_month, custom_methods) rules_by_month end |
.next_holidays(holidays_count, options, from_date = Date.today) ⇒ Object
FIXME All other methods start with a date and require a date. For the next
major version bump we should take the opportunity to change this
signature to match, e.g. next_holidays(from_date, count, )
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/holidays.rb', line 55 def next_holidays(holidays_count, , from_date = Date.today) raise ArgumentError unless holidays_count raise ArgumentError if .empty? raise ArgumentError unless .is_a?(Array) # remove the timezone from_date = from_date.new_offset(0) + from_date.offset if from_date.respond_to?(:new_offset) from_date = get_date(from_date) Factory::Finder.next_holiday.call(holidays_count, from_date, ) end |
.on(date, *options) ⇒ Object
30 31 32 |
# File 'lib/holidays.rb', line 30 def on(date, *) between(date, date, *) end |
.year_holidays(options, from_date = Date.today) ⇒ Object
FIXME All other methods start with a date and require a date. For the next
major version bump we should take the opportunity to change this
signature to match, e.g. year_holidays(from_date, )
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/holidays.rb', line 71 def year_holidays(, from_date = Date.today) raise ArgumentError if .empty? raise ArgumentError unless .is_a?(Array) # remove the timezone from_date = from_date.new_offset(0) + from_date.offset if from_date.respond_to?(:new_offset) from_date = get_date(from_date) Factory::Finder.year_holiday.call(from_date, ) end |