business_calendar 0.0.17 → 0.0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/business_calendar/calendar.rb +14 -11
- data/lib/business_calendar/version.rb +1 -1
- data/lib/business_calendar.rb +10 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82cbe11f46934df2bcc820bd3725e10601f7e2942ef46285e191e96af392faee
|
4
|
+
data.tar.gz: 1bc29d426eb24de502a7b62c26300e841b914c74f66c6ab99193e2b862031103
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8aeaca2443bb3a4cfdf40dd6a016803b3e16bbf714104efb725ca417efcb9aecd76a5dd9cc7b334c6a2c79e66a882db31254b72cf834892a00a00b90be3da5f6
|
7
|
+
data.tar.gz: 76cc84dc341780de4f5c90899f101d0cc3215fc3b930602f982be66bf2f74b876503ad067abfa56d28be10fd5acee278db90a49e95740fe66c5e7a1f7e098de2
|
@@ -4,6 +4,7 @@ class BusinessCalendar::Calendar
|
|
4
4
|
# @param [Proc[Date -> Boolean]] a proc which returns whether or not a date is a
|
5
5
|
# holiday.
|
6
6
|
def initialize(holiday_determiner)
|
7
|
+
@is_holiday = {}
|
7
8
|
@holiday_determiner = holiday_determiner
|
8
9
|
end
|
9
10
|
|
@@ -11,7 +12,8 @@ class BusinessCalendar::Calendar
|
|
11
12
|
# @return [Boolean] Whether or not this calendar's list of holidays includes <date>.
|
12
13
|
def is_holiday?(date)
|
13
14
|
date = date.send(:to_date) if date.respond_to?(:to_date, true)
|
14
|
-
|
15
|
+
return @is_holiday[date] unless @is_holiday[date].nil?
|
16
|
+
@is_holiday[date] = holiday_determiner.call(date)
|
15
17
|
end
|
16
18
|
|
17
19
|
# @param [Date] date
|
@@ -36,8 +38,9 @@ class BusinessCalendar::Calendar
|
|
36
38
|
return subtract_business_days(date_or_dates, -num) if num < 0
|
37
39
|
|
38
40
|
with_one_or_many(date_or_dates) do |date|
|
39
|
-
|
40
|
-
num.times
|
41
|
+
d = nearest_business_day(date, initial_direction)
|
42
|
+
num.times { d = following_business_day(d) }
|
43
|
+
d
|
41
44
|
end
|
42
45
|
end
|
43
46
|
alias :add_business_day :add_business_days
|
@@ -51,7 +54,8 @@ class BusinessCalendar::Calendar
|
|
51
54
|
return add_business_days(date_or_dates, -num) if num < 0
|
52
55
|
|
53
56
|
with_one_or_many(date_or_dates) do |date|
|
54
|
-
num.times
|
57
|
+
num.times { date = preceding_business_day(date) }
|
58
|
+
date
|
55
59
|
end
|
56
60
|
end
|
57
61
|
alias :subtract_business_day :subtract_business_days
|
@@ -102,13 +106,12 @@ class BusinessCalendar::Calendar
|
|
102
106
|
|
103
107
|
private
|
104
108
|
def with_one_or_many(thing_or_things)
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
109
|
+
if thing_or_things.is_a? Enumerable
|
110
|
+
thing_or_things.collect do |thing|
|
111
|
+
yield thing
|
112
|
+
end
|
113
|
+
else
|
114
|
+
yield thing_or_things
|
110
115
|
end
|
111
|
-
|
112
|
-
return is_array ? results : results.first
|
113
116
|
end
|
114
117
|
end
|
data/lib/business_calendar.rb
CHANGED
@@ -2,8 +2,12 @@ module BusinessCalendar
|
|
2
2
|
CountryNotSupported = Class.new(StandardError)
|
3
3
|
OrganizationNotSupported = Class.new(StandardError)
|
4
4
|
class << self
|
5
|
-
def for(country)
|
6
|
-
|
5
|
+
def for(country, options = {})
|
6
|
+
if options["use_cached_calendar"]
|
7
|
+
calendar_cache[country] ||= Calendar.new(holiday_determiner(country))
|
8
|
+
else
|
9
|
+
Calendar.new(holiday_determiner(country))
|
10
|
+
end
|
7
11
|
end
|
8
12
|
|
9
13
|
def for_organization(org)
|
@@ -34,6 +38,10 @@ module BusinessCalendar
|
|
34
38
|
:additions_only => cfg['additions_only'] )
|
35
39
|
end
|
36
40
|
|
41
|
+
def calendar_cache
|
42
|
+
@calendar_cache ||= {}
|
43
|
+
end
|
44
|
+
|
37
45
|
def config(country)
|
38
46
|
@config ||= load_config
|
39
47
|
@config[country.to_s]
|