holidays 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .DS_Store
2
+ *.gem
3
+ nbproject
data/CHANGELOG CHANGED
@@ -1,4 +1,7 @@
1
1
  = Ruby Holidays Gem CHANGELOG
2
+
3
+ == 1.0.2
4
+ * Add `orthodox_easter` method and Greek holiday definitions (thanks https://github.com/ddimitriadis)
2
5
 
3
6
  == 1.0.0
4
7
  * Support calculating mday from negative weeks other than -1 (thanks http://github.com/bjeanes)
data/README.rdoc CHANGED
@@ -68,6 +68,6 @@ Lookup Canada Day in different regions.
68
68
  * Docs: http://rdoc.info/github/alexdunae/holidays/master/frames
69
69
  * Contributors: https://github.com/alexdunae/holidays/contributors
70
70
 
71
- Started by Alex Dunae (dunae.ca, e-mail 'code' at the same domain), 2007-10.
71
+ Started by Alex Dunae (dunae.ca, e-mail 'code' at the same domain), 2007-11.
72
72
 
73
73
  Made on Vancouver Island.
data/data/el.yaml ADDED
@@ -0,0 +1,79 @@
1
+ # Greek holiday definitions for the Ruby Holiday gem.
2
+ #
3
+ # Created: 2011-05-11.
4
+ # Sources:
5
+ # http://www.assa.org.au/edm.html
6
+ # http://fotios.org/node/1104
7
+ # http://www.faqs.org/faqs/calendars/faq/
8
+ # http://5dspace-time.org/Calendar/Algorithm.html - for offsets
9
+ # http://el.wikipedia.org/wiki/Επίσημες_αργίες_στην_Ελλάδα - for holidays
10
+ # http://www.eortologio.gr/arthra/pasxa.php - for holidays
11
+ ---
12
+ months:
13
+ 0:
14
+ - name: Μεγάλη Παρασκευή
15
+ regions: [el]
16
+ function: orthodox_easter(year)-2
17
+ - name: Μεγάλο Σάββατο
18
+ regions: [el]
19
+ function: orthodox_easter(year)-1
20
+ - name: Κυριακή του Πάσχα
21
+ regions: [el]
22
+ function: orthodox_easter(year)
23
+ - name: Δευτέρα του Πάσχα
24
+ regions: [el]
25
+ function: orthodox_easter(year)+1
26
+ - name: Καθαρά Δευτέρα
27
+ regions: [el]
28
+ function: orthodox_easter(year)-48
29
+ - name: Αγίου Πνεύματος
30
+ regions: [el]
31
+ function: orthodox_easter(year)+50
32
+ 1:
33
+ - name: Πρωτοχρονιά
34
+ regions: [el]
35
+ mday: 1
36
+ - name: Θεοφάνεια
37
+ regions: [el]
38
+ mday: 6
39
+ 3:
40
+ - name: Επέτειος της Επανάστασης του 1821
41
+ regions: [el]
42
+ mday: 25
43
+ 5:
44
+ - name: Πρωτομαγιά
45
+ regions: [el]
46
+ mday: 1
47
+ 8:
48
+ - name: Κοίμηση της Θεοτόκου
49
+ regions: [el]
50
+ mday: 15
51
+ 10:
52
+ - name: Επέτειος του Όχι
53
+ regions: [el]
54
+ mday: 28
55
+ 12:
56
+ - name: Χριστούγεννα
57
+ regions: [el]
58
+ mday: 25
59
+ - name: Δεύτερη ημέρα των Χριστουγέννων
60
+ regions: [el]
61
+ mday: 26
62
+ tests: |
63
+ {Date.civil(2011,1,1) => 'Πρωτοχρονιά',
64
+ Date.civil(2011,1,6) => 'Θεοφάνεια',
65
+ Date.civil(2011,4,22) => 'Μεγάλη Παρασκευή',
66
+ Date.civil(1970,4,25) => 'Μεγάλο Σάββατο',
67
+ Date.civil(1985,4,14) => 'Κυριακή του Πάσχα',
68
+ Date.civil(2011,4,24) => 'Κυριακή του Πάσχα',
69
+ Date.civil(2027,5,2) => 'Κυριακή του Πάσχα',
70
+ Date.civil(2046,4,30) => 'Δευτέρα του Πάσχα',
71
+ Date.civil(2011,5,1) => 'Πρωτομαγιά',
72
+ Date.civil(2011,6,13) => 'Αγίου Πνεύματος',
73
+ Date.civil(2012,6,4) => 'Αγίου Πνεύματος',
74
+ Date.civil(2011,3,7) => 'Καθαρά Δευτέρα',
75
+ Date.civil(2012,2,27) => 'Καθαρά Δευτέρα',
76
+ Date.civil(2011,12,25) => 'Χριστούγεννα',
77
+ Date.civil(2011,12,26) => 'Δεύτερη ημέρα των Χριστουγέννων'}.each do |date, name|
78
+ assert_equal name, (Holidays.on(date, :el, :informal)[0] || {})[:name]
79
+ end
data/data/index.yaml CHANGED
@@ -7,6 +7,7 @@ defs:
7
7
  CZ: ['cz.yaml']
8
8
  DK: ['dk.yaml']
9
9
  DE: ['de.yaml']
10
+ EL: ['el.yaml']
10
11
  ES: ['es.yaml']
11
12
  FI: ['fi.yaml']
12
13
  FR: ['fr.yaml']
@@ -27,5 +28,5 @@ defs:
27
28
  ZA: ['za.yaml']
28
29
  North_America: ['ca.yaml', 'mx.yaml', 'us.yaml', 'north_america_informal.yaml']
29
30
  Scandinavia: ['dk.yaml', 'is.yaml', 'no.yaml', 'se.yaml', 'fi.yaml']
30
- Europe: ['cz.yaml', 'dk.yaml', 'de.yaml', 'es.yaml', 'fr.yaml', 'gb.yaml', 'ie.yaml', 'is.yaml', 'it.yaml', 'nl.yaml', 'no.yaml', 'pt.yaml']
31
+ Europe: ['cz.yaml', 'dk.yaml', 'de.yaml', 'el.yaml', 'es.yaml', 'fr.yaml', 'gb.yaml', 'ie.yaml', 'is.yaml', 'it.yaml', 'nl.yaml', 'no.yaml', 'pt.yaml']
31
32
  JP: ['jp.yaml']
data/holidays.gemspec CHANGED
@@ -1,155 +1,161 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in rakefile.rb, and run 'rake gemspec'
3
+ # Instead, edit Jeweler::Tasks in rakefile.rb, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{holidays}
8
- s.version = "1.0.1"
8
+ s.version = "1.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alex Dunae", "Rowan Crawford"]
12
- s.date = %q{2011-04-29}
12
+ s.date = %q{2011-05-13}
13
13
  s.description = %q{A collection of Ruby methods to deal with statutory and other holidays. You deserve a holiday!}
14
14
  s.email = %q{code@dunae.ca}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
- "CHANGELOG",
21
- "LICENSE",
22
- "README.rdoc",
23
- "REFERENCES",
24
- "data/SYNTAX.rdoc",
25
- "data/au.yaml",
26
- "data/br.yaml",
27
- "data/build_defs.rb",
28
- "data/ca.yaml",
29
- "data/cz.yaml",
30
- "data/de.yaml",
31
- "data/dk.yaml",
32
- "data/es.yaml",
33
- "data/fi.yaml",
34
- "data/fr.yaml",
35
- "data/gb.yaml",
36
- "data/ie.yaml",
37
- "data/index.yaml",
38
- "data/is.yaml",
39
- "data/it.yaml",
40
- "data/jp.yaml",
41
- "data/mx.yaml",
42
- "data/nl.yaml",
43
- "data/no.yaml",
44
- "data/north_america_informal.yaml",
45
- "data/nyse.yaml",
46
- "data/nz.yaml",
47
- "data/pt.yaml",
48
- "data/se.yaml",
49
- "data/united_nations.yaml",
50
- "data/ups.yaml",
51
- "data/us.yaml",
52
- "data/za.yaml",
53
- "holidays.gemspec",
54
- "lib/holidays.rb",
55
- "lib/holidays/MANIFEST",
56
- "lib/holidays/au.rb",
57
- "lib/holidays/br.rb",
58
- "lib/holidays/ca.rb",
59
- "lib/holidays/cz.rb",
60
- "lib/holidays/de.rb",
61
- "lib/holidays/dk.rb",
62
- "lib/holidays/es.rb",
63
- "lib/holidays/europe.rb",
64
- "lib/holidays/fi.rb",
65
- "lib/holidays/fr.rb",
66
- "lib/holidays/gb.rb",
67
- "lib/holidays/ie.rb",
68
- "lib/holidays/is.rb",
69
- "lib/holidays/it.rb",
70
- "lib/holidays/jp.rb",
71
- "lib/holidays/mx.rb",
72
- "lib/holidays/nl.rb",
73
- "lib/holidays/no.rb",
74
- "lib/holidays/north_america.rb",
75
- "lib/holidays/nyse.rb",
76
- "lib/holidays/nz.rb",
77
- "lib/holidays/pt.rb",
78
- "lib/holidays/scandinavia.rb",
79
- "lib/holidays/se.rb",
80
- "lib/holidays/united_nations.rb",
81
- "lib/holidays/ups.rb",
82
- "lib/holidays/us.rb",
83
- "lib/holidays/za.rb",
84
- "rakefile.rb",
85
- "test/defs/test_defs_au.rb",
86
- "test/defs/test_defs_br.rb",
87
- "test/defs/test_defs_ca.rb",
88
- "test/defs/test_defs_cz.rb",
89
- "test/defs/test_defs_de.rb",
90
- "test/defs/test_defs_dk.rb",
91
- "test/defs/test_defs_es.rb",
92
- "test/defs/test_defs_europe.rb",
93
- "test/defs/test_defs_fi.rb",
94
- "test/defs/test_defs_fr.rb",
95
- "test/defs/test_defs_gb.rb",
96
- "test/defs/test_defs_ie.rb",
97
- "test/defs/test_defs_is.rb",
98
- "test/defs/test_defs_it.rb",
99
- "test/defs/test_defs_jp.rb",
100
- "test/defs/test_defs_mx.rb",
101
- "test/defs/test_defs_nl.rb",
102
- "test/defs/test_defs_no.rb",
103
- "test/defs/test_defs_north_america.rb",
104
- "test/defs/test_defs_nyse.rb",
105
- "test/defs/test_defs_nz.rb",
106
- "test/defs/test_defs_pt.rb",
107
- "test/defs/test_defs_scandinavia.rb",
108
- "test/defs/test_defs_se.rb",
109
- "test/defs/test_defs_ups.rb",
110
- "test/defs/test_defs_us.rb",
111
- "test/defs/test_defs_za.rb",
112
- "test/test_date.rb",
113
- "test/test_helper.rb",
114
- "test/test_holidays.rb",
115
- "test/test_multiple_regions.rb"
20
+ ".gitignore",
21
+ "CHANGELOG",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "REFERENCES",
25
+ "data/SYNTAX.rdoc",
26
+ "data/au.yaml",
27
+ "data/br.yaml",
28
+ "data/build_defs.rb",
29
+ "data/ca.yaml",
30
+ "data/cz.yaml",
31
+ "data/de.yaml",
32
+ "data/dk.yaml",
33
+ "data/el.yaml",
34
+ "data/es.yaml",
35
+ "data/fi.yaml",
36
+ "data/fr.yaml",
37
+ "data/gb.yaml",
38
+ "data/ie.yaml",
39
+ "data/index.yaml",
40
+ "data/is.yaml",
41
+ "data/it.yaml",
42
+ "data/jp.yaml",
43
+ "data/mx.yaml",
44
+ "data/nl.yaml",
45
+ "data/no.yaml",
46
+ "data/north_america_informal.yaml",
47
+ "data/nyse.yaml",
48
+ "data/nz.yaml",
49
+ "data/pt.yaml",
50
+ "data/se.yaml",
51
+ "data/united_nations.yaml",
52
+ "data/ups.yaml",
53
+ "data/us.yaml",
54
+ "data/za.yaml",
55
+ "holidays.gemspec",
56
+ "lib/holidays.rb",
57
+ "lib/holidays/MANIFEST",
58
+ "lib/holidays/au.rb",
59
+ "lib/holidays/br.rb",
60
+ "lib/holidays/ca.rb",
61
+ "lib/holidays/cz.rb",
62
+ "lib/holidays/de.rb",
63
+ "lib/holidays/dk.rb",
64
+ "lib/holidays/el.rb",
65
+ "lib/holidays/es.rb",
66
+ "lib/holidays/europe.rb",
67
+ "lib/holidays/fi.rb",
68
+ "lib/holidays/fr.rb",
69
+ "lib/holidays/gb.rb",
70
+ "lib/holidays/ie.rb",
71
+ "lib/holidays/is.rb",
72
+ "lib/holidays/it.rb",
73
+ "lib/holidays/jp.rb",
74
+ "lib/holidays/mx.rb",
75
+ "lib/holidays/nl.rb",
76
+ "lib/holidays/no.rb",
77
+ "lib/holidays/north_america.rb",
78
+ "lib/holidays/nyse.rb",
79
+ "lib/holidays/nz.rb",
80
+ "lib/holidays/pt.rb",
81
+ "lib/holidays/scandinavia.rb",
82
+ "lib/holidays/se.rb",
83
+ "lib/holidays/united_nations.rb",
84
+ "lib/holidays/ups.rb",
85
+ "lib/holidays/us.rb",
86
+ "lib/holidays/za.rb",
87
+ "rakefile.rb",
88
+ "test/defs/test_defs_au.rb",
89
+ "test/defs/test_defs_br.rb",
90
+ "test/defs/test_defs_ca.rb",
91
+ "test/defs/test_defs_cz.rb",
92
+ "test/defs/test_defs_de.rb",
93
+ "test/defs/test_defs_dk.rb",
94
+ "test/defs/test_defs_el.rb",
95
+ "test/defs/test_defs_es.rb",
96
+ "test/defs/test_defs_europe.rb",
97
+ "test/defs/test_defs_fi.rb",
98
+ "test/defs/test_defs_fr.rb",
99
+ "test/defs/test_defs_gb.rb",
100
+ "test/defs/test_defs_ie.rb",
101
+ "test/defs/test_defs_is.rb",
102
+ "test/defs/test_defs_it.rb",
103
+ "test/defs/test_defs_jp.rb",
104
+ "test/defs/test_defs_mx.rb",
105
+ "test/defs/test_defs_nl.rb",
106
+ "test/defs/test_defs_no.rb",
107
+ "test/defs/test_defs_north_america.rb",
108
+ "test/defs/test_defs_nyse.rb",
109
+ "test/defs/test_defs_nz.rb",
110
+ "test/defs/test_defs_pt.rb",
111
+ "test/defs/test_defs_scandinavia.rb",
112
+ "test/defs/test_defs_se.rb",
113
+ "test/defs/test_defs_ups.rb",
114
+ "test/defs/test_defs_us.rb",
115
+ "test/defs/test_defs_za.rb",
116
+ "test/test_date.rb",
117
+ "test/test_helper.rb",
118
+ "test/test_holidays.rb",
119
+ "test/test_multiple_regions.rb"
116
120
  ]
117
121
  s.homepage = %q{https://github.com/alexdunae/holidays}
122
+ s.rdoc_options = ["--charset=UTF-8"]
118
123
  s.require_paths = ["lib"]
119
124
  s.rubygems_version = %q{1.3.7}
120
125
  s.summary = %q{A collection of Ruby methods to deal with statutory and other holidays. You deserve a holiday!}
121
126
  s.test_files = [
122
127
  "test/defs/test_defs_au.rb",
123
- "test/defs/test_defs_br.rb",
124
- "test/defs/test_defs_ca.rb",
125
- "test/defs/test_defs_cz.rb",
126
- "test/defs/test_defs_de.rb",
127
- "test/defs/test_defs_dk.rb",
128
- "test/defs/test_defs_es.rb",
129
- "test/defs/test_defs_europe.rb",
130
- "test/defs/test_defs_fi.rb",
131
- "test/defs/test_defs_fr.rb",
132
- "test/defs/test_defs_gb.rb",
133
- "test/defs/test_defs_ie.rb",
134
- "test/defs/test_defs_is.rb",
135
- "test/defs/test_defs_it.rb",
136
- "test/defs/test_defs_jp.rb",
137
- "test/defs/test_defs_mx.rb",
138
- "test/defs/test_defs_nl.rb",
139
- "test/defs/test_defs_no.rb",
140
- "test/defs/test_defs_north_america.rb",
141
- "test/defs/test_defs_nyse.rb",
142
- "test/defs/test_defs_nz.rb",
143
- "test/defs/test_defs_pt.rb",
144
- "test/defs/test_defs_scandinavia.rb",
145
- "test/defs/test_defs_se.rb",
146
- "test/defs/test_defs_ups.rb",
147
- "test/defs/test_defs_us.rb",
148
- "test/defs/test_defs_za.rb",
149
- "test/test_date.rb",
150
- "test/test_helper.rb",
151
- "test/test_holidays.rb",
152
- "test/test_multiple_regions.rb"
128
+ "test/defs/test_defs_br.rb",
129
+ "test/defs/test_defs_ca.rb",
130
+ "test/defs/test_defs_cz.rb",
131
+ "test/defs/test_defs_de.rb",
132
+ "test/defs/test_defs_dk.rb",
133
+ "test/defs/test_defs_el.rb",
134
+ "test/defs/test_defs_es.rb",
135
+ "test/defs/test_defs_europe.rb",
136
+ "test/defs/test_defs_fi.rb",
137
+ "test/defs/test_defs_fr.rb",
138
+ "test/defs/test_defs_gb.rb",
139
+ "test/defs/test_defs_ie.rb",
140
+ "test/defs/test_defs_is.rb",
141
+ "test/defs/test_defs_it.rb",
142
+ "test/defs/test_defs_jp.rb",
143
+ "test/defs/test_defs_mx.rb",
144
+ "test/defs/test_defs_nl.rb",
145
+ "test/defs/test_defs_no.rb",
146
+ "test/defs/test_defs_north_america.rb",
147
+ "test/defs/test_defs_nyse.rb",
148
+ "test/defs/test_defs_nz.rb",
149
+ "test/defs/test_defs_pt.rb",
150
+ "test/defs/test_defs_scandinavia.rb",
151
+ "test/defs/test_defs_se.rb",
152
+ "test/defs/test_defs_ups.rb",
153
+ "test/defs/test_defs_us.rb",
154
+ "test/defs/test_defs_za.rb",
155
+ "test/test_date.rb",
156
+ "test/test_helper.rb",
157
+ "test/test_holidays.rb",
158
+ "test/test_multiple_regions.rb"
153
159
  ]
154
160
 
155
161
  if s.respond_to? :specification_version then
data/lib/holidays.rb CHANGED
@@ -43,7 +43,7 @@ module Holidays
43
43
  # Exception thrown when an unknown region is requested.
44
44
  class UnknownRegionError < ArgumentError; end
45
45
 
46
- VERSION = '1.0.1'
46
+ VERSION = '1.0.2'
47
47
 
48
48
  @@regions = []
49
49
  @@holidays_by_month = {}
@@ -211,6 +211,33 @@ module Holidays
211
211
  day = ((h + l - 7 * m + 114) % 31) + 1
212
212
  Date.civil(year, month, day)
213
213
  end
214
+
215
+ # A method to calculate the orthodox easter date, returns date in the Gregorian (western) calendar
216
+ # Safe until appr. 4100 AD, when one leap day will be removed.
217
+ # Returns a Date object.
218
+ def self.orthodox_easter(year)
219
+ y = year
220
+ g = y % 19
221
+ i = (19 * g + 15) % 30
222
+ j = (year + year/4 + i) % 7
223
+ j_month = 3 + (i - j + 40) / 44
224
+ j_day = i - j + 28 - 31 * (j_month / 4)
225
+ j_date = Date.civil(year, j_month, j_day)
226
+ case
227
+ # up until 1582, julian and gregorian easter dates were identical
228
+ when year <= 1582
229
+ offset = 0
230
+ # between the years 1583 and 1699 10 days are added to the julian day count
231
+ when (year >= 1583 and year <= 1699)
232
+ offset = 10
233
+ # after 1700, 1 day is added for each century, except if the century year is exactly divisible by 400 (in which case no days are added).
234
+ # Safe until 4100 AD, when one leap day will be removed.
235
+ when year >= 1700
236
+ offset = (year - 1700).divmod(100)[0] + ((year - year.divmod(100)[1]).divmod(400)[1] == 0 ? 0 : 1) - (year - year.divmod(100)[1] - 1700).divmod(400)[0] + 10
237
+ end
238
+ # add offset to the julian day
239
+ return Date.jd(j_date.jd + offset)
240
+ end
214
241
 
215
242
  # Move date to Monday if it occurs on a Sunday.
216
243
  # Used as a callback function.