holidays_from_google_calendar 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2ae6b02cc84e33b45e895f23533e6c3bf660a64
|
4
|
+
data.tar.gz: 4ae41a072da7685c8c30afe4a6d7c8f9a346fec6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 200ebd890eddc0d45a9aa72e93101ec4ac128b4d15fd9e186735ea7247907f3a06f3bdb398eca8616ace16e6062bbf828f54e866f444f2a3cb6b6b8813fe17e8
|
7
|
+
data.tar.gz: c2894111a48fcb745adc21805631d98a1266063d4b675c14742aa8d47c2c9889c1f4a454d57cb47f54c0c34cdfff2f2de331de781ecd583e4c887046d142c018
|
data/README.md
CHANGED
@@ -61,7 +61,6 @@ usa_holidays.in_year(Date.parse("2016-02-06")) # Retrieve 2016's holidays
|
|
61
61
|
#<HolidaysFromGoogleCalendar::Holiday:0x007ff7d42d7a70 @date=Sun, 25 Dec 2016, @name="Christmas Day">,
|
62
62
|
#<HolidaysFromGoogleCalendar::Holiday:0x007ff7d42d7660 @date=Mon, 26 Dec 2016, @name="Christmas Day observed">,
|
63
63
|
#<HolidaysFromGoogleCalendar::Holiday:0x007ff7d42d70e8 @date=Sat, 31 Dec 2016, @name="New Year's Eve">,
|
64
|
-
#<HolidaysFromGoogleCalendar::Holiday:0x007ff7d42d62b0 @date=Sun, 01 Jan 2017, @name="New Year's Day">]
|
65
64
|
|
66
65
|
usa_holidays.in_month(Date.parse("3rd March 2016")) # Retrieve holidays of March, 2016
|
67
66
|
=> [#<HolidaysFromGoogleCalendar::Holiday:0x007ff7d42dd808 @date=Sun, 13 Mar 2016, @name="Daylight Saving Time starts">,
|
@@ -17,27 +17,30 @@ module HolidaysFromGoogleCalendar
|
|
17
17
|
@client = Client.new(@configuration)
|
18
18
|
end
|
19
19
|
|
20
|
+
def on_date(date)
|
21
|
+
@client.retrieve(
|
22
|
+
date_min: date,
|
23
|
+
date_max: date
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
20
27
|
def in_year(date)
|
21
|
-
date = Date.parse(date.iso8601) if date.is_a?(Time)
|
22
28
|
@client.retrieve(
|
23
29
|
date_min: date.beginning_of_year,
|
24
|
-
date_max: date.end_of_year
|
30
|
+
date_max: date.end_of_year
|
25
31
|
)
|
26
32
|
end
|
27
33
|
|
28
34
|
def in_month(date)
|
29
|
-
date = Date.parse(date.iso8601) if date.is_a?(Time)
|
30
35
|
@client.retrieve(
|
31
36
|
date_min: date.beginning_of_month,
|
32
|
-
date_max: date.end_of_month
|
37
|
+
date_max: date.end_of_month
|
33
38
|
)
|
34
39
|
end
|
35
40
|
|
36
41
|
def holiday?(date)
|
37
|
-
date = Date.parse(date.iso8601) if date.is_a?(Time)
|
38
42
|
return true if date.wday.in?([0, 6]) # If Sunday or Saturday
|
39
|
-
|
40
|
-
holiday && holiday.date == date
|
43
|
+
@client.retrieve(date_min: date, date_max: date).size > 0
|
41
44
|
end
|
42
45
|
end
|
43
46
|
end
|
@@ -11,6 +11,9 @@ module HolidaysFromGoogleCalendar
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def retrieve(date_min: nil, date_max: nil)
|
14
|
+
date_min = Date.parse(date_min.iso8601)
|
15
|
+
date_max = Date.parse(date_max.iso8601)
|
16
|
+
|
14
17
|
if @cache.enabled?
|
15
18
|
cached_holidays = @cache.retrieve(date_min, date_max)
|
16
19
|
return cached_holidays if cached_holidays
|
@@ -32,9 +35,9 @@ module HolidaysFromGoogleCalendar
|
|
32
35
|
single_events: true,
|
33
36
|
order_by: "startTime",
|
34
37
|
time_min: date_to_time(date_min),
|
35
|
-
time_max: date_to_time(date_max)
|
38
|
+
time_max: date_to_time(date_max + 1.day)
|
36
39
|
)
|
37
|
-
pack_response_in_object(response)
|
40
|
+
pack_response_in_object(response, date_min, date_max)
|
38
41
|
end
|
39
42
|
|
40
43
|
def calendar_id
|
@@ -42,17 +45,21 @@ module HolidaysFromGoogleCalendar
|
|
42
45
|
end
|
43
46
|
|
44
47
|
def date_to_time(date)
|
45
|
-
date = Date.parse(date.iso8601) if date.is_a?(Time)
|
46
48
|
Time.parse(date.iso8601).iso8601
|
47
49
|
end
|
48
50
|
|
49
|
-
def pack_response_in_object(response)
|
51
|
+
def pack_response_in_object(response, date_min, date_max)
|
50
52
|
response.items.reduce([]) do |array, item|
|
51
53
|
holiday = Holiday.new(
|
52
54
|
name: item.summary,
|
53
55
|
date: Date.parse(item.start.date)
|
54
56
|
)
|
55
|
-
|
57
|
+
|
58
|
+
if date_min <= holiday.date && holiday.date <= date_max
|
59
|
+
array.push(holiday)
|
60
|
+
else
|
61
|
+
array # Do nothing
|
62
|
+
end
|
56
63
|
end
|
57
64
|
end
|
58
65
|
|