jpdate 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +99 -0
- data/Rakefile +2 -0
- data/bin/jcal +148 -0
- data/jpdate.gemspec +23 -0
- data/lib/jpdate/era.rb +47 -0
- data/lib/jpdate/holiday.rb +210 -0
- data/lib/jpdate/version.rb +8 -0
- data/lib/jpdate.rb +26 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6488a5d9d1384f39e50eee11dbca82e75ecfb476
|
4
|
+
data.tar.gz: a515ae8cfa0a8032eab3b6643427cc9e8e378660
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b172bbfe8fff38e46085085c4b3156a8a2d0850d9506d7b56610fd9604bfe5750de06d897063bce6b2fa9166d7662e8522378d953e4a662b09aa97f3ba9edf3c
|
7
|
+
data.tar.gz: 5fd5233a399a631594830bec19039078fa35bf14c7ebd592c0758ef65bb11fa05a7cfe6d70613d5851a69092198e762924cde7fb7296cab5ffb0d6a24ccbaad5
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 zariganitosh
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
#jcalコマンド & JPDateクラス
|
2
|
+
|
3
|
+
* jcal : 日本の祝日もちゃんと表示するカレンダー出力コマンド。
|
4
|
+
* JPDate: 祝日名称と年号を返すクラス&モジュール。
|
5
|
+
* 以下の法律に準拠
|
6
|
+
* 太政官布告 五節ヲ廃シ祝日ヲ定ム
|
7
|
+
* 太政官布告 年中祭日祝日ノ休暇日ヲ定ム
|
8
|
+
* 勅令 休日ニ關スル件
|
9
|
+
* 法律 国民の祝日に関する法律
|
10
|
+
|
11
|
+
* 明治6年・1973年から2099年までのカレンダーに対応。(将来のカレンダーには現行の法律を適用)
|
12
|
+
* 日本の暦は、明治6年・1973年1月1日より太陽暦で動いている。(それ以前は太陰暦)
|
13
|
+
* jcal・JPDateは、太陽暦以降の祝日に関する法律に可能な限り準拠しようとしている。
|
14
|
+
|
15
|
+
##Installation
|
16
|
+
|
17
|
+
$ git clone https://github.com/zarigani/jcal
|
18
|
+
$ cd jcal
|
19
|
+
$ sudo gem install jpdate
|
20
|
+
|
21
|
+
または、
|
22
|
+
|
23
|
+
# Click "Download ZIP" button in the GitHub(https://github.com/zarigani/jcal).
|
24
|
+
|
25
|
+
$ unzip jcal-master.zip
|
26
|
+
$ cd jcal-master
|
27
|
+
$ sudo gem install jpdate
|
28
|
+
|
29
|
+
##Usage(jcal)
|
30
|
+
|
31
|
+
Usage: jcal [options] [yyyy|mm] [yyyy|mm] [yyyy|mm]
|
32
|
+
|
33
|
+
-y[NUM] List NUM years.(0-10)
|
34
|
+
-m[NUM] Show NUM months.(0-12)
|
35
|
+
-e List with the name of Japanese era.
|
36
|
+
|
37
|
+
Example:
|
38
|
+
jcal # Show monthly calendar of this month.
|
39
|
+
jcal 8 # Show monthly calendar of Aug.
|
40
|
+
jcal 8 2 # Show monthly calendar from Aug. to Feb. of next year.
|
41
|
+
jcal 2010 # Show all monthly calendar of 2010.
|
42
|
+
jcal -y # Show all monthly calendar of this year.
|
43
|
+
jcal -y5 # List from this year to after 5 years.
|
44
|
+
jcal 2011 2012 # List from 2011 to 2012.
|
45
|
+
jcal -m # Show monthly calendar from last month to next month.
|
46
|
+
jcal -m6 2010 1 # Show monthly calendar from Jan.2010 to Jun.2010.
|
47
|
+
jcal 2010 2 8 # Show monthly calendar from Feb.2010 to Aug.2010.
|
48
|
+
|
49
|
+
##Usage(JPDate, JPDate::Holiday, JPDate::Era)
|
50
|
+
|
51
|
+
require 'jpdate'
|
52
|
+
|
53
|
+
JPDate.new(2014, 9 ,23).holiday
|
54
|
+
=> "秋分の日"
|
55
|
+
|
56
|
+
JPDate.new(2014, 9 ,24).holiday
|
57
|
+
=> nil
|
58
|
+
|
59
|
+
JPDate::Holiday.list(2014..2015)
|
60
|
+
=> {#<Date: 2014-01-01 ((2456659j,0s,0n),+0s,2299161j)>=>"元旦",
|
61
|
+
#<Date: 2014-01-13 ((2456671j,0s,0n),+0s,2299161j)>=>"成人の日",
|
62
|
+
#<Date: 2014-02-11 ((2456700j,0s,0n),+0s,2299161j)>=>"建国記念日",
|
63
|
+
#<Date: 2014-03-21 ((2456738j,0s,0n),+0s,2299161j)>=>"春分の日"
|
64
|
+
...中略...
|
65
|
+
#<Date: 2015-11-03 ((2457330j,0s,0n),+0s,2299161j)>=>"文化の日",
|
66
|
+
#<Date: 2015-11-23 ((2457350j,0s,0n),+0s,2299161j)>=>"勤労感謝の日",
|
67
|
+
#<Date: 2015-12-23 ((2457380j,0s,0n),+0s,2299161j)>=>"天皇誕生日"}
|
68
|
+
|
69
|
+
JPDate::Era.name_year(1989)
|
70
|
+
=> ["昭和64年", "平成元年"]
|
71
|
+
|
72
|
+
JPDate::Era.name_year(1989, 1)
|
73
|
+
=> ["昭和64年", "平成元年"]
|
74
|
+
|
75
|
+
JPDate::Era.name_year(1989, 2)
|
76
|
+
=> ["平成元年"]
|
77
|
+
|
78
|
+
JPDate::Era.name_year(1989, 1, 7)
|
79
|
+
=> ["昭和64年"]
|
80
|
+
|
81
|
+
JPDate::Era.name_year(1989, 1, 8)
|
82
|
+
=> ["平成元年"]
|
83
|
+
|
84
|
+
JPDate::Era.short_name_year(1989)
|
85
|
+
=> ["S64", "H01"]
|
86
|
+
|
87
|
+
##More Document
|
88
|
+
|
89
|
+
###gemサーバーを起動する方法
|
90
|
+
$ gem server
|
91
|
+
|
92
|
+
* gemサーバー起動後、以下のURLを開く。
|
93
|
+
* http://0.0.0.0:8808/doc_root/jpdate-0.1/
|
94
|
+
|
95
|
+
###Rdocを生成する方法
|
96
|
+
|
97
|
+
$ cd ~/Desktop
|
98
|
+
$ rdoc $(dirname `gem which jpdate`)
|
99
|
+
$ open doc/index.html
|
data/Rakefile
ADDED
data/bin/jcal
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
#!/usr/bin/ruby -W0
|
2
|
+
# encoding: utf-8
|
3
|
+
require 'jpdate'
|
4
|
+
|
5
|
+
# JcalモジュールのためのStringクラスrefine拡張
|
6
|
+
module JcalEx
|
7
|
+
refine String do
|
8
|
+
def full_length() count("^ -~。-゚") end
|
9
|
+
def length_ja() length + full_length end
|
10
|
+
def ljust_ja(width, padstr=' ') align_ja(:ljust, width, padstr) end
|
11
|
+
def rjust_ja(width, padstr=' ') align_ja(:rjust, width, padstr) end
|
12
|
+
def center_ja(width, padstr=' ') align_ja(:center, width, padstr) end
|
13
|
+
|
14
|
+
def align_ja(method, width, padstr, dummy='A'*length_ja)
|
15
|
+
if full_length == 0
|
16
|
+
send(method, width, padstr)
|
17
|
+
else
|
18
|
+
dummy.succ!.empty? && break while padstr.include?(dummy)
|
19
|
+
dummy.send(method, width, padstr).sub(dummy, self)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
using JcalEx
|
26
|
+
|
27
|
+
# カレンダーを描画する
|
28
|
+
module Jcal
|
29
|
+
WEEK_JA = %w(日 月 火 水 木 金 土)
|
30
|
+
|
31
|
+
module_function
|
32
|
+
|
33
|
+
def render_matrix(y, m)
|
34
|
+
title = (sprintf("#{JPDate::Era.name_year(y, m).join('/')} %4d年 %2d月", y, m)).center_ja(16 * 7)
|
35
|
+
week_names = WEEK_JA.map {|s| s.rjust_ja(16)}
|
36
|
+
week_names[0] = "\e[31m#{week_names[0]}\e[0m"
|
37
|
+
week_names[6] = "\e[36m#{week_names[6]}\e[0m"
|
38
|
+
puts title, week_names.join
|
39
|
+
|
40
|
+
start_date = JPDate.new(y, m) - JPDate.new(y, m).wday
|
41
|
+
end_date = JPDate.new(y, m, -1) + (6 - JPDate.new(y, m, -1).wday)
|
42
|
+
(start_date..end_date).each_slice(7) do |week|
|
43
|
+
week.each do |date|
|
44
|
+
today_marker = date == Date.today ? "\e[7m" : ''
|
45
|
+
holiday_name = date.holiday.to_s.rjust_ja(14)
|
46
|
+
fgcolor = case
|
47
|
+
when date.month != m then 37
|
48
|
+
when date.wday == 0, date.holiday then 31
|
49
|
+
when date.wday == 6 then 36
|
50
|
+
else 0
|
51
|
+
end
|
52
|
+
printf "\e[%dm%s%s%2d\e[0m", fgcolor, holiday_name, today_marker, date.day
|
53
|
+
end
|
54
|
+
puts
|
55
|
+
end
|
56
|
+
puts
|
57
|
+
end
|
58
|
+
|
59
|
+
def render_list(y, col, era)
|
60
|
+
date366 = (Date.new(2004, 1, 1)..Date.new(2004, 12, 31)).to_a
|
61
|
+
list366 = Array.new(366, '')
|
62
|
+
(y...y + col).each do |y|
|
63
|
+
date366.each_with_index do |d366, i|
|
64
|
+
date = JPDate.new(y, d366.month, d366.day) rescue nil
|
65
|
+
today_marker = (date == Date.today) ? "\e[7m" : '' rescue ''
|
66
|
+
era_name = date.short_era.last.ljust(4) rescue ' ' * 4 if era
|
67
|
+
date_text = date.strftime("%Y-%m-%d") rescue ' ' * 10
|
68
|
+
week_name = WEEK_JA[date.wday] rescue ' ' * 2
|
69
|
+
holiday_name = date.holiday.to_s.ljust_ja(12) rescue ' ' * 12
|
70
|
+
fgcolor = case
|
71
|
+
when date == nil then 0
|
72
|
+
when date.wday == 0, date.holiday then 31
|
73
|
+
when date.wday == 6 then 36
|
74
|
+
else 0
|
75
|
+
end
|
76
|
+
list366[i] += "\e[%dm%s%s%s%s\e[0;%dm%s\e[0m" % [fgcolor, today_marker, era_name, date_text, week_name, fgcolor, holiday_name]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
list366.each {|list| puts list}
|
80
|
+
end
|
81
|
+
|
82
|
+
def matrix(base_year, start_month, end_month=start_month)
|
83
|
+
base_year -= 1 if start_month <= 0
|
84
|
+
start_month, end_month = *[start_month, end_month].map {|i| i %= 12; i == 0 ? 12 : i}
|
85
|
+
if start_month <= end_month
|
86
|
+
(start_month..end_month).each {|i| render_matrix(base_year , i)}
|
87
|
+
else
|
88
|
+
(start_month..12 ).each {|i| render_matrix(base_year , i)}
|
89
|
+
( 1..end_month).each {|i| render_matrix(base_year + 1, i)}
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def list(base_year, column, era)
|
94
|
+
render_list(base_year, [column, 10].min, era)
|
95
|
+
end
|
96
|
+
|
97
|
+
end # module Jcal
|
98
|
+
|
99
|
+
require 'optparse'
|
100
|
+
|
101
|
+
# オプション解析
|
102
|
+
options = {}
|
103
|
+
OptionParser.new do |opt|
|
104
|
+
opt.banner = 'Usage: jcal [options] [yyyy|mm] [yyyy|mm] [yyyy|mm]'
|
105
|
+
opt.separator('')
|
106
|
+
opt.on('-y[NUM]', 'List NUM years.(0-10)') {|v| options[:years] = v.to_i}
|
107
|
+
opt.on('-m[NUM]', 'Show NUM months.(0-12)') {|v| options[:months] = v.to_i}
|
108
|
+
opt.on('-e' , 'List with the name of Japanese era.') {|v| options[:era] = v}
|
109
|
+
opt.separator('')
|
110
|
+
opt.on('Example:',
|
111
|
+
' jcal # Show monthly calendar of this month.',
|
112
|
+
' jcal 8 # Show monthly calendar of Aug.',
|
113
|
+
' jcal 8 2 # Show monthly calendar from Aug. to Feb. of next year.',
|
114
|
+
' jcal 2010 # Show all monthly calendar of 2010.',
|
115
|
+
' jcal -y # Show all monthly calendar of this year.',
|
116
|
+
' jcal -y5 # List from this year to after 5 years.',
|
117
|
+
' jcal 2011 2012 # List from 2011 to 2012.',
|
118
|
+
' jcal -m # Show monthly calendar from last month to next month.',
|
119
|
+
' jcal -m6 2010 1 # Show monthly calendar from Jan.2010 to Jun.2010.',
|
120
|
+
' jcal 2010 2 8 # Show monthly calendar from Feb.2010 to Aug.2010.',
|
121
|
+
)
|
122
|
+
begin
|
123
|
+
opt.parse!(ARGV)
|
124
|
+
rescue => e
|
125
|
+
puts e
|
126
|
+
exit
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# 引数解析
|
131
|
+
y = ARGV.map(&:to_i).select {|i| i > 12 }
|
132
|
+
m = ARGV.map(&:to_i).select {|i| i <= 12 }
|
133
|
+
m.map! {|i| i == 0 ? Date.today.month : i}
|
134
|
+
|
135
|
+
m = [1, 12] if y.size == 1 && m.empty? && options.empty? # 西暦1個・月0個・オプションなしは、12カ月分表示
|
136
|
+
y[0] ||= Date.today.year
|
137
|
+
m[0] ||= Date.today.month
|
138
|
+
m = [m[0] - 1, m[0] + 1] if options.key?(:months) && options[:months] == 0 # -m引数なしは、前月から翌月まで表示
|
139
|
+
m = [m[0] , m[0] + options[:months] - 1] if options.key?(:months) && options[:months] > 0 # -m引数ありは、指定した月数分を表示
|
140
|
+
(y[0] = options[:years]; options[:years] = 0) if options.key?(:years) && options[:years] >= 1900 # -y西暦なら、西暦と解釈
|
141
|
+
m = [1, 12] if options.key?(:years) && options[:years] <= 1 # -y指定期間が1年以下は、12カ月分表示
|
142
|
+
options[:years] ||= (y[1] - y[0]).abs + 1 if y.size == 2 && (options.empty? || options[:era]) # 西暦2個・月0個・オプションなしは、-yに期間を追加
|
143
|
+
|
144
|
+
if options.key?(:years) && options[:years] >= 2
|
145
|
+
Jcal::list(y.min, options[:years], options[:era])
|
146
|
+
else
|
147
|
+
Jcal::matrix(y[0], *m)
|
148
|
+
end
|
data/jpdate.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'jpdate/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "jpdate"
|
8
|
+
spec.version = JPDate::VERSION
|
9
|
+
spec.authors = ["zariganitosh"]
|
10
|
+
spec.email = ["XXXX@example.com"]
|
11
|
+
spec.summary = %q{日本の祝日を出力するJPDateクラス}
|
12
|
+
spec.description = %q{明治6年1月1日以降の日本の祝日を出力可能なJPDateクラス}
|
13
|
+
spec.homepage = "https://github.com/zarigani/jcal"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
data/lib/jpdate/era.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'date'
|
3
|
+
|
4
|
+
class JPDate < Date
|
5
|
+
module Era
|
6
|
+
ERAS = [
|
7
|
+
['1868-10-23', '1912-07-30', '明治', :M],
|
8
|
+
['1912-07-30', '1926-12-25', '大正', :T],
|
9
|
+
['1926-12-25', '1989-01-07', '昭和', :S],
|
10
|
+
['1989-01-08', '9999-12-31', '平成', :H],
|
11
|
+
]
|
12
|
+
|
13
|
+
module_function
|
14
|
+
|
15
|
+
# 和暦の元号と年を返す
|
16
|
+
# ===Example:
|
17
|
+
# JPDate::Era.name_year(2014) # => ["平成26年"]
|
18
|
+
# JPDate::Era.name_year(1926) # => ["大正15年", "昭和元年"]
|
19
|
+
# JPDate::Era.name_year(1926, 11) # => ["大正15年"]
|
20
|
+
# JPDate::Era.name_year(1926, 12) # => ["大正15年", "昭和元年"]
|
21
|
+
# JPDate::Era.name_year(1926, 12, 24) # => ["大正15年"]
|
22
|
+
# JPDate::Era.name_year(1926, 12, 25) # => ["大正15年", "昭和元年"]
|
23
|
+
# JPDate::Era.name_year(1926, 12, 26) # => ["昭和元年"]
|
24
|
+
# JPDate::Era.name_year(1926, 12, 26, human: false) # => ["昭和1年"]
|
25
|
+
# JPDate::Era.name_year(1927, format: '%s%02d年') # => ["昭和02年"]
|
26
|
+
def name_year(y, m=nil, d=nil, format: '%s%d年', human: true, short: false)
|
27
|
+
dates = [Date.new(y, m || 1, d || 1), Date.new(y, m || -1, d || -1)]
|
28
|
+
eras = ERAS.select do |era_s, era_e|
|
29
|
+
(0..1).inject(false) {|t, i| t || Date.parse(era_s) <= dates[i] && dates[i] <= Date.parse(era_e)}
|
30
|
+
end
|
31
|
+
eras.map do |s, e, v, initial|
|
32
|
+
era_year = y - Date.parse(s).year + 1
|
33
|
+
res = sprintf(format, short ? initial : v, era_year)
|
34
|
+
human ? res.sub(/(\D+)0*1(\D+|$)/, '\1元\2') : res
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# 和暦のアルファベットの元号と年を返す
|
39
|
+
# ===Example:
|
40
|
+
# JPDate::Era.short_name_year(2014) # => ["H26"]
|
41
|
+
# JPDate::Era.short_name_year(1926) # => ["T15", "S01"]
|
42
|
+
def short_name_year(y, m=nil, d=nil)
|
43
|
+
name_year(y, m, d, format: '%s%02d', human: false, short: true)
|
44
|
+
end
|
45
|
+
|
46
|
+
end # module Era
|
47
|
+
end # class JPDate < Date
|
@@ -0,0 +1,210 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'date'
|
3
|
+
|
4
|
+
class JPDate < Date
|
5
|
+
# ====日本の太陽暦の始まり
|
6
|
+
# 明治5年11月9日・1872年12月9日施行 太政官布告第337号 改暦ノ布告
|
7
|
+
# 「今般太陰曆ヲ廢シ太陽曆御頒行相成候ニ付來ル12月3日ヲ以テ明治6年1月1日ト被定候事」
|
8
|
+
# 太陰暦 太陽暦 西暦
|
9
|
+
# 明治5年12月 2日 1872年12月31日 太陰暦ここまで
|
10
|
+
# 明治5年12月 3日 明治6年 1月 1日 1873年 1月 1日 太陽暦ここから
|
11
|
+
# JPDate::Holidayクラスは、太陽暦 明治6年・1873年1月1日以降の日本の祝日を扱う
|
12
|
+
# ====以下の法律に準拠する
|
13
|
+
# * 五節ヲ廃シ祝日ヲ定ム
|
14
|
+
# * 年中祭日祝日ノ休暇日ヲ定ム
|
15
|
+
# * 休日ニ關スル件
|
16
|
+
# * 国民の祝日に関する法律
|
17
|
+
class Holiday
|
18
|
+
# 祝日情報テーブル
|
19
|
+
HOLIDAYS = [
|
20
|
+
# 明治 6年 1873年 1月 4日施行 太政官布告第1号 五節ヲ廃シ祝日ヲ定ム
|
21
|
+
{month:1, day:29, term:1873..1873, name:'神武天皇即位日'},
|
22
|
+
|
23
|
+
# 明治 6年 1873年10月14日施行 太政官布告第344号 年中祭日祝日ノ休暇日ヲ定ム
|
24
|
+
# 明治11年 1878年 6月 5日施行 太政官布告第 23号 年中祭日祝日ノ休暇日ヲ定ム(改正)
|
25
|
+
# 明治12年 1879年 7月 5日施行 太政官布告第 27号 年中祭日祝日ノ休暇日ヲ定ム(改正)
|
26
|
+
{month:1, day:3, term:1874..1912, name:'元始祭'},
|
27
|
+
{month:1, day:5, term:1874..1912, name:'新年宴會'},
|
28
|
+
{month:1, day:30, term:1874..1912, name:'孝明天皇祭'},
|
29
|
+
{month:2, day:11, term:1874..1912, name:'紀元節'},
|
30
|
+
{month:3, day:'spring_day',term:1879..1912, name:'春季皇靈祭'},# 1878年6月5日追加
|
31
|
+
{month:4, day:3, term:1874..1912, name:'神武天皇祭'},
|
32
|
+
{month:9, day:'autumn_day',term:1878..1911, name:'秋季皇靈祭'},# 1878年6月5日追加
|
33
|
+
{month:9, day:17, term:1874..1878, name:'神嘗祭'},
|
34
|
+
{month:10, day:17, term:1879..1911, name:'神嘗祭'}, # 1879年7月5日修正
|
35
|
+
{month:11, day:3, term:1873..1911, name:'天長節'},
|
36
|
+
{month:11, day:23, term:1873..1911, name:'新嘗祭'},
|
37
|
+
|
38
|
+
# 四方節について
|
39
|
+
# 四方節(1月1日)は紀元節・天長節・明治節とともに四大節の1つだが
|
40
|
+
# 実は法令で定められた休日ではなく、年始の習慣としての休日であった
|
41
|
+
# (現在の1月2日、3日が慣例的に休日となっている扱いと似ている)
|
42
|
+
|
43
|
+
# 大正元年 1912年 9月 4日施行 勅令第 19号 休日ニ關スル件
|
44
|
+
# 大正 2年 1913年 7月16日施行 勅令第259号 休日ニ關スル件(改正)
|
45
|
+
# 昭和 2年 1927年 3月 4日施行 勅令第 25号 休日ニ關スル件(改正)
|
46
|
+
{month:1, day:3, term:1913..1948, name:'元始祭'},
|
47
|
+
{month:1, day:5, term:1913..1948, name:'新年宴會'},
|
48
|
+
{month:2, day:11, term:1913..1948, name:'紀元節'},
|
49
|
+
{month:3, day:'spring_day',term:1913..1948, name:'春季皇靈祭'},
|
50
|
+
{month:4, day:3, term:1913..1948, name:'神武天皇祭'},
|
51
|
+
{month:4, day:29, term:1927..1948, name:'天長節'}, # 1927年3月4日改正
|
52
|
+
{month:7, day:30, term:1913..1926, name:'明治天皇祭'},
|
53
|
+
{month:8, day:31, term:1913..1926, name:'天長節'},
|
54
|
+
{month:9, day:'autumn_day',term:1912..1947, name:'秋季皇靈祭'},
|
55
|
+
{month:10, day:17, term:1912..1947, name:'神嘗祭'},
|
56
|
+
{month:10, day:31, term:1913..1926, name:'天長節祝日'},# 1913年7月16日改正
|
57
|
+
{month:11, day:3, term:1927..1947, name:'明治節'}, # 1927年3月4日改正
|
58
|
+
{month:11, day:23, term:1912..1947, name:'新嘗祭'},
|
59
|
+
{month:12, day:25, term:1927..1947, name:'大正天皇際'},# 1927年3月4日改正
|
60
|
+
|
61
|
+
# 昭和23年 1948年 7月20日公布・施行 法律第178号 国民の祝日に関する法律
|
62
|
+
# 昭和41年 1966年 6月25日公布・施行 法律第 86号 国民の祝日に関する法律(改正)
|
63
|
+
# 昭和48年 1973年 4月12日公布・施行 法律第 10号 国民の祝日に関する法律(改正) 振替休日
|
64
|
+
# 昭和60年 1985年12月27日公布・施行 法律第103号 国民の祝日に関する法律(改正) 国民の休日
|
65
|
+
# 平成元年 1989年 2月17日公布・施行 法律第 5号 国民の祝日に関する法律(改正)
|
66
|
+
# 平成 7年 1995年 3月 8日公布・平成 8年 1996年1月1日施行 法律第 22号 国民の祝日に関する法律(改正)
|
67
|
+
# 平成10年 1998年10月21日公布・平成12年 2000年1月1日施行 法律第141号 国民の祝日に関する法律(改正)
|
68
|
+
# 平成13年 2001年 6月22日公布・平成15年 2003年1月1日施行 法律第 59号 国民の祝日に関する法律(改正)
|
69
|
+
# 平成17年 2005年 5月20日公布・平成19年 2007年1月1日施行 法律第 43号 国民の祝日に関する法律(改正)
|
70
|
+
# 平成26年 2014年 5月30日公布・平成28年 2016年1月1日施行 法律第 43号 国民の祝日に関する法律(改正)
|
71
|
+
{month:1, day:1, term:1949..9999, name:'元旦'},
|
72
|
+
{month:1, day:15, term:1949..1999, name:'成人の日'},
|
73
|
+
{month:1, day:'monday 2', term:2000..9999, name:'成人の日'},
|
74
|
+
{month:2, day:11, term:1967..9999, name:'建国記念日'},
|
75
|
+
{month:3, day:'spring_day',term:1949..2099, name:'春分の日'},
|
76
|
+
{month:4, day:29, term:1949..1988, name:'天皇誕生日'},
|
77
|
+
{month:4, day:29, term:1989..2006, name:'みどりの日'},
|
78
|
+
{month:4, day:29, term:2007..9999, name:'昭和の日'},
|
79
|
+
{month:5, day:3 , term:1949..9999, name:'憲法記念日'},
|
80
|
+
{month:5, day:4 , term:2007..9999, name:'みどりの日'},
|
81
|
+
{month:5, day:5 , term:1949..9999, name:'こどもの日'},
|
82
|
+
{month:7, day:20, term:1996..2002, name:'海の日'},
|
83
|
+
{month:7, day:'monday 3', term:2003..9999, name:'海の日'},
|
84
|
+
{month:8, day:11, term:2016..9999, name:'山の日'},
|
85
|
+
{month:9, day:15, term:1966..2002, name:'敬老の日'},
|
86
|
+
{month:9, day:'monday 3', term:2003..9999, name:'敬老の日'},
|
87
|
+
{month:9, day:'autumn_day',term:1948..2099, name:'秋分の日'},
|
88
|
+
{month:10, day:10, term:1966..1999, name:'体育の日'},
|
89
|
+
{month:10, day:'monday 2', term:2000..9999, name:'体育の日'},
|
90
|
+
{month:11, day:3, term:1948..9999, name:'文化の日'},
|
91
|
+
{month:11, day:23, term:1948..9999, name:'勤労感謝の日'},
|
92
|
+
{month:12, day:23, term:1989..9999, name:'天皇誕生日'},
|
93
|
+
|
94
|
+
# 臨時の休日
|
95
|
+
# 大正 4年 1915年 9月21日施行 勅令161号 大禮ニ關スル休日ノ件
|
96
|
+
# 昭和 3年 1928年 9月 8日施行 勅令226号 大禮ニ關スル休日ノ件
|
97
|
+
# 昭和34年 1959年 3月17日施行 法律 16号 皇太子明仁親王の結婚の儀の行われる日を休日とする法律
|
98
|
+
# 平成元年 1989年 2月17日施行 法律 4号 昭和天皇の大喪の礼の行われる日を休日とする法律
|
99
|
+
# 平成 2年 1990年 6月 1日施行 法律 24号 即位礼正殿の儀の行われる日を休日とする法律
|
100
|
+
# 平成 5年 1993年 4月30日施行 法律 32号 皇太子徳仁親王の結婚の儀の行われる日を休日とする法律
|
101
|
+
{month:11, day:10, term:1915..1915, name:'即位ノ礼'},
|
102
|
+
{month:11, day:14, term:1915..1915, name:'大嘗祭'},
|
103
|
+
{month:11, day:16, term:1915..1915, name:'大饗第一日'},
|
104
|
+
{month:11, day:10, term:1928..1928, name:'即位ノ礼'},
|
105
|
+
{month:11, day:14, term:1928..1928, name:'大嘗祭'},
|
106
|
+
{month:11, day:16, term:1928..1928, name:'大饗第一日'},
|
107
|
+
{month:4, day:10, term:1959..1959, name:'結婚の儀'},
|
108
|
+
{month:2, day:24, term:1989..1989, name:'大喪の礼'},
|
109
|
+
{month:11, day:12, term:1990..1990, name:'即位の礼'},
|
110
|
+
{month:6, day:9, term:1993..1993, name:'結婚の儀'},
|
111
|
+
]
|
112
|
+
|
113
|
+
# 昭和48年 1973年 4月12日公布・施行 法律第 10号 国民の祝日に関する法律(改正) 振替休日の開始日付
|
114
|
+
SUBSTITUTE_HOLIDAY_START = Date.new(1973, 4, 12)
|
115
|
+
|
116
|
+
# 昭和60年 1985年12月27日公布・施行 法律第103号 国民の祝日に関する法律(改正) 国民の休日の開始日付
|
117
|
+
NATIONAL_HOLIDAY_START = Date.new(1985, 12, 27)
|
118
|
+
|
119
|
+
@@holidays = {}
|
120
|
+
@@years = []
|
121
|
+
|
122
|
+
# 指定した日付の祝日名称を返す
|
123
|
+
# ===Example:
|
124
|
+
# JPDate::Holiday.name(Date.parse('2014-9-23')) # => "秋分の日"
|
125
|
+
# JPDate::Holiday.name(Date.parse('2014-9-24')) # => nil
|
126
|
+
def self.name(date)
|
127
|
+
new(date.year) unless @@years.include?(date.year)
|
128
|
+
@@holidays[date]
|
129
|
+
end
|
130
|
+
|
131
|
+
# 指定した期間の祝日のハッシュを返す
|
132
|
+
# ===Example:
|
133
|
+
# JPDate::Holiday.list(2015) # => {#<Date: 2015-01-01 ((2457024j,0s,0n),+0s,2299161j)>=>"元旦", #<Date: 2015-01-12 ((2457035j,0s,0n),+0s,2299161j)>=>"成人の日", #<Date: 2015-02-11 ((2457065j,0s,0n),+0s,2299161j)>=>"建国記念日", #<Date: 2015-03-21 ((2457103j,0s,0n),+0s,2299161j)>=>"春分の日", #<Date: 2015-04-29 ((2457142j,0s,0n),+0s,2299161j)>=>"昭和の日", #<Date: 2015-05-03 ((2457146j,0s,0n),+0s,2299161j)>=>"憲法記念日", #<Date: 2015-05-04 ((2457147j,0s,0n),+0s,2299161j)>=>"みどりの日", #<Date: 2015-05-05 ((2457148j,0s,0n),+0s,2299161j)>=>"こどもの日", #<Date: 2015-05-06 ((2457149j,0s,0n),+0s,2299161j)>=>"振替休日", #<Date: 2015-07-20 ((2457224j,0s,0n),+0s,2299161j)>=>"海の日", #<Date: 2015-09-21 ((2457287j,0s,0n),+0s,2299161j)>=>"敬老の日", #<Date: 2015-09-22 ((2457288j,0s,0n),+0s,2299161j)>=>"国民の休日", #<Date: 2015-09-23 ((2457289j,0s,0n),+0s,2299161j)>=>"秋分の日", #<Date: 2015-10-12 ((2457308j,0s,0n),+0s,2299161j)>=>"体育の日", #<Date: 2015-11-03 ((2457330j,0s,0n),+0s,2299161j)>=>"文化の日", #<Date: 2015-11-23 ((2457350j,0s,0n),+0s,2299161j)>=>"勤労感謝の日", #<Date: 2015-12-23 ((2457380j,0s,0n),+0s,2299161j)>=>"天皇誕生日"}
|
134
|
+
# JPDate::Holiday.list(1989..2014) # => ...中略...
|
135
|
+
def self.list(range)
|
136
|
+
range = range..range if range.class == Fixnum
|
137
|
+
range.each {|y| new(y) unless @@years.include?(y)}
|
138
|
+
Hash[@@holidays.sort].select {|k, v| range.include?(k.year)}
|
139
|
+
end
|
140
|
+
|
141
|
+
private
|
142
|
+
|
143
|
+
def initialize(y) # :nodoc:
|
144
|
+
@holidays = {}
|
145
|
+
HOLIDAYS.select {|h| h[:term].include?(y)}.each do |h|
|
146
|
+
date = case h[:day]
|
147
|
+
when Fixnum then Date.new(y, h[:month], h[:day])
|
148
|
+
when String then send(*h[:day].split, y, h[:month])
|
149
|
+
end
|
150
|
+
@holidays[date] = h[:name]
|
151
|
+
end
|
152
|
+
dates = @holidays.keys.sort
|
153
|
+
add_substitute_holiday(dates)
|
154
|
+
add_national_holiday(dates)
|
155
|
+
@@holidays.merge!(@holidays)
|
156
|
+
@@years << y
|
157
|
+
end
|
158
|
+
|
159
|
+
# 振替休日を追加
|
160
|
+
def add_substitute_holiday(dates)
|
161
|
+
dates.each do |date|
|
162
|
+
if date.wday == 0 && date >= SUBSTITUTE_HOLIDAY_START
|
163
|
+
date += 1 while @holidays[date]
|
164
|
+
@holidays[date] = '振替休日'
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
# 国民の休日を追加
|
170
|
+
def add_national_holiday(dates)
|
171
|
+
dates.each_cons(2) do |a, b|
|
172
|
+
if b - a == 2 && (a + 1).wday != 0 && !@@holidays[a + 1] && a + 1 >= NATIONAL_HOLIDAY_START
|
173
|
+
@holidays[a + 1] = '国民の休日'
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
def monday(n, y, m) nth_week_day(y, m, n.to_i, 1) end
|
179
|
+
|
180
|
+
# y年m月の第n w曜日の日付を返す
|
181
|
+
# Sun Mon Tue Wed Thu Fri Sat
|
182
|
+
# w: 0 1 2 3 4 5 6
|
183
|
+
# 以下2014年10月第2月曜日の場合
|
184
|
+
# nth_week_day(2014, 10, 2, 1)
|
185
|
+
def nth_week_day(y, m, n, w)
|
186
|
+
Date.new(y, m, 7 * n - (Date.new(y, m) - w - 1).wday)
|
187
|
+
end
|
188
|
+
|
189
|
+
# 春分・秋分の日付を返す
|
190
|
+
def equinox_day(y, m)
|
191
|
+
case y
|
192
|
+
when 1851..1899
|
193
|
+
dy = y - 1980
|
194
|
+
return Date.new(y, m, (19.8277 + 0.242194*dy - dy/4).to_i) if m == 3
|
195
|
+
return Date.new(y, m, (22.2588 + 0.242194*dy - dy/4).to_i) if m == 9
|
196
|
+
when 1900..2099
|
197
|
+
dy = y - 1900
|
198
|
+
return Date.new(y, m, (21.4471 + 0.242377*dy - dy/4).to_i) if m == 3
|
199
|
+
return Date.new(y, m, (23.8896 + 0.242032*dy - dy/4).to_i) if m == 9
|
200
|
+
when 2100..2150
|
201
|
+
dy = y - 1980
|
202
|
+
return Date.new(y, m, (21.8510 + 0.242194*dy - dy/4).to_i) if m == 3
|
203
|
+
return Date.new(y, m, (24.2488 + 0.242194*dy - dy/4).to_i) if m == 9
|
204
|
+
end
|
205
|
+
end
|
206
|
+
alias_method :spring_day, :equinox_day
|
207
|
+
alias_method :autumn_day, :equinox_day
|
208
|
+
|
209
|
+
end # class Holiday
|
210
|
+
end # class JPDate
|
data/lib/jpdate.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'date'
|
3
|
+
require "jpdate/version"
|
4
|
+
require 'jpdate/era'
|
5
|
+
require 'jpdate/holiday'
|
6
|
+
|
7
|
+
# 日本の祝日と年号を出力するDateクラス(Dateを継承)
|
8
|
+
# ===Example:
|
9
|
+
# date = JPDate.parse('2014-9-23')
|
10
|
+
# date.holiday # => "秋分の日"
|
11
|
+
# date.era # => ["平成26年"]
|
12
|
+
# date.short_era # => ["H26"]
|
13
|
+
class JPDate < Date
|
14
|
+
def holiday
|
15
|
+
Holiday.name(self)
|
16
|
+
end
|
17
|
+
|
18
|
+
def era
|
19
|
+
Era.name_year(year, month, day)
|
20
|
+
end
|
21
|
+
|
22
|
+
def short_era
|
23
|
+
Era.short_name_year(year, month, day)
|
24
|
+
end
|
25
|
+
|
26
|
+
end # class JPDate
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jpdate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- zariganitosh
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: 明治6年1月1日以降の日本の祝日を出力可能なJPDateクラス
|
42
|
+
email:
|
43
|
+
- XXXX@example.com
|
44
|
+
executables:
|
45
|
+
- jcal
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- .gitignore
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/jcal
|
55
|
+
- jpdate.gemspec
|
56
|
+
- lib/jpdate.rb
|
57
|
+
- lib/jpdate/era.rb
|
58
|
+
- lib/jpdate/holiday.rb
|
59
|
+
- lib/jpdate/version.rb
|
60
|
+
homepage: https://github.com/zarigani/jcal
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.2.2
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: 日本の祝日を出力するJPDateクラス
|
84
|
+
test_files: []
|