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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: dd7d03465f889396be6264be771d19d0f7a3f71a
4
- data.tar.gz: 5c0f49346d750e16dd3a9a8c3e6a939ebaa6c17a
2
+ SHA256:
3
+ metadata.gz: fa83de54f75e47487ab3a1ade42e1975626626277bfacd7216d6ef49e33a29b1
4
+ data.tar.gz: 33dc6e82aeaaa225235235b5a9c1088316f2edd223fa46f8d1a16ac872fd7a1f
5
5
  SHA512:
6
- metadata.gz: 74ed1f4f406eb301a75a6671baaa52e0276cfc297e389af8b9456f7a88333ea976e407c6083f0c44d57a1ee02e2c5de0394999150248f92f80ac5351f9fded31
7
- data.tar.gz: bd007cbe4385ac145a49c6c1cb5d91ebeff72429032b3fb6da5ebe54600c88952a2166026fee65c5bedbbd3e19259cd401f34ae6fc886c4721b040fe516d4652
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(2018,3,21))
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(2018,3,21))
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 2018'
53
- listing year 2018...
54
- 2018-01-01 Mon 元日
55
- 2018-01-08 Mon 成人の日
56
- 2018-02-11 Sun 建国記念の日
57
- 2018-02-12 Mon 振替休日
58
- 2018-03-21 Wed 春分の日
59
- 2018-04-29 Sun 昭和の日
60
- 2018-04-30 Mon 振替休日
61
- 2018-05-03 Thu 憲法記念日
62
- 2018-05-04 Fri みどりの日
63
- 2018-05-05 Sat こどもの日
64
- 2018-07-16 Mon 海の日
65
- 2018-08-11 Sat 山の日
66
- 2018-09-17 Mon 敬老の日
67
- 2018-09-23 Sun 秋分の日
68
- 2018-09-24 Mon 振替休日
69
- 2018-10-08 Mon 体育の日
70
- 2018-11-03 Sat 文化の日
71
- 2018-11-23 Fri 勤労感謝の日
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(2018)
80
- => [[#<Date: 2018-01-01 ((2458120j,0s,0n),+0s,2299161j)>, "元日"],
81
- [#<Date: 2018-01-08 ((2458127j,0s,0n),+0s,2299161j)>, "成人の日"],
82
- [#<Date: 2018-02-11 ((2458161j,0s,0n),+0s,2299161j)>, "建国記念の日"],
83
- [#<Date: 2018-02-12 ((2458162j,0s,0n),+0s,2299161j)>, "振替休日"],
84
- [#<Date: 2018-03-21 ((2458199j,0s,0n),+0s,2299161j)>, "春分の日"],
85
- [#<Date: 2018-04-29 ((2458238j,0s,0n),+0s,2299161j)>, "昭和の日"],
86
- [#<Date: 2018-04-30 ((2458239j,0s,0n),+0s,2299161j)>, "振替休日"],
87
- [#<Date: 2018-05-03 ((2458242j,0s,0n),+0s,2299161j)>, "憲法記念日"],
88
- [#<Date: 2018-05-04 ((2458243j,0s,0n),+0s,2299161j)>, "みどりの日"],
89
- [#<Date: 2018-05-05 ((2458244j,0s,0n),+0s,2299161j)>, "こどもの日"],
90
- [#<Date: 2018-07-16 ((2458316j,0s,0n),+0s,2299161j)>, "海の日"],
91
- [#<Date: 2018-08-11 ((2458342j,0s,0n),+0s,2299161j)>, "山の日"],
92
- [#<Date: 2018-09-17 ((2458379j,0s,0n),+0s,2299161j)>, "敬老の日"],
93
- [#<Date: 2018-09-23 ((2458385j,0s,0n),+0s,2299161j)>, "秋分の日"],
94
- [#<Date: 2018-09-24 ((2458386j,0s,0n),+0s,2299161j)>, "振替休日"],
95
- [#<Date: 2018-10-08 ((2458400j,0s,0n),+0s,2299161j)>, "体育の日"],
96
- [#<Date: 2018-11-03 ((2458426j,0s,0n),+0s,2299161j)>, "文化の日"],
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(2018)
106
- => {#<Date: 2018-01-01 ((2458120j,0s,0n),+0s,2299161j)>=>"元日",
107
- #<Date: 2018-01-08 ((2458127j,0s,0n),+0s,2299161j)>=>"成人の日",
108
- #<Date: 2018-02-11 ((2458161j,0s,0n),+0s,2299161j)>=>"建国記念の日",
109
- #<Date: 2018-02-12 ((2458162j,0s,0n),+0s,2299161j)>=>"振替休日",
110
- #<Date: 2018-03-21 ((2458199j,0s,0n),+0s,2299161j)>=>"春分の日",
111
- #<Date: 2018-04-29 ((2458238j,0s,0n),+0s,2299161j)>=>"昭和の日",
112
- #<Date: 2018-04-30 ((2458239j,0s,0n),+0s,2299161j)>=>"振替休日",
113
- #<Date: 2018-05-03 ((2458242j,0s,0n),+0s,2299161j)>=>"憲法記念日",
114
- #<Date: 2018-05-04 ((2458243j,0s,0n),+0s,2299161j)>=>"みどりの日",
115
- #<Date: 2018-05-05 ((2458244j,0s,0n),+0s,2299161j)>=>"こどもの日",
116
- #<Date: 2018-07-16 ((2458316j,0s,0n),+0s,2299161j)>=>"海の日",
117
- #<Date: 2018-08-11 ((2458342j,0s,0n),+0s,2299161j)>=>"山の日",
118
- #<Date: 2018-09-17 ((2458379j,0s,0n),+0s,2299161j)>=>"敬老の日",
119
- #<Date: 2018-09-23 ((2458385j,0s,0n),+0s,2299161j)>=>"秋分の日",
120
- #<Date: 2018-09-24 ((2458386j,0s,0n),+0s,2299161j)>=>"振替休日",
121
- #<Date: 2018-10-08 ((2458400j,0s,0n),+0s,2299161j)>=>"体育の日",
122
- #<Date: 2018-11-03 ((2458426j,0s,0n),+0s,2299161j)>=>"文化の日",
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("2018-4-1","2019-3-31")
132
- => {#<Date: 2018-04-29 ((2458238j,0s,0n),+0s,2299161j)>=>"昭和の日",
133
- #<Date: 2018-04-30 ((2458239j,0s,0n),+0s,2299161j)>=>"振替休日",
134
- #<Date: 2018-05-03 ((2458242j,0s,0n),+0s,2299161j)>=>"憲法記念日",
135
- #<Date: 2018-05-04 ((2458243j,0s,0n),+0s,2299161j)>=>"みどりの日",
136
- #<Date: 2018-05-05 ((2458244j,0s,0n),+0s,2299161j)>=>"こどもの日",
137
- #<Date: 2018-07-16 ((2458316j,0s,0n),+0s,2299161j)>=>"海の日",
138
- #<Date: 2018-08-11 ((2458342j,0s,0n),+0s,2299161j)>=>"山の日",
139
- #<Date: 2018-09-17 ((2458379j,0s,0n),+0s,2299161j)>=>"敬老の日",
140
- #<Date: 2018-09-23 ((2458385j,0s,0n),+0s,2299161j)>=>"秋分の日",
141
- #<Date: 2018-09-24 ((2458386j,0s,0n),+0s,2299161j)>=>"振替休日",
142
- #<Date: 2018-10-08 ((2458400j,0s,0n),+0s,2299161j)>=>"体育の日",
143
- #<Date: 2018-11-03 ((2458426j,0s,0n),+0s,2299161j)>=>"文化の日",
144
- #<Date: 2018-11-23 ((2458446j,0s,0n),+0s,2299161j)>=>"勤労感謝の日",
145
- #<Date: 2018-12-23 ((2458476j,0s,0n),+0s,2299161j)>=>"天皇誕生日",
146
- #<Date: 2018-12-24 ((2458477j,0s,0n),+0s,2299161j)>=>"振替休日",
147
- #<Date: 2019-01-01 ((2458485j,0s,0n),+0s,2299161j)>=>"元日",
148
- #<Date: 2019-01-14 ((2458498j,0s,0n),+0s,2299161j)>=>"成人の日",
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(2016,2018).each{|a| c<<a}}'
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
- 2016-01-01,元日
160
- 2016-01-11,成人の日
161
- 2016-02-11,建国記念の日
158
+ 2020-01-01,元日
159
+ 2020-01-13,成人の日
160
+ 2020-02-11,建国記念の日
162
161
  ...
163
- 2018-11-23,勤労感謝の日
164
- 2018-12-23,天皇誕生日
165
- 2018-12-24,振替休日
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
- * 2018年の[暦要項](http://eco.mtk.nao.ac.jp/koyomi/yoko/)まで確認(法改正がない限り以降も有効)
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-2017 by Masahiro TANAKA
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 「山の日」追加
@@ -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
@@ -1 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ task :readme do
4
+ sh "erb -T 1 README.md.erb > README.md"
5
+ end
@@ -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 between 1948..2150}
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
 
@@ -6,57 +6,63 @@ require "date"
6
6
 
7
7
  module HolidayJapan
8
8
 
9
- VERSION = "1.3.0"
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 : 1e34
16
+ INF = (defined? Float::INFINITY) ? Float::INFINITY : 1e16
17
17
 
18
18
  # 祝日データ: 1948年7月20日以降で有効
19
19
  DATA = [
20
- ["元日", 1949..INF , 1, 1 ],
21
- ["成人の日", 1949..1999, 1, 15 ],
22
- ["成人の日", 2000..INF , 1, WEEK2, MON ],
23
- ["建国記念の日",1967..INF , 2, 11 ],
24
- ["天皇誕生日", 2020..INF , 2, 23 ],
25
- ["天皇誕生日", 1949..1988, 4, 29 ],
26
- ["みどりの日", 1989..2006, 4, 29 ],
27
- ["昭和の日", 2007..INF , 4, 29 ],
28
- ["憲法記念日", 1949..INF , 5, 3 ],
29
- ["みどりの日", 2007..INF , 5, 4 ],
30
- ["こどもの日", 1949..INF , 5, 5 ],
31
- ["海の日", 1996..2002, 7, 20 ],
32
- ["海の日", 2003..INF , 7, WEEK3, MON ],
33
- ["山の日", 2016..INF , 8, 11 ],
34
- ["敬老の日", 1966..2002, 9, 15 ],
35
- ["敬老の日", 2003..INF , 9, WEEK3, MON ],
36
- ["体育の日", 1966..1999, 10, 10 ],
37
- ["体育の日", 2000..INF , 10, WEEK2, MON ],
38
- ["文化の日", 1948..INF , 11, 3 ],
39
- ["勤労感謝の日",1948..INF , 11, 23 ],
40
- ["天皇誕生日", 1989..2018, 12, 23 ],
41
- ["春分の日", 1949..1979, 3,
42
- proc{|y|Integer(20.8357+0.242194*(y-1980))-Integer((y-1983)/4.0)} ],
43
- ["春分の日", 1980..2099, 3,
44
- proc{|y|Integer(20.8431+0.242194*(y-1980))-Integer((y-1980)/4.0)} ],
45
- ["春分の日", 2100..2150, 3,
46
- proc{|y|Integer(21.8510+0.242194*(y-1980))-Integer((y-1980)/4.0)} ],
47
- ["秋分の日" , 1948..1979, 9,
48
- proc{|y|Integer(23.2588+0.242194*(y-1980))-Integer((y-1983)/4.0)} ],
49
- ["秋分の日" , 1980..2099, 9,
50
- proc{|y|Integer(23.2488+0.242194*(y-1980))-Integer((y-1980)/4.0)} ],
51
- ["秋分の日" , 2100..2150, 9,
52
- proc{|y|Integer(24.2488+0.242194*(y-1980))-Integer((y-1980)/4.0)} ],
53
- ["皇太子明仁親王の結婚の儀", 1959..1959, 4, 10 ],
54
- ["昭和天皇の大喪の礼", 1989..1989, 2, 24 ],
55
- ["即位礼正殿の儀", 1990..1990, 11, 12 ],
56
- ["皇太子徳仁親王の結婚の儀", 1993..1993, 6, 9 ],
57
- ["即位礼正殿の儀", 2019..2019, 5, 1 ],
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[0].freeze; x.freeze }
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
- year_range,mon,day,wday = data[1..4]
68
- if year_range === year
69
- case day
70
- when Integer
71
- if wday
72
- wday0 = Date.new(year,mon,day).wday
73
- Date.new( year, mon, day+(wday-wday0+7)%7 )
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
- Date.new( year, mon, day )
87
+ raise "invalid holiday data"
76
88
  end
77
- when Proc
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)