holiday_japan 1.2.5 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +89 -76
- data/lib/holiday_japan.rb +28 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd7d03465f889396be6264be771d19d0f7a3f71a
|
4
|
+
data.tar.gz: 5c0f49346d750e16dd3a9a8c3e6a939ebaa6c17a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74ed1f4f406eb301a75a6671baaa52e0276cfc297e389af8b9456f7a88333ea976e407c6083f0c44d57a1ee02e2c5de0394999150248f92f80ac5351f9fded31
|
7
|
+
data.tar.gz: bd007cbe4385ac145a49c6c1cb5d91ebeff72429032b3fb6da5ebe54600c88952a2166026fee65c5bedbbd3e19259cd401f34ae6fc886c4721b040fe516d4652
|
data/README.md
CHANGED
@@ -4,7 +4,8 @@
|
|
4
4
|
([RubyGems](https://rubygems.org/gems/holiday_japan))
|
5
5
|
|
6
6
|
## 特徴
|
7
|
-
* 1948年7月20
|
7
|
+
* 1948年7月20日以降の日本の国民の祝日、振替休日、および国民の休日を計算して判定。
|
8
|
+
* スクリプトコード([holiday_japan.rb](https://github.com/masa16/holiday_japan/blob/master/lib/holiday_japan.rb))は、祝日データを含めて200行弱とコンパクト。
|
8
9
|
|
9
10
|
(date2 の holiday.rb と比較して)
|
10
11
|
* 祝日をキャッシュすることにより、大量の日付について祝日判定する場合でも高速に動作
|
@@ -34,108 +35,119 @@
|
|
34
35
|
* `check(date)` ― Dateクラスのオブジェクトによる祝日判定
|
35
36
|
|
36
37
|
```ruby
|
37
|
-
HolidayJapan.check(Date.new(
|
38
|
+
HolidayJapan.check(Date.new(2018,3,21))
|
38
39
|
=> true
|
39
40
|
```
|
40
41
|
|
41
42
|
* `name(date)` ― 日付が祝日の場合は祝日名を返し、祝日でなければ nil を返す。
|
42
43
|
|
43
44
|
```ruby
|
44
|
-
HolidayJapan.name(Date.new(
|
45
|
+
HolidayJapan.name(Date.new(2018,3,21))
|
45
46
|
=> "春分の日"
|
46
47
|
```
|
47
48
|
|
48
49
|
* `print_year(year)` ― ある年の祝日一覧をプリント
|
49
50
|
|
50
51
|
```
|
51
|
-
$ ruby -r holiday_japan -e 'HolidayJapan.print_year
|
52
|
-
listing year
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
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 振替休日
|
70
74
|
```
|
71
75
|
|
72
76
|
* `list_year(year)` ― ある年について、 [日付, 祝日名] のArrayを返す
|
73
77
|
|
74
78
|
```ruby
|
75
|
-
HolidayJapan.list_year(
|
76
|
-
=> [[#<Date:
|
77
|
-
[#<Date:
|
78
|
-
[#<Date:
|
79
|
-
[#<Date:
|
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:
|
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)>, "振替休日"]]
|
93
100
|
```
|
94
101
|
|
95
102
|
* `hash_year(year)` ― ある年について、 {日付=>祝日名} のHashを返す
|
96
103
|
|
97
104
|
```ruby
|
98
|
-
HolidayJapan.hash_year(
|
99
|
-
=> {#<Date:
|
100
|
-
#<Date:
|
101
|
-
#<Date:
|
102
|
-
#<Date:
|
103
|
-
#<Date:
|
104
|
-
#<Date:
|
105
|
-
#<Date:
|
106
|
-
#<Date:
|
107
|
-
#<Date:
|
108
|
-
#<Date:
|
109
|
-
#<Date:
|
110
|
-
#<Date:
|
111
|
-
#<Date:
|
112
|
-
#<Date:
|
113
|
-
#<Date:
|
114
|
-
#<Date:
|
115
|
-
#<Date:
|
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)>=>"振替休日"}
|
116
126
|
```
|
117
127
|
|
118
128
|
* `between(from_date,to_date)` ― from_date から to_date までの祝日について、{日付=>祝日名}のHashを返す
|
119
129
|
|
120
130
|
```ruby
|
121
|
-
HolidayJapan.between(
|
122
|
-
=> {#<Date:
|
123
|
-
#<Date:
|
124
|
-
#<Date:
|
125
|
-
#<Date:
|
126
|
-
#<Date:
|
127
|
-
#<Date:
|
128
|
-
#<Date:
|
129
|
-
#<Date:
|
130
|
-
#<Date:
|
131
|
-
#<Date:
|
132
|
-
#<Date:
|
133
|
-
#<Date:
|
134
|
-
#<Date: 2018-
|
135
|
-
#<Date: 2018-
|
136
|
-
#<Date: 2018-
|
137
|
-
#<Date:
|
138
|
-
#<Date:
|
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)>=>"春分の日"}
|
139
151
|
```
|
140
152
|
|
141
153
|
### 祝日データをCSVに出力
|
@@ -169,6 +181,7 @@
|
|
169
181
|
NO WARRANTY.
|
170
182
|
|
171
183
|
## Version:
|
184
|
+
2017-12-01 ver 1.3 print_between 関数追加
|
172
185
|
2015-04-11 ver 1.2 hash_year, between 関数追加
|
173
186
|
2014-05-23 ver 1.1 「山の日」追加
|
174
187
|
2012-12-23 ver 1.0 モジュール名を Holiday から HolidayJapan に変更
|
data/lib/holiday_japan.rb
CHANGED
@@ -6,7 +6,7 @@ require "date"
|
|
6
6
|
|
7
7
|
module HolidayJapan
|
8
8
|
|
9
|
-
VERSION = "1.
|
9
|
+
VERSION = "1.3.0"
|
10
10
|
|
11
11
|
WEEK1 = 1
|
12
12
|
WEEK2 = 8
|
@@ -21,7 +21,7 @@ module HolidayJapan
|
|
21
21
|
["成人の日", 1949..1999, 1, 15 ],
|
22
22
|
["成人の日", 2000..INF , 1, WEEK2, MON ],
|
23
23
|
["建国記念の日",1967..INF , 2, 11 ],
|
24
|
-
["天皇誕生日",
|
24
|
+
["天皇誕生日", 2020..INF , 2, 23 ],
|
25
25
|
["天皇誕生日", 1949..1988, 4, 29 ],
|
26
26
|
["みどりの日", 1989..2006, 4, 29 ],
|
27
27
|
["昭和の日", 2007..INF , 4, 29 ],
|
@@ -53,7 +53,8 @@ module HolidayJapan
|
|
53
53
|
["皇太子明仁親王の結婚の儀", 1959..1959, 4, 10 ],
|
54
54
|
["昭和天皇の大喪の礼", 1989..1989, 2, 24 ],
|
55
55
|
["即位礼正殿の儀", 1990..1990, 11, 12 ],
|
56
|
-
["皇太子徳仁親王の結婚の儀", 1993..1993, 6, 9 ]
|
56
|
+
["皇太子徳仁親王の結婚の儀", 1993..1993, 6, 9 ],
|
57
|
+
["即位礼正殿の儀", 2019..2019, 5, 1 ],
|
57
58
|
]
|
58
59
|
DATA.each{|x| x[0].freeze; x.freeze }
|
59
60
|
DATA.freeze
|
@@ -135,8 +136,24 @@ module HolidayJapan
|
|
135
136
|
end
|
136
137
|
|
137
138
|
def between(from_date,to_date)
|
138
|
-
|
139
|
-
|
139
|
+
case from_date
|
140
|
+
when String
|
141
|
+
from_date = Date.parse(from_date)
|
142
|
+
when Integer
|
143
|
+
from_date = Date.new(from_date,1,1)
|
144
|
+
when Date
|
145
|
+
else
|
146
|
+
raise ArgumentError, "invalid type fpr from_date"
|
147
|
+
end
|
148
|
+
case to_date
|
149
|
+
when String
|
150
|
+
to_date = Date.parse(to_date)
|
151
|
+
when Integer
|
152
|
+
to_date = Date.new(to_date,12,31)
|
153
|
+
when Date
|
154
|
+
else
|
155
|
+
raise ArgumentError, "invalid type fpr to_date"
|
156
|
+
end
|
140
157
|
if from_date > to_date
|
141
158
|
raise ArgumentError, "to_date is earlier than from_date"
|
142
159
|
end
|
@@ -173,6 +190,12 @@ module HolidayJapan
|
|
173
190
|
_print_year(year)
|
174
191
|
end
|
175
192
|
end
|
193
|
+
|
194
|
+
def print_between(from_date,to_date)
|
195
|
+
between(from_date,to_date).each do |y|
|
196
|
+
puts "#{y[0].strftime('%Y-%m-%d %a')} #{y[1]}"
|
197
|
+
end
|
198
|
+
end
|
176
199
|
end
|
177
200
|
|
178
201
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: holiday_japan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masahiro TANAKA
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Calculate National Holidays of Japan between 1948..2150
|
14
14
|
email:
|
@@ -44,7 +44,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
44
44
|
version: '0'
|
45
45
|
requirements: []
|
46
46
|
rubyforge_project:
|
47
|
-
rubygems_version: 2.6.
|
47
|
+
rubygems_version: 2.6.13
|
48
48
|
signing_key:
|
49
49
|
specification_version: 4
|
50
50
|
summary: Calculate National Holidays of Japan
|