holiday_japan 1.3.0 → 1.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +96 -95
- data/README.md.erb +126 -0
- data/Rakefile +4 -0
- data/holiday_japan.gemspec +1 -1
- data/lib/holiday_japan.rb +63 -51
- data/test/holiday.csv +1016 -0
- data/test/holiday_japan_test.rb +50 -0
- metadata +10 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fa83de54f75e47487ab3a1ade42e1975626626277bfacd7216d6ef49e33a29b1
|
4
|
+
data.tar.gz: 33dc6e82aeaaa225235235b5a9c1088316f2edd223fa46f8d1a16ac872fd7a1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4d95886e086319038d5d550bbbd72fdd1c57032a95cda32b2c8ad21bbbd2ff400bff7ebf5d3cc8fcb4dc4a65647759310c1112bddd802417eab0f98cb661726
|
7
|
+
data.tar.gz: fcba6ca2e2d6f35777b0f822f28f0196e4cdacfd3a6bf9ac9cc69484f4a044115584dac34f7e6960dbe5f390ad1c22977cc62d649babe7fefe340214b2ae0dfe
|
data/README.md
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
|
1
2
|
# 日本の祝日判定Rubyプログラム
|
2
3
|
|
3
4
|
([GitHub](https://github.com/masa16/holiday_japan)),
|
@@ -12,6 +13,9 @@
|
|
12
13
|
* 祝日名を返すことが可能
|
13
14
|
* 祝日のルールをテーブルで持つことにより、法改正による祝日変更への対応が容易
|
14
15
|
|
16
|
+
([holiday_jp](https://rubygems.org/gems/holiday_jp) と比較して)
|
17
|
+
* holiday_jp は日付をキーとする祝日データセットに基く。holiday_japan は祝日ルールに基き、照会された年ごとにデータセットを生成する。
|
18
|
+
|
15
19
|
## インストール
|
16
20
|
|
17
21
|
* RubyGems によるインストール
|
@@ -35,152 +39,149 @@
|
|
35
39
|
* `check(date)` ― Dateクラスのオブジェクトによる祝日判定
|
36
40
|
|
37
41
|
```ruby
|
38
|
-
HolidayJapan.check(Date.new(
|
42
|
+
HolidayJapan.check(Date.new(2021,3,20))
|
39
43
|
=> true
|
40
44
|
```
|
41
45
|
|
46
|
+
|
42
47
|
* `name(date)` ― 日付が祝日の場合は祝日名を返し、祝日でなければ nil を返す。
|
43
48
|
|
44
49
|
```ruby
|
45
|
-
HolidayJapan.name(Date.new(
|
50
|
+
HolidayJapan.name(Date.new(2021,3,20))
|
46
51
|
=> "春分の日"
|
47
52
|
```
|
48
53
|
|
54
|
+
|
49
55
|
* `print_year(year)` ― ある年の祝日一覧をプリント
|
50
56
|
|
51
57
|
```
|
52
|
-
$ ruby -r holiday_japan -e 'HolidayJapan.print_year
|
53
|
-
listing year
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
2018-12-23 Sun 天皇誕生日
|
73
|
-
2018-12-24 Mon 振替休日
|
58
|
+
$ ruby -r holiday_japan -e 'HolidayJapan.print_year 2021'
|
59
|
+
listing year 2021...
|
60
|
+
2021-01-01 Fri 元日
|
61
|
+
2021-01-11 Mon 成人の日
|
62
|
+
2021-02-11 Thu 建国記念の日
|
63
|
+
2021-02-23 Tue 天皇誕生日
|
64
|
+
2021-03-20 Sat 春分の日
|
65
|
+
2021-04-29 Thu 昭和の日
|
66
|
+
2021-05-03 Mon 憲法記念日
|
67
|
+
2021-05-04 Tue みどりの日
|
68
|
+
2021-05-05 Wed こどもの日
|
69
|
+
2021-07-22 Thu 海の日
|
70
|
+
2021-07-23 Fri スポーツの日
|
71
|
+
2021-08-08 Sun 山の日
|
72
|
+
2021-08-09 Mon 振替休日
|
73
|
+
2021-09-20 Mon 敬老の日
|
74
|
+
2021-09-23 Thu 秋分の日
|
75
|
+
2021-11-03 Wed 文化の日
|
76
|
+
2021-11-23 Tue 勤労感謝の日
|
77
|
+
|
74
78
|
```
|
75
79
|
|
76
80
|
* `list_year(year)` ― ある年について、 [日付, 祝日名] のArrayを返す
|
77
81
|
|
78
82
|
```ruby
|
79
|
-
HolidayJapan.list_year(
|
80
|
-
=> [[#<Date:
|
81
|
-
[#<Date:
|
82
|
-
[#<Date:
|
83
|
-
[#<Date:
|
84
|
-
[#<Date:
|
85
|
-
[#<Date:
|
86
|
-
[#<Date:
|
87
|
-
[#<Date:
|
88
|
-
[#<Date:
|
89
|
-
[#<Date:
|
90
|
-
[#<Date:
|
91
|
-
[#<Date:
|
92
|
-
[#<Date:
|
93
|
-
[#<Date:
|
94
|
-
[#<Date:
|
95
|
-
[#<Date:
|
96
|
-
[#<Date:
|
97
|
-
[#<Date: 2018-11-23 ((2458446j,0s,0n),+0s,2299161j)>, "勤労感謝の日"],
|
98
|
-
[#<Date: 2018-12-23 ((2458476j,0s,0n),+0s,2299161j)>, "天皇誕生日"],
|
99
|
-
[#<Date: 2018-12-24 ((2458477j,0s,0n),+0s,2299161j)>, "振替休日"]]
|
83
|
+
HolidayJapan.list_year(2021)
|
84
|
+
=> [[#<Date: 2021-01-01 ((2459216j,0s,0n),+0s,2299161j)>, "元日"],
|
85
|
+
[#<Date: 2021-01-11 ((2459226j,0s,0n),+0s,2299161j)>, "成人の日"],
|
86
|
+
[#<Date: 2021-02-11 ((2459257j,0s,0n),+0s,2299161j)>, "建国記念の日"],
|
87
|
+
[#<Date: 2021-02-23 ((2459269j,0s,0n),+0s,2299161j)>, "天皇誕生日"],
|
88
|
+
[#<Date: 2021-03-20 ((2459294j,0s,0n),+0s,2299161j)>, "春分の日"],
|
89
|
+
[#<Date: 2021-04-29 ((2459334j,0s,0n),+0s,2299161j)>, "昭和の日"],
|
90
|
+
[#<Date: 2021-05-03 ((2459338j,0s,0n),+0s,2299161j)>, "憲法記念日"],
|
91
|
+
[#<Date: 2021-05-04 ((2459339j,0s,0n),+0s,2299161j)>, "みどりの日"],
|
92
|
+
[#<Date: 2021-05-05 ((2459340j,0s,0n),+0s,2299161j)>, "こどもの日"],
|
93
|
+
[#<Date: 2021-07-22 ((2459418j,0s,0n),+0s,2299161j)>, "海の日"],
|
94
|
+
[#<Date: 2021-07-23 ((2459419j,0s,0n),+0s,2299161j)>, "スポーツの日"],
|
95
|
+
[#<Date: 2021-08-08 ((2459435j,0s,0n),+0s,2299161j)>, "山の日"],
|
96
|
+
[#<Date: 2021-08-09 ((2459436j,0s,0n),+0s,2299161j)>, "振替休日"],
|
97
|
+
[#<Date: 2021-09-20 ((2459478j,0s,0n),+0s,2299161j)>, "敬老の日"],
|
98
|
+
[#<Date: 2021-09-23 ((2459481j,0s,0n),+0s,2299161j)>, "秋分の日"],
|
99
|
+
[#<Date: 2021-11-03 ((2459522j,0s,0n),+0s,2299161j)>, "文化の日"],
|
100
|
+
[#<Date: 2021-11-23 ((2459542j,0s,0n),+0s,2299161j)>, "勤労感謝の日"]]
|
100
101
|
```
|
101
102
|
|
103
|
+
|
102
104
|
* `hash_year(year)` ― ある年について、 {日付=>祝日名} のHashを返す
|
103
105
|
|
104
106
|
```ruby
|
105
|
-
HolidayJapan.hash_year(
|
106
|
-
=> {#<Date:
|
107
|
-
#<Date:
|
108
|
-
#<Date:
|
109
|
-
#<Date:
|
110
|
-
#<Date:
|
111
|
-
#<Date:
|
112
|
-
#<Date:
|
113
|
-
#<Date:
|
114
|
-
#<Date:
|
115
|
-
#<Date:
|
116
|
-
#<Date:
|
117
|
-
#<Date:
|
118
|
-
#<Date:
|
119
|
-
#<Date:
|
120
|
-
#<Date:
|
121
|
-
#<Date:
|
122
|
-
#<Date:
|
123
|
-
#<Date: 2018-11-23 ((2458446j,0s,0n),+0s,2299161j)>=>"勤労感謝の日",
|
124
|
-
#<Date: 2018-12-23 ((2458476j,0s,0n),+0s,2299161j)>=>"天皇誕生日",
|
125
|
-
#<Date: 2018-12-24 ((2458477j,0s,0n),+0s,2299161j)>=>"振替休日"}
|
107
|
+
HolidayJapan.hash_year(2021)
|
108
|
+
=> {#<Date: 2021-01-01 ((2459216j,0s,0n),+0s,2299161j)>=>"元日",
|
109
|
+
#<Date: 2021-01-11 ((2459226j,0s,0n),+0s,2299161j)>=>"成人の日",
|
110
|
+
#<Date: 2021-02-11 ((2459257j,0s,0n),+0s,2299161j)>=>"建国記念の日",
|
111
|
+
#<Date: 2021-02-23 ((2459269j,0s,0n),+0s,2299161j)>=>"天皇誕生日",
|
112
|
+
#<Date: 2021-03-20 ((2459294j,0s,0n),+0s,2299161j)>=>"春分の日",
|
113
|
+
#<Date: 2021-04-29 ((2459334j,0s,0n),+0s,2299161j)>=>"昭和の日",
|
114
|
+
#<Date: 2021-05-03 ((2459338j,0s,0n),+0s,2299161j)>=>"憲法記念日",
|
115
|
+
#<Date: 2021-05-04 ((2459339j,0s,0n),+0s,2299161j)>=>"みどりの日",
|
116
|
+
#<Date: 2021-05-05 ((2459340j,0s,0n),+0s,2299161j)>=>"こどもの日",
|
117
|
+
#<Date: 2021-07-22 ((2459418j,0s,0n),+0s,2299161j)>=>"海の日",
|
118
|
+
#<Date: 2021-07-23 ((2459419j,0s,0n),+0s,2299161j)>=>"スポーツの日",
|
119
|
+
#<Date: 2021-08-08 ((2459435j,0s,0n),+0s,2299161j)>=>"山の日",
|
120
|
+
#<Date: 2021-08-09 ((2459436j,0s,0n),+0s,2299161j)>=>"振替休日",
|
121
|
+
#<Date: 2021-09-20 ((2459478j,0s,0n),+0s,2299161j)>=>"敬老の日",
|
122
|
+
#<Date: 2021-09-23 ((2459481j,0s,0n),+0s,2299161j)>=>"秋分の日",
|
123
|
+
#<Date: 2021-11-03 ((2459522j,0s,0n),+0s,2299161j)>=>"文化の日",
|
124
|
+
#<Date: 2021-11-23 ((2459542j,0s,0n),+0s,2299161j)>=>"勤労感謝の日"}
|
126
125
|
```
|
127
126
|
|
127
|
+
|
128
128
|
* `between(from_date,to_date)` ― from_date から to_date までの祝日について、{日付=>祝日名}のHashを返す
|
129
129
|
|
130
130
|
```ruby
|
131
|
-
HolidayJapan.between("
|
132
|
-
=> {#<Date:
|
133
|
-
#<Date:
|
134
|
-
#<Date:
|
135
|
-
#<Date:
|
136
|
-
#<Date:
|
137
|
-
#<Date:
|
138
|
-
#<Date:
|
139
|
-
#<Date:
|
140
|
-
#<Date:
|
141
|
-
#<Date:
|
142
|
-
#<Date:
|
143
|
-
#<Date:
|
144
|
-
#<Date:
|
145
|
-
#<Date:
|
146
|
-
#<Date:
|
147
|
-
#<Date:
|
148
|
-
#<Date:
|
149
|
-
#<Date: 2019-02-11 ((2458526j,0s,0n),+0s,2299161j)>=>"建国記念の日",
|
150
|
-
#<Date: 2019-03-21 ((2458564j,0s,0n),+0s,2299161j)>=>"春分の日"}
|
131
|
+
HolidayJapan.between("2021-4-1","2022-3-31")
|
132
|
+
=> {#<Date: 2021-04-29 ((2459334j,0s,0n),+0s,2299161j)>=>"昭和の日",
|
133
|
+
#<Date: 2021-05-03 ((2459338j,0s,0n),+0s,2299161j)>=>"憲法記念日",
|
134
|
+
#<Date: 2021-05-04 ((2459339j,0s,0n),+0s,2299161j)>=>"みどりの日",
|
135
|
+
#<Date: 2021-05-05 ((2459340j,0s,0n),+0s,2299161j)>=>"こどもの日",
|
136
|
+
#<Date: 2021-07-22 ((2459418j,0s,0n),+0s,2299161j)>=>"海の日",
|
137
|
+
#<Date: 2021-07-23 ((2459419j,0s,0n),+0s,2299161j)>=>"スポーツの日",
|
138
|
+
#<Date: 2021-08-08 ((2459435j,0s,0n),+0s,2299161j)>=>"山の日",
|
139
|
+
#<Date: 2021-08-09 ((2459436j,0s,0n),+0s,2299161j)>=>"振替休日",
|
140
|
+
#<Date: 2021-09-20 ((2459478j,0s,0n),+0s,2299161j)>=>"敬老の日",
|
141
|
+
#<Date: 2021-09-23 ((2459481j,0s,0n),+0s,2299161j)>=>"秋分の日",
|
142
|
+
#<Date: 2021-11-03 ((2459522j,0s,0n),+0s,2299161j)>=>"文化の日",
|
143
|
+
#<Date: 2021-11-23 ((2459542j,0s,0n),+0s,2299161j)>=>"勤労感謝の日",
|
144
|
+
#<Date: 2022-01-01 ((2459581j,0s,0n),+0s,2299161j)>=>"元日",
|
145
|
+
#<Date: 2022-01-10 ((2459590j,0s,0n),+0s,2299161j)>=>"成人の日",
|
146
|
+
#<Date: 2022-02-11 ((2459622j,0s,0n),+0s,2299161j)>=>"建国記念の日",
|
147
|
+
#<Date: 2022-02-23 ((2459634j,0s,0n),+0s,2299161j)>=>"天皇誕生日",
|
148
|
+
#<Date: 2022-03-21 ((2459660j,0s,0n),+0s,2299161j)>=>"春分の日"}
|
151
149
|
```
|
152
150
|
|
151
|
+
|
153
152
|
### 祝日データをCSVに出力
|
154
153
|
|
155
154
|
```
|
156
|
-
$ ruby -r csv -r holiday_japan -e 'CSV.open("holiday.csv","w"){|c| HolidayJapan.between(
|
155
|
+
$ ruby -r csv -r holiday_japan -e 'CSV.open("holiday.csv","w"){|c| HolidayJapan.between(2020,2021).each{|a| c<<a}}'
|
157
156
|
|
158
157
|
$ head -n3 holiday.csv ; echo ...; tail -n3 holiday.csv
|
159
|
-
|
160
|
-
|
161
|
-
|
158
|
+
2020-01-01,元日
|
159
|
+
2020-01-13,成人の日
|
160
|
+
2020-02-11,建国記念の日
|
162
161
|
...
|
163
|
-
|
164
|
-
|
165
|
-
|
162
|
+
2021-09-23,秋分の日
|
163
|
+
2021-11-03,文化の日
|
164
|
+
2021-11-23,勤労感謝の日
|
165
|
+
|
166
166
|
```
|
167
167
|
|
168
168
|
## 祝日データ
|
169
169
|
|
170
170
|
* 1948年7月20日(祝日法発令) 以降の祝日に対応
|
171
|
-
*
|
171
|
+
* 2021年の[暦要項](http://eco.mtk.nao.ac.jp/koyomi/yoko/)まで確認(法改正がない限り以降も有効)
|
172
172
|
* 春分の日・秋分の日の計算は2150年まで
|
173
173
|
|
174
174
|
## Author:
|
175
175
|
Masahiro TANAKA
|
176
176
|
|
177
177
|
## Copyright:
|
178
|
-
(C) Copyright 2003-
|
178
|
+
(C) Copyright 2003-2020 by Masahiro TANAKA
|
179
179
|
This program is free software under MIT license.
|
180
180
|
See LICENSE.txt.
|
181
181
|
NO WARRANTY.
|
182
182
|
|
183
183
|
## Version:
|
184
|
+
2018-04-14 ver 1.4 祝日データ仕様変更、2019,2020年対応
|
184
185
|
2017-12-01 ver 1.3 print_between 関数追加
|
185
186
|
2015-04-11 ver 1.2 hash_year, between 関数追加
|
186
187
|
2014-05-23 ver 1.1 「山の日」追加
|
data/README.md.erb
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
<%
|
2
|
+
# erb -T 1 README.md.erb > README.md
|
3
|
+
require 'pp'
|
4
|
+
require 'holiday_japan'
|
5
|
+
$indent=' '
|
6
|
+
|
7
|
+
def x(sample)
|
8
|
+
a = eval(sample).pretty_inspect.each_line.to_a
|
9
|
+
[
|
10
|
+
"```ruby\n",
|
11
|
+
sample+"\n",
|
12
|
+
"=> "+a.shift,
|
13
|
+
*a.map{|x| " "+x },
|
14
|
+
"```\n"
|
15
|
+
].map{|x| $indent+x}.join
|
16
|
+
end
|
17
|
+
|
18
|
+
def c(sample)
|
19
|
+
[
|
20
|
+
"$ "+sample+"\n",
|
21
|
+
*`#{sample}`.each_line.to_a,
|
22
|
+
].map{|x| $indent+x}.join
|
23
|
+
end
|
24
|
+
%>
|
25
|
+
# 日本の祝日判定Rubyプログラム
|
26
|
+
|
27
|
+
([GitHub](https://github.com/masa16/holiday_japan)),
|
28
|
+
([RubyGems](https://rubygems.org/gems/holiday_japan))
|
29
|
+
|
30
|
+
## 特徴
|
31
|
+
* 1948年7月20日以降の日本の国民の祝日、振替休日、および国民の休日を計算して判定。
|
32
|
+
* スクリプトコード([holiday_japan.rb](https://github.com/masa16/holiday_japan/blob/master/lib/holiday_japan.rb))は、祝日データを含めて200行弱とコンパクト。
|
33
|
+
|
34
|
+
(date2 の holiday.rb と比較して)
|
35
|
+
* 祝日をキャッシュすることにより、大量の日付について祝日判定する場合でも高速に動作
|
36
|
+
* 祝日名を返すことが可能
|
37
|
+
* 祝日のルールをテーブルで持つことにより、法改正による祝日変更への対応が容易
|
38
|
+
|
39
|
+
([holiday_jp](https://rubygems.org/gems/holiday_jp) と比較して)
|
40
|
+
* holiday_jp は日付をキーとする祝日データセットに基く。holiday_japan は祝日ルールに基き、照会された年ごとにデータセットを生成する。
|
41
|
+
|
42
|
+
## インストール
|
43
|
+
|
44
|
+
* RubyGems によるインストール
|
45
|
+
```
|
46
|
+
gem install holiday_japan
|
47
|
+
```
|
48
|
+
|
49
|
+
* または、[holiday_japan.rb](https://github.com/masa16/holiday_japan/blob/master/lib/holiday_japan.rb)
|
50
|
+
のスクリプトファイルを ruby のライブラリパスに置く
|
51
|
+
|
52
|
+
## 使い方
|
53
|
+
|
54
|
+
### モジュールをロード
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
require 'holiday_japan'
|
58
|
+
```
|
59
|
+
|
60
|
+
### HolidayJapan モジュール関数
|
61
|
+
|
62
|
+
* `check(date)` ― Dateクラスのオブジェクトによる祝日判定
|
63
|
+
|
64
|
+
<%= x('HolidayJapan.check(Date.new(2021,3,20))') %>
|
65
|
+
|
66
|
+
* `name(date)` ― 日付が祝日の場合は祝日名を返し、祝日でなければ nil を返す。
|
67
|
+
|
68
|
+
<%= x('HolidayJapan.name(Date.new(2021,3,20))') %>
|
69
|
+
|
70
|
+
* `print_year(year)` ― ある年の祝日一覧をプリント
|
71
|
+
|
72
|
+
```
|
73
|
+
<%= c("ruby -r holiday_japan -e 'HolidayJapan.print_year 2021'") %>
|
74
|
+
```
|
75
|
+
|
76
|
+
* `list_year(year)` ― ある年について、 [日付, 祝日名] のArrayを返す
|
77
|
+
|
78
|
+
<%= x('HolidayJapan.list_year(2021)') %>
|
79
|
+
|
80
|
+
* `hash_year(year)` ― ある年について、 {日付=>祝日名} のHashを返す
|
81
|
+
|
82
|
+
<%= x('HolidayJapan.hash_year(2021)') %>
|
83
|
+
|
84
|
+
* `between(from_date,to_date)` ― from_date から to_date までの祝日について、{日付=>祝日名}のHashを返す
|
85
|
+
|
86
|
+
<%= x('HolidayJapan.between("2021-4-1","2022-3-31")') %>
|
87
|
+
|
88
|
+
### 祝日データをCSVに出力
|
89
|
+
|
90
|
+
```
|
91
|
+
<%= c(%!ruby -r csv -r holiday_japan -e 'CSV.open("holiday.csv","w"){|c| HolidayJapan.between(2020,2021).each{|a| c<<a}}'!) %>
|
92
|
+
<%= c("head -n3 holiday.csv ; echo ...; tail -n3 holiday.csv") %>
|
93
|
+
```
|
94
|
+
|
95
|
+
## 祝日データ
|
96
|
+
|
97
|
+
* 1948年7月20日(祝日法発令) 以降の祝日に対応
|
98
|
+
* 2021年の[暦要項](http://eco.mtk.nao.ac.jp/koyomi/yoko/)まで確認(法改正がない限り以降も有効)
|
99
|
+
* 春分の日・秋分の日の計算は2150年まで
|
100
|
+
|
101
|
+
## Author:
|
102
|
+
Masahiro TANAKA
|
103
|
+
|
104
|
+
## Copyright:
|
105
|
+
(C) Copyright 2003-2020 by Masahiro TANAKA
|
106
|
+
This program is free software under MIT license.
|
107
|
+
See LICENSE.txt.
|
108
|
+
NO WARRANTY.
|
109
|
+
|
110
|
+
## Version:
|
111
|
+
2018-04-14 ver 1.4 祝日データ仕様変更、2019,2020年対応
|
112
|
+
2017-12-01 ver 1.3 print_between 関数追加
|
113
|
+
2015-04-11 ver 1.2 hash_year, between 関数追加
|
114
|
+
2014-05-23 ver 1.1 「山の日」追加
|
115
|
+
2012-12-23 ver 1.0 モジュール名を Holiday から HolidayJapan に変更
|
116
|
+
2007-08-02 ver 0.9 リファクタリング
|
117
|
+
2007-03-08 ver 0.8 祝日データクラスを統一、データを配列で記述
|
118
|
+
2006-02-06 ver 0.7 平成19年(西暦2007年)の暦要項 反映(祝日法改正)
|
119
|
+
Holiday.create_table 修正
|
120
|
+
Holiday.list_year 追加
|
121
|
+
2003-10-02 ver 0.6 祝日データ追加
|
122
|
+
2003-09-29 ver 0.5
|
123
|
+
2003-09-22 ver 0.4
|
124
|
+
2003-09-20 ver 0.3
|
125
|
+
2003-09-16 ver 0.2
|
126
|
+
2003-09-15 ver 0.1
|
data/Rakefile
CHANGED
data/holiday_japan.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |gem|
|
|
9
9
|
gem.authors = ["Masahiro TANAKA"]
|
10
10
|
gem.email = ["masa16.tanaka@gmail.com"]
|
11
11
|
gem.summary = %q{Calculate National Holidays of Japan}
|
12
|
-
gem.description = %q{Calculate National Holidays of Japan
|
12
|
+
gem.description = %q{Calculate National Holidays of Japan after 1948}
|
13
13
|
gem.homepage = "http://masa16.github.io/holiday_japan/"
|
14
14
|
gem.license = "MIT"
|
15
15
|
|
data/lib/holiday_japan.rb
CHANGED
@@ -6,57 +6,63 @@ require "date"
|
|
6
6
|
|
7
7
|
module HolidayJapan
|
8
8
|
|
9
|
-
VERSION = "1.
|
9
|
+
VERSION = "1.4.4"
|
10
10
|
|
11
11
|
WEEK1 = 1
|
12
12
|
WEEK2 = 8
|
13
13
|
WEEK3 = 15
|
14
14
|
WEEK4 = 22
|
15
15
|
SUN,MON,TUE,WED,THU,FRU,SAT = (0..6).to_a
|
16
|
-
INF = (defined? Float::INFINITY) ? Float::INFINITY :
|
16
|
+
INF = (defined? Float::INFINITY) ? Float::INFINITY : 1e16
|
17
17
|
|
18
18
|
# 祝日データ: 1948年7月20日以降で有効
|
19
19
|
DATA = [
|
20
|
-
["元日", 1949..INF , 1, 1
|
21
|
-
["成人の日",
|
22
|
-
|
23
|
-
["建国記念の日",1967..INF , 2, 11
|
24
|
-
["
|
25
|
-
["
|
26
|
-
["みどりの日",
|
27
|
-
|
28
|
-
["
|
29
|
-
["
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
["山の日",
|
34
|
-
|
35
|
-
|
36
|
-
["
|
37
|
-
|
38
|
-
["
|
39
|
-
|
40
|
-
["
|
41
|
-
|
42
|
-
|
43
|
-
["
|
44
|
-
|
45
|
-
["
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
proc{|y|
|
51
|
-
|
52
|
-
|
53
|
-
["
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
20
|
+
["元日", [1949..INF , 1, 1 ]],
|
21
|
+
["成人の日", [2000..INF , 1, [WEEK2,MON]],
|
22
|
+
[1949..1999, 1, 15 ]],
|
23
|
+
["建国記念の日",[1967..INF , 2, 11 ]],
|
24
|
+
["昭和の日", [2007..INF , 4, 29 ]],
|
25
|
+
["憲法記念日", [1949..INF , 5, 3 ]],
|
26
|
+
["みどりの日", [2007..INF , 5, 4 ],
|
27
|
+
[1989..2006, 4, 29 ]],
|
28
|
+
["こどもの日", [1949..INF , 5, 5 ]],
|
29
|
+
["海の日", [2020, 7, 23 ],
|
30
|
+
[2021, 7, 22 ],
|
31
|
+
[2003..INF, 7, [WEEK3,MON]],
|
32
|
+
[1996..2002, 7, 20 ]],
|
33
|
+
["山の日", [2020, 8, 10 ],
|
34
|
+
[2021 , 8, 8 ],
|
35
|
+
[2016..INF , 8, 11 ]],
|
36
|
+
["敬老の日", [2003..INF , 9, [WEEK3,MON]],
|
37
|
+
[1966..2002, 9, 15 ]],
|
38
|
+
["体育の日", [2000..2019, 10, [WEEK2,MON]],
|
39
|
+
[1966..1999, 10, 10 ]],
|
40
|
+
["スポーツの日",[2020, 7, 24 ],
|
41
|
+
[2021, 7, 23 ],
|
42
|
+
[2022..INF , 10, [WEEK2,MON]]],
|
43
|
+
["文化の日", [1948..INF , 11, 3 ]],
|
44
|
+
["勤労感謝の日",[1948..INF , 11, 23 ]],
|
45
|
+
["天皇誕生日", [2020..INF , 2, 23 ],
|
46
|
+
[1989..2018, 12, 23 ],
|
47
|
+
[1949..1988, 4, 29 ]],
|
48
|
+
["春分の日",
|
49
|
+
[1980..2099, 3, proc{|y|(20.8431+0.242194*(y-1980)).to_i-((y-1980)/4.0).to_i} ],
|
50
|
+
[1949..1979, 3, proc{|y|(20.8357+0.242194*(y-1980)).to_i-((y-1983)/4.0).to_i} ],
|
51
|
+
[2100..2150, 3, proc{|y|(21.8510+0.242194*(y-1980)).to_i-((y-1980)/4.0).to_i} ],
|
52
|
+
],
|
53
|
+
["秋分の日" ,
|
54
|
+
[1980..2099, 9, proc{|y|(23.2488+0.242194*(y-1980)).to_i-((y-1980)/4.0).to_i} ],
|
55
|
+
[1948..1979, 9, proc{|y|(23.2588+0.242194*(y-1980)).to_i-((y-1983)/4.0).to_i} ],
|
56
|
+
[2100..2150, 9, proc{|y|(24.2488+0.242194*(y-1980)).to_i-((y-1980)/4.0).to_i} ],
|
57
|
+
],
|
58
|
+
["即位礼正殿の儀", [2019, 10, 22 ],
|
59
|
+
[1990, 11, 12 ]],
|
60
|
+
["天皇の即位の日", [2019, 5, 1 ]],
|
61
|
+
["皇太子徳仁親王の結婚の儀", [1993, 6, 9 ]],
|
62
|
+
["昭和天皇の大喪の礼", [1989, 2, 24 ]],
|
63
|
+
["皇太子明仁親王の結婚の儀", [1959, 4, 10 ]]
|
58
64
|
]
|
59
|
-
DATA.each{|x| x
|
65
|
+
DATA.each{|x| x.each{|y| y .freeze}}
|
60
66
|
DATA.freeze
|
61
67
|
TABLE = {}
|
62
68
|
FURIKAE_START = Date.new(1973,4,12).freeze
|
@@ -64,20 +70,26 @@ module HolidayJapan
|
|
64
70
|
module_function
|
65
71
|
|
66
72
|
def holiday_date(year,data)
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
73
|
+
data.each do |item|
|
74
|
+
next if item.kind_of?(String)
|
75
|
+
year_range,mon,day = *item
|
76
|
+
if year_range === year
|
77
|
+
case day
|
78
|
+
when Integer
|
79
|
+
# skip
|
80
|
+
when Array
|
81
|
+
day0,wday = day
|
82
|
+
wday0 = Date.new(year,mon,day0).wday
|
83
|
+
day = day0+(wday-wday0+7)%7
|
84
|
+
when Proc
|
85
|
+
day = day.call(year)
|
74
86
|
else
|
75
|
-
|
87
|
+
raise "invalid holiday data"
|
76
88
|
end
|
77
|
-
|
78
|
-
Date.new( year, mon, day.call(year) )
|
89
|
+
return Date.new( year, mon, day )
|
79
90
|
end
|
80
91
|
end
|
92
|
+
nil
|
81
93
|
end
|
82
94
|
|
83
95
|
def create_table(y)
|