Module: HolidayCo
- Defined in:
- lib/holiday_co/holiday_calculator.rb,
lib/holiday_co.rb,
lib/holiday_co/cache.rb,
lib/holiday_co/utils.rb,
lib/holiday_co/errors.rb,
lib/holiday_co/version.rb,
lib/holiday_co/models/day.rb,
lib/holiday_co/models/year.rb,
lib/holiday_co/calculate_holidays/fixed.rb,
lib/holiday_co/calculate_holidays/pascua.rb,
lib/holiday_co/calculate_holidays/movable.rb
Overview
Dates are in YYYY-MM-DD format
Defined Under Namespace
Modules: CalculateHolidays
Classes: Cache, Day, HolidayCalculator, Year, YearDataNotAvailableError
Constant Summary
collapse
- UTC_OFFSET =
Colombian time zone is 5 hours behind UTC.
"-05:00".freeze
- AVAILABLE_YEARS =
Colombian Holidays started in 1983
(1983..9999).freeze
- VERSION =
"2.0.0"
Class Attribute Summary collapse
Class Method Summary
collapse
-
.adjust_day_for_pascua(day, month, march_22_offset, days_to_sunday, lunar_cycle_position) ⇒ Object
-
.cache ⇒ Object
-
.cache_enabled? ⇒ Boolean
-
.calculate_pascua_day_per_year(year) ⇒ Object
-
.calculate_pascua_offset(pascua_offset) ⇒ Object
-
.clear_cache! ⇒ Object
-
.configure {|_self| ... } ⇒ Object
-
.current_date ⇒ Object
-
.current_time ⇒ Object
-
.current_year ⇒ Object
-
.exception_date?(day, month) ⇒ Boolean
-
.generate_pascua_date(year, month, day) ⇒ Object
-
.holidays(year = current_year) ⇒ Object
-
.holidays_dates(year = current_year) ⇒ Object
-
.holidays_names(year = current_year) ⇒ Object
-
.is_holiday?(date = current_date) ⇒ Boolean
(also: holiday?)
-
.pascua_correction?(day, march_22_offset, days_to_sunday, lunar_cycle_position) ⇒ Boolean
-
.pascua_day_per_year(year) ⇒ Object
Class Attribute Details
.cache_enabled=(value) ⇒ Object
Sets the attribute cache_enabled
44
45
46
|
# File 'lib/holiday_co/cache.rb', line 44
def cache_enabled=(value)
@cache_enabled = value
end
|
.cache_size ⇒ Object
Returns the value of attribute cache_size.
45
46
47
|
# File 'lib/holiday_co/cache.rb', line 45
def cache_size
@cache_size
end
|
Class Method Details
.adjust_day_for_pascua(day, month, march_22_offset, days_to_sunday, lunar_cycle_position) ⇒ Object
78
79
80
81
82
83
|
# File 'lib/holiday_co/utils.rb', line 78
def self.adjust_day_for_pascua(day, month, march_22_offset, days_to_sunday, lunar_cycle_position)
return day unless exception_date?(day, month)
return day unless pascua_correction?(day, march_22_offset, days_to_sunday, lunar_cycle_position)
day -= 7
end
|
.cache ⇒ Object
60
61
62
|
# File 'lib/holiday_co/cache.rb', line 60
def cache
@cache ||= Cache.new(max_size: cache_size)
end
|
.cache_enabled? ⇒ Boolean
51
52
53
|
# File 'lib/holiday_co/cache.rb', line 51
def cache_enabled?
@cache_enabled
end
|
.calculate_pascua_day_per_year(year) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/holiday_co/utils.rb', line 31
def self.calculate_pascua_day_per_year(year)
lunar_cycle_position = year % 19 leap_year_indicator = year % 4 week_day_position = year % 7
century = year / 100 leap_year_adjustment = (13 + 8 * century) / 25 century_quarters = century / 4
lunar_adjustment = (15 - leap_year_adjustment + century - century_quarters) % 30 weekday_adjustment = (4 + century - century_quarters) % 7
march_22_offset = (19 * lunar_cycle_position + lunar_adjustment) % 30
final_weekday_adjustment = (
(2 * leap_year_indicator) +
(4 * week_day_position) +
(6 * march_22_offset) +
weekday_adjustment
) % 7
pascua_offset = march_22_offset + final_weekday_adjustment
day, month = calculate_pascua_offset(pascua_offset)
day = adjust_day_for_pascua(day, month, march_22_offset, final_weekday_adjustment, lunar_cycle_position)
generate_pascua_date(year, month, day)
end
|
.calculate_pascua_offset(pascua_offset) ⇒ Object
66
67
68
|
# File 'lib/holiday_co/utils.rb', line 66
def self.calculate_pascua_offset(pascua_offset)
pascua_offset <= 9 ? [pascua_offset + 22, "03"] : [pascua_offset - 9, "04"]
end
|
.clear_cache! ⇒ Object
64
65
66
|
# File 'lib/holiday_co/cache.rb', line 64
def clear_cache!
cache.clear!
end
|
47
48
49
|
# File 'lib/holiday_co/cache.rb', line 47
def configure
yield self if block_given?
end
|
.current_date ⇒ Object
19
20
21
|
# File 'lib/holiday_co/utils.rb', line 19
def self.current_date
current_time.to_date
end
|
.current_time ⇒ Object
11
12
13
|
# File 'lib/holiday_co/utils.rb', line 11
def self.current_time
Time.now.getlocal(UTC_OFFSET)
end
|
.current_year ⇒ Object
15
16
17
|
# File 'lib/holiday_co/utils.rb', line 15
def self.current_year
current_time.year
end
|
.exception_date?(day, month) ⇒ Boolean
70
71
72
|
# File 'lib/holiday_co/utils.rb', line 70
def self.exception_date?(day, month)
[26, 25].include?(day) && month == "04"
end
|
.generate_pascua_date(year, month, day) ⇒ Object
85
86
87
|
# File 'lib/holiday_co/utils.rb', line 85
def self.generate_pascua_date(year, month, day)
{ "#{year}" => "#{year}-#{month}-#{format('%02d', day)}" }
end
|
.holidays(year = current_year) ⇒ Object
18
19
20
|
# File 'lib/holiday_co.rb', line 18
def holidays(year = current_year)
Year.new(year).holidays
end
|
.holidays_dates(year = current_year) ⇒ Object
26
27
28
|
# File 'lib/holiday_co.rb', line 26
def holidays_dates(year = current_year)
Year.new(year).holiday_dates
end
|
.holidays_names(year = current_year) ⇒ Object
22
23
24
|
# File 'lib/holiday_co.rb', line 22
def holidays_names(year = current_year)
Year.new(year).holiday_names
end
|
.is_holiday?(date = current_date) ⇒ Boolean
Also known as:
holiday?
12
13
14
|
# File 'lib/holiday_co.rb', line 12
def is_holiday?(date = current_date)
Day.new(date).holiday?
end
|
.pascua_correction?(day, march_22_offset, days_to_sunday, lunar_cycle_position) ⇒ Boolean
74
75
76
|
# File 'lib/holiday_co/utils.rb', line 74
def self.pascua_correction?(day, march_22_offset, days_to_sunday, lunar_cycle_position)
day == 26 || march_22_offset == 28 && days_to_sunday == 6 && lunar_cycle_position > 10
end
|
.pascua_day_per_year(year) ⇒ Object