date-holiday 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ce42e68e404159b0d65ea1f92c61a7f86d51f430
4
+ data.tar.gz: 4a15256f08173ce195a07a41a1fea3b441985dce
5
+ SHA512:
6
+ metadata.gz: 1a49ac097801f05c73b14957e9a521b64e560527e8eabe2ac5fda271cd14742e37d0826e4c164417ddaa84800d163b1c7300918aa19ed70e60cad043681291a3
7
+ data.tar.gz: f8e9f9dce74c27ae837ec875892f4165fa491fb50250edc8b7b3bd74a8a3956021c28518eb28b3793f94178407b8a2b249d4ee7fc1c7878d82bf657ea53ba940
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 1998-2014, Tadayoshi Funaba
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are
6
+ met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright
9
+ notice, this list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright
12
+ notice, this list of conditions and the following disclaimer in the
13
+ documentation and/or other materials provided with the
14
+ distribution.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
+ HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/MANUAL ADDED
@@ -0,0 +1,28 @@
1
+
2
+ Date
3
+
4
+ クラスメソッド
5
+
6
+ gregorian_easter(year[, start])
7
+ easter(year[, start])
8
+ グレゴリオ暦における、その年の復活祭の日曜日を返します。
9
+
10
+ julian_easter(year[, start])
11
+ ユリウス暦における、その年の復活祭の日曜日を返します。
12
+
13
+ メソッド
14
+
15
+ easter?
16
+ 復活祭の日曜日であれば真を返します。
17
+
18
+ national_holiday?
19
+ 「国民の祝日に関する法律」による休日、 もしくは、いくつかの特別な休日であれば真を返します。
20
+
21
+ このメソッドは、第八次改正 「国民の祝日に関する法律の一部を改正する法律」
22
+ (平成17年5月20日号外法律43号)に対応済みです。
23
+
24
+ 春分日、秋分日は前年の2月はじめの官報に掲載されるものが正しいのですが、 ここでは計算で求めています。
25
+ つまり将来については間違えることもあるかもしれません。 なお、平成21年 (2009) 分までは官報等により確認済みです。
26
+
27
+ old_national_holiday?
28
+ 舊祝祭日であれば眞を返します。 此は未だ實驗的な代物で有ります。
data/MANUAL.en ADDED
@@ -0,0 +1,25 @@
1
+
2
+ Date
3
+
4
+ Class Methods
5
+
6
+ gregorian_easter(year[, start])
7
+ easter(year[, start])
8
+ Returns a date object denoting the Easter sunday in the given
9
+ Gregorian year.
10
+
11
+ julian_easter(year[, start])
12
+ Returns a date object denoting the Easter sunday in the given
13
+ Julian year.
14
+
15
+ Methods
16
+
17
+ easter?
18
+ Returns true if the day is an Easter sunday.
19
+
20
+ national_holiday?
21
+ Returns true if the day is a Japanese national holiday.
22
+
23
+ old_national_holiday?
24
+ Returns true if the day is an old Japanese national holiday.
25
+ This is still experimental.
data/MANUAL.en.html ADDED
@@ -0,0 +1,48 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
6
+ <head>
7
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
8
+ <title>Date</title>
9
+ <link href="styles/default.css" type="text/css" rel="stylesheet" />
10
+ <link href="index.html" rel="index" />
11
+ <link href="mailto:tadf@funaba.org" rev="made" />
12
+ </head>
13
+ <body>
14
+ <h1><a name="label-0" id="label-0">date/holiday - determination of secular and religious holidays</a></h1><!-- RDLabel: "date/holiday - determination of secular and religious holidays" -->
15
+ <h2><a name="label-1" id="label-1">Date</a></h2><!-- RDLabel: "Date" -->
16
+ <h3><a name="label-2" id="label-2">Class Methods</a></h3><!-- RDLabel: "Class Methods" -->
17
+ <dl>
18
+ <dt><a name="label-3" id="label-3">gregorian_easter(year[, start])</a></dt><!-- RDLabel: "gregorian_easter(year[, start])" -->
19
+ <dt><a name="label-4" id="label-4">easter(year[, start])</a></dt><!-- RDLabel: "easter(year[, start])" -->
20
+ <dd>
21
+ Returns a date object denoting
22
+ the Easter sunday in the given Gregorian year.
23
+ </dd>
24
+ <dt><a name="label-5" id="label-5">julian_easter(year[, start])</a></dt><!-- RDLabel: "julian_easter(year[, start])" -->
25
+ <dd>
26
+ Returns a date object denoting
27
+ the Easter sunday in the given Julian year.
28
+ </dd>
29
+ </dl>
30
+ <h3><a name="label-6" id="label-6">Methods</a></h3><!-- RDLabel: "Methods" -->
31
+ <dl>
32
+ <dt><a name="label-7" id="label-7">easter?</a></dt><!-- RDLabel: "easter?" -->
33
+ <dd>
34
+ Returns true if the day is an Easter sunday.
35
+ </dd>
36
+ <dt><a name="label-8" id="label-8">national_holiday?</a></dt><!-- RDLabel: "national_holiday?" -->
37
+ <dd>
38
+ Returns true if the day is a Japanese national holiday.
39
+ </dd>
40
+ <dt><a name="label-9" id="label-9">old_national_holiday?</a></dt><!-- RDLabel: "old_national_holiday?" -->
41
+ <dd>
42
+ Returns true if the day is an old Japanese national holiday.
43
+ This is still experimental.
44
+ </dd>
45
+ </dl>
46
+
47
+ </body>
48
+ </html>
data/MANUAL.en.rd ADDED
@@ -0,0 +1,28 @@
1
+ =begin
2
+ = date/holiday - determination of secular and religious holidays
3
+
4
+ == Date
5
+
6
+ === Class Methods
7
+
8
+ : gregorian_easter(year[, start])
9
+ : easter(year[, start])
10
+ Returns a date object denoting
11
+ the Easter sunday in the given Gregorian year.
12
+
13
+ : julian_easter(year[, start])
14
+ Returns a date object denoting
15
+ the Easter sunday in the given Julian year.
16
+
17
+ === Methods
18
+
19
+ : easter?
20
+ Returns true if the day is an Easter sunday.
21
+
22
+ : national_holiday?
23
+ Returns true if the day is a Japanese national holiday.
24
+
25
+ : old_national_holiday?
26
+ Returns true if the day is an old Japanese national holiday.
27
+ This is still experimental.
28
+ =end
data/MANUAL.html ADDED
@@ -0,0 +1,54 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
6
+ <head>
7
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
8
+ <title>Date</title>
9
+ <link href="styles/default.css" type="text/css" rel="stylesheet" />
10
+ <link href="index.html" rel="index" />
11
+ <link href="mailto:tadf@funaba.org" rev="made" />
12
+ </head>
13
+ <body>
14
+ <h1><a name="label-0" id="label-0">date/holiday - 祝祭日の判定</a></h1><!-- RDLabel: "date/holiday - 祝祭日の判定" -->
15
+ <h2><a name="label-1" id="label-1">Date</a></h2><!-- RDLabel: "Date" -->
16
+ <h3><a name="label-2" id="label-2">クラスメソッド</a></h3><!-- RDLabel: "クラスメソッド" -->
17
+ <dl>
18
+ <dt><a name="label-3" id="label-3">gregorian_easter(year[, start])</a></dt><!-- RDLabel: "gregorian_easter(year[, start])" -->
19
+ <dt><a name="label-4" id="label-4">easter(year[, start])</a></dt><!-- RDLabel: "easter(year[, start])" -->
20
+ <dd>
21
+ グレゴリオ暦における、その年の復活祭の日曜日を返します。
22
+ </dd>
23
+ <dt><a name="label-5" id="label-5">julian_easter(year[, start])</a></dt><!-- RDLabel: "julian_easter(year[, start])" -->
24
+ <dd>
25
+ ユリウス暦における、その年の復活祭の日曜日を返します。
26
+ </dd>
27
+ </dl>
28
+ <h3><a name="label-6" id="label-6">メソッド</a></h3><!-- RDLabel: "メソッド" -->
29
+ <dl>
30
+ <dt><a name="label-7" id="label-7">easter?</a></dt><!-- RDLabel: "easter?" -->
31
+ <dd>
32
+ 復活祭の日曜日であれば真を返します。
33
+ </dd>
34
+ <dt><a name="label-8" id="label-8">national_holiday?</a></dt><!-- RDLabel: "national_holiday?" -->
35
+ <dd>
36
+ <p>「国民の祝日に関する法律」による休日、
37
+ もしくは、いくつかの特別な休日であれば真を返します。</p>
38
+ <p>このメソッドは、第八次改正
39
+ 「国民の祝日に関する法律の一部を改正する法律」
40
+ (平成17年5月20日号外法律43号)に対応済みです。</p>
41
+ <p>春分日、秋分日は前年の2月はじめの官報に掲載されるものが正しいのですが、
42
+ ここでは計算で求めています。
43
+ つまり将来については間違えることもあるかもしれません。
44
+ なお、平成21年 (2009) 分までは官報等により確認済みです。</p>
45
+ </dd>
46
+ <dt><a name="label-9" id="label-9">old_national_holiday?</a></dt><!-- RDLabel: "old_national_holiday?" -->
47
+ <dd>
48
+ 舊祝祭日であれば眞を返します。
49
+ 此は未だ實驗的な代物で有ります。
50
+ </dd>
51
+ </dl>
52
+
53
+ </body>
54
+ </html>
data/MANUAL.rd ADDED
@@ -0,0 +1,36 @@
1
+ =begin
2
+ = date/holiday - �˺�����Ƚ��
3
+
4
+ == Date
5
+
6
+ === ���饹�᥽�å�
7
+
8
+ : gregorian_easter(year[, start])
9
+ : easter(year[, start])
10
+ ���쥴�ꥪ��ˤ����롢����ǯ������פ����������֤��ޤ���
11
+
12
+ : julian_easter(year[, start])
13
+ ��ꥦ����ˤ����롢����ǯ������פ����������֤��ޤ���
14
+
15
+ === �᥽�å�
16
+
17
+ : easter?
18
+ ����פ��������Ǥ���п����֤��ޤ���
19
+
20
+ : national_holiday?
21
+ �ֹ�̱�ν����˴ؤ���ˡΧ�פˤ�������
22
+ �⤷���ϡ������Ĥ������̤ʵ����Ǥ���п����֤��ޤ���
23
+
24
+ ���Υ᥽�åɤϡ���Ȭ������
25
+ �ֹ�̱�ν����˴ؤ���ˡΧ�ΰ������������ˡΧ��
26
+ (ʿ��17ǯ5��20���泰ˡΧ43��)���б��ѤߤǤ���
27
+
28
+ ��ʬ������ʬ������ǯ��2��Ϥ���δ���˷Ǻܤ�����Τ��������ΤǤ�����
29
+ �����ǤϷ׻��ǵ��Ƥ��ޤ���
30
+ �Ĥޤ꾭��ˤĤ��Ƥϴְ㤨�뤳�Ȥ⤢�뤫�⤷��ޤ���
31
+ �ʤ���ʿ��21ǯ (2009) ʬ�ޤǤϴ������ˤ���ǧ�ѤߤǤ���
32
+
33
+ : old_national_holiday?
34
+ �ѽ˺����Ǥ�����ä��֤��ޤ���
35
+ ����̤������Ū����ʪ��ͭ��ޤ���
36
+ =end
data/README ADDED
@@ -0,0 +1,49 @@
1
+ �˺�����Ƚ��
2
+ ============
3
+
4
+ date/holiday �Ϥ����Ĥ��ν���Ƚ��ΰ٤Υ᥽�åɤ��󶡤��ޤ���������
5
+ date2 ���������ʪ�Ǥ���
6
+
7
+ ���路���ϡ��ե����� MANUAL �򻲾Ȥ��Ƥ���������
8
+
9
+
10
+ ���󥹥ȡ���
11
+ ------------
12
+
13
+ ������ץ� "install.rb" ��Ĥ����ޤ���
14
+
15
+ $ ruby install.rb config
16
+ $ ruby install.rb setup
17
+ ($ su)
18
+ # ruby install.rb install
19
+
20
+ ���路���ϡ�"ruby install.rb --help" �Ȥ��Ƥ���������
21
+
22
+
23
+ ����ʸ��
24
+ --------
25
+
26
+ Jean Meeus, Astronomical Algorithms, Willmann-Bell,Inc., 1991.
27
+
28
+ Nachum Dershowitz and Edward M. Reingold, ``Calendrical
29
+ Calculations'', Software---Practice & Experience, vol. 20, no. 9
30
+ (Sept. 1990), pp. 899--928.
31
+
32
+ ��׻�������ԡֿ����������Ģ�׹����Ҹ����� 1991
33
+
34
+ ��̱�ν����˴ؤ���ˡΧ (����23ǯ7��20��ˡΧ��178�� - ʿ��13ǯ6��22������)
35
+
36
+ ����ǰ�����Ȥʤ������������� (����41ǯ12��9���泰������376��)
37
+
38
+ ����ŷ�Ĥ����Ӥ���ιԤ�����������Ȥ���ˡΧ (ʿ����ǯ2��17��ˡΧ��4��)
39
+
40
+ ¨�������¤ε��ιԤ�����������Ȥ���ˡΧ (ʿ��2ǯ6��1��ˡΧ��24��)
41
+
42
+ ���������οƲ��η뺧�ε��ιԤ�����������Ȥ���ˡΧ (ʿ��5ǯ4��30��ˡΧ��32��)
43
+
44
+ �����������������Խ����ԡ�20����������������������� 1998
45
+
46
+
47
+ �դʤФ����褷
48
+ mailto:tadf@funaba.org
49
+ http://www.funaba.org/
data/README.en ADDED
@@ -0,0 +1,56 @@
1
+ Determination of holidays
2
+ =========================
3
+
4
+
5
+ date/holiday provides methods about determination of holidays. This
6
+ methdos are derivative of date2.
7
+
8
+ For more information, see the file MANUAL.en.
9
+
10
+
11
+ Install
12
+ -------
13
+
14
+ Use the script "install.rb".
15
+
16
+ $ ruby install.rb config
17
+ $ ruby install.rb setup
18
+ ($ su)
19
+ # ruby install.rb install
20
+
21
+ For more information, type "ruby install.rb --help".
22
+
23
+
24
+ References
25
+ ----------
26
+
27
+ Jean Meeus, Astronomical Algorithms, Willmann-Bell,Inc., 1991.
28
+
29
+ Nachum Dershowitz and Edward M. Reingold, "Calendrical Calculations",
30
+ Software---Practice & Experience, vol. 20, no. 9 (Sept. 1990),
31
+ pp. 899--928.
32
+
33
+ Koyomi-Keisan Kenkyū-kai, Shin Koyomi Benrichō, Kōseisha Kōseikaku,
34
+ 1991
35
+
36
+ Kokumin no Shukujitsu ni Kansuru Hōritsu (Shōwa 23 nen 7 gatsu 20 ka
37
+ Hōritsu Dai 178 Gō - Heisei 13 nen 6 gatsu 22 nichi Kaisei)
38
+
39
+ Kenkoku-Kinen-no-Hi Tonaru Hi o Sadameru Seirei (Shōwa 41 nen 12 gatsu
40
+ 9 ka Gōgai Seirei Dai 376 Gō)
41
+
42
+ Shōwa-Ten'nō no Taisō-no-Rei no Okonawareru Hi o Kyūjitsu Tosuru
43
+ Hōritsu (Heisei Gannen 2 gatsu 17 nichi Hōritsu Dai 4 Gō)
44
+
45
+ Sokui-Rei-Seiden-no-Gi no Okonawareru Hi o kyūjitsu Tosuru Hōritsu
46
+ (Heisei 2 nen 6 gatsu 1 chi Hōritsu Dai 24 Gō)
47
+
48
+ Kōtaishi Norihito-Shin'nō no Kekkon-no-Gi no Okonawareru Hi o Kyūjitsu
49
+ Tosuru Hōritsu (Heisei 5 nen 4 gatsu 30 nichi Hōritsu Dai 32 Gō)
50
+
51
+ Nichigai Associates, 20 Seiki-reki, Nichigai Associates 1998
52
+
53
+
54
+ Tadayoshi Funaba
55
+ mailto:tadf@funaba.org
56
+ http://www.funaba.org/
@@ -0,0 +1,35 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ # goodfriday.rb: Written by Tadayoshi Funaba 1998-2002
4
+ # $Id: goodfriday.rb,v 2.4 2002-06-08 00:40:29+09 tadf Exp $
5
+
6
+ require 'date'
7
+ require 'date/holiday'
8
+
9
+ es = Date.easter(Date.today.year)
10
+ [[-9*7, 'Septuagesima Sunday'],
11
+ [-8*7, 'Sexagesima Sunday'],
12
+ [-7*7, 'Quinquagesima Sunday (Shrove Sunday)'],
13
+ [-48, 'Shrove Monday'],
14
+ [-47, 'Shrove Tuesday'],
15
+ [-46, 'Ash Wednesday'],
16
+ [-6*7, 'Quadragesima Sunday'],
17
+ [-3*7, 'Mothering Sunday'],
18
+ [-2*7, 'Passion Sunday'],
19
+ [-7, 'Palm Sunday'],
20
+ [-3, 'Maunday Thursday'],
21
+ [-2, 'Good Friday'],
22
+ [-1, 'Easter Eve'],
23
+ [0, 'Easter Day'],
24
+ [1, 'Easter Monday'],
25
+ [7, 'Low Sunday'],
26
+ [5*7, 'Rogation Sunday'],
27
+ [39, 'Ascension Day (Holy Thursday)'],
28
+ [42, 'Sunday after Ascension Day'],
29
+ [7*7, 'Pentecost (Whitsunday)'],
30
+ [50, 'Whitmonday'],
31
+ [8*7, 'Trinity Sunday'],
32
+ [60, 'Corpus Christi (Thursday after Trinity)']].
33
+ each do |xs|
34
+ puts((es + xs.shift).to_s + ' ' + xs.shift)
35
+ end
data/example/ncal.rb ADDED
@@ -0,0 +1,225 @@
1
+ #! /usr/bin/env ruby -Ku
2
+
3
+ # ncal.rb: Written by Tadayoshi Funaba 1998-2004,2006,2008,2014
4
+ # $Id: ncal.rb,v 2.12 2014-04-07 20:19:01+09 tadf Exp $
5
+
6
+ require 'date'
7
+ require 'date/holiday'
8
+
9
+ class String
10
+
11
+ unless ''.respond_to?(:each_codepoint)
12
+ def awidth
13
+ aw = 0
14
+ unpack('U*').each do |c|
15
+ if c < 256
16
+ aw += 1
17
+ else
18
+ aw += 2
19
+ end
20
+ end
21
+ aw
22
+ end
23
+ else
24
+ def awidth
25
+ aw = 0
26
+ each_codepoint do |c|
27
+ if c < 256
28
+ aw += 1
29
+ else
30
+ aw += 2
31
+ end
32
+ end
33
+ aw
34
+ end
35
+ end
36
+
37
+ alias rjust_orig rjust
38
+
39
+ def rjust(w, pad=' ')
40
+ rjust_orig(w - (awidth - size), pad)
41
+ end
42
+
43
+ alias center_orig center
44
+
45
+ def center(w, pad=' ')
46
+ center_orig(w - (awidth - size), pad)
47
+ end
48
+
49
+ end
50
+
51
+ class Cal
52
+
53
+ START =
54
+ {
55
+ 'cn' => Date::GREGORIAN, # China
56
+ 'de' => 2342032, # Germany (protestant states)
57
+ 'dk' => 2342032, # Denmark
58
+ 'es' => 2299161, # Spain
59
+ 'fi' => 2361390, # Finland
60
+ 'fr' => 2299227, # France
61
+ 'gb' => 2361222, # United Kingdom
62
+ 'gr' => 2423868, # Greece
63
+ 'hu' => 2301004, # Hungary
64
+ 'it' => 2299161, # Italy
65
+ 'jp' => Date::GREGORIAN, # Japan
66
+ 'no' => 2342032, # Norway
67
+ 'pl' => 2299161, # Poland
68
+ 'pt' => 2299161, # Portugal
69
+ 'ru' => 2421639, # Russia
70
+ 'se' => 2361390, # Sweden
71
+ 'us' => 2361222, # United States
72
+ 'os' => Date::JULIAN, # (old style)
73
+ 'ns' => Date::GREGORIAN # (new style)
74
+ }
75
+
76
+ DEFAULT_START = 'jp'
77
+
78
+ def initialize
79
+ opt_j; opt_m; opt_t; opt_y; opt_c; tty
80
+ end
81
+
82
+ def opt_j(flag=false) @opt_j = flag end
83
+ def opt_m(flag=false) @opt_m = flag end
84
+ def opt_t(flag=false) @opt_t = flag end
85
+ def opt_y(flag=false) @opt_y = flag end
86
+
87
+ def opt_c(arg=DEFAULT_START) @start = START[arg] end
88
+
89
+ def tty(flag=false) @tty = flag end
90
+
91
+ def set_params
92
+ @dw = if @opt_j then 3 else 2 end
93
+ @mw = (@dw + 1) * 7 - 1
94
+ @mn = if @opt_j then 2 else 3 end
95
+ @tw = (@mw + 2) * @mn - 2
96
+ @k = if @opt_m then 1 else 0 end
97
+ @da = if @opt_j then :yday else :mday end
98
+ @es = @tty
99
+ end
100
+
101
+ def pict(y, m)
102
+ d = (1..31).detect{|x| Date.valid_date?(y, m, x, @start)}
103
+ fi = Date.new(y, m, d, @start)
104
+ fi -= (fi.jd - @k + 1) % 7
105
+
106
+ ve = (fi..fi + 6).collect{|cu|
107
+ [ %w(日 月 火 水 木 金 土)[cu.wday],
108
+ [31, 0, 0, 0, 0, 0, 34][cu.wday] ]
109
+ }
110
+ ve += (fi..fi + 41).collect{|cu|
111
+ [ if cu.mon == m then cu.send(@da) end.to_s,
112
+ if cu.mon == m && cu.national_holiday? then 41
113
+ else [31, 0, 0, 0, 0, 0, 34][cu.wday] end ]
114
+ }
115
+
116
+ ve = ve.collect{|e, n| esc(e.rjust(@dw), n)}
117
+
118
+ gr = group(ve, 7)
119
+ gr = trans(gr) if @opt_t
120
+ ta = gr.collect{|xs| xs.join(' ')}
121
+
122
+ ca = %w(睦月 如月 弥生 卯月 皐月 水無月
123
+ 文月 葉月 長月 神無月 霜月 師走)[m - 1]
124
+ ca = y.to_s + '年 ' + ca if !@opt_y
125
+ ca = esc(ca.center(@mw), 1)
126
+
127
+ ta.unshift(ca)
128
+ end
129
+
130
+ def esc2(n)
131
+ if @es then "\e[" + n.to_s + "m" else '' end
132
+ end
133
+
134
+ def esc(s, n)
135
+ esc2(n) + s + esc2(0)
136
+ end
137
+
138
+ def group(xs, n)
139
+ (0..xs.size / n - 1).collect{|i| xs[i * n, n]}
140
+ end
141
+
142
+ def trans(xs)
143
+ (0..xs[0].size - 1).collect{|i| xs.collect{|x| x[i]}}
144
+ end
145
+
146
+ def stack(xs)
147
+ if xs.empty? then [] else xs[0] + stack(xs[1..-1]) end
148
+ end
149
+
150
+ def block(xs, n)
151
+ stack(group(xs, n).collect{|ys| trans(ys).collect{|zs| zs.join(' ')}})
152
+ end
153
+
154
+ def unlines(xs)
155
+ xs.collect{|x| x + "\n"}.join
156
+ end
157
+
158
+ def monthly(y, m)
159
+ unlines(pict(y, m))
160
+ end
161
+
162
+ def addmon(y, m, n)
163
+ y, m = (y * 12 + (m - 1) + n).divmod(12)
164
+ return y, m + 1
165
+ end
166
+
167
+ def yearly(y)
168
+ esc((y.to_s + '年').center(@tw), 1) + "\n\n" +
169
+ unlines(block((0..11).collect{|n| pict(*addmon(y, 1, n))}, @mn)) + "\n"
170
+ end
171
+
172
+ def print(y, m)
173
+ set_params
174
+ if @opt_y then yearly(y) else monthly(y, m) end
175
+ end
176
+
177
+ end
178
+
179
+ if __FILE__ == $0
180
+
181
+ require 'getoptlong'
182
+
183
+ def usage
184
+ warn 'usage: ncal [-c iso3166] [-jmty] [[month] year]'
185
+ exit 1
186
+ end
187
+
188
+ cal = Cal.new
189
+
190
+ begin
191
+ GetoptLong.new(['-c', GetoptLong::REQUIRED_ARGUMENT],
192
+ ['-j', GetoptLong::NO_ARGUMENT],
193
+ ['-m', GetoptLong::NO_ARGUMENT],
194
+ ['-t', GetoptLong::NO_ARGUMENT],
195
+ ['-y', GetoptLong::NO_ARGUMENT]).
196
+ each do |opt, arg|
197
+ case opt
198
+ when '-c'; cal.opt_c(arg) || raise
199
+ when '-j'; cal.opt_j(true)
200
+ when '-m'; cal.opt_m(true)
201
+ when '-t'; cal.opt_t(true)
202
+ when '-y'; cal.opt_y(true)
203
+ end
204
+ end
205
+ rescue
206
+ usage
207
+ end
208
+
209
+ y, m = ARGV.values_at(1, 0).compact.collect{|x| x.to_i}
210
+ cal.opt_y(true) if y && !m
211
+
212
+ to = Date.today
213
+ y ||= to.year
214
+ m ||= to.mon
215
+
216
+ usage unless m >= 1 && m <= 12
217
+ usage unless y >= -4712
218
+
219
+ cal.tty($stdout.tty?)
220
+
221
+ print cal.print(y, m)
222
+
223
+ end
224
+
225
+ # See Bird & Wadler's Introduction to functional programming 4.5.
@@ -0,0 +1,269 @@
1
+ # date/holiday.rb: Written by Tadayoshi Funaba 1998-2006,2014
2
+ # $Id: holiday.rb,v 2.17 2014-04-07 20:18:37+09 tadf Exp $
3
+
4
+ require 'date'
5
+
6
+ class Date
7
+
8
+ def fixed?
9
+ return false unless jd >= 2432753 # 1948-07-20/PooD
10
+ *x = mon, mday
11
+ (x == [ 1, 1]) || # --01-01
12
+ (x == [ 1, 15] && # --01-15 (1948-07-20/1999-12-31)
13
+ jd <= 2451544) ||
14
+ (x == [ 2, 11] && # --02-11 (1966-12-09/PooD)
15
+ jd >= 2439469) ||
16
+ (x == [ 4, 29]) || # --04-29
17
+ (x == [ 5, 3]) || # --05-03
18
+ (x == [ 5, 4] && # --05-04 (2007-01-01/PooD)
19
+ jd >= 2454102) ||
20
+ (x == [ 5, 5]) || # --05-05
21
+ (x == [ 7, 20] && # --07-20 (1996-01-01/2002-12-31)
22
+ jd >= 2450084 &&
23
+ jd <= 2452640) ||
24
+ (x == [ 9, 15] && # --09-15 (1966-06-25/2002-12-31)
25
+ jd >= 2439302 &&
26
+ jd <= 2452640) ||
27
+ (x == [10, 10] && # --10-10 (1966-06-25/1999-12-31)
28
+ jd >= 2439302 &&
29
+ jd <= 2451544) ||
30
+ (x == [11, 3]) || # --11-03
31
+ (x == [11, 23]) || # --11-23
32
+ (x == [12, 23] && # --12-23 (1989-02-17/PooD)
33
+ jd >= 2447575)
34
+ end
35
+
36
+ t = Module.new do
37
+
38
+ private
39
+
40
+ def find_fdom(y, m, sg)
41
+ 1.upto(31) do |d|
42
+ if Date.valid_civil?(y, m, d, sg)
43
+ return Date.new(y, m, d, sg).jd
44
+ end
45
+ end
46
+ end
47
+
48
+ def find_ldom(y, m, sg)
49
+ 31.downto(1) do |d|
50
+ if Date.valid_civil?(y, m, d, sg)
51
+ return Date.new(y, m, d, sg).jd
52
+ end
53
+ end
54
+ end
55
+
56
+ def nth_kday_to_jd(y, m, n, k, sg=GREGORIAN)
57
+ j = if n > 0
58
+ find_fdom(y, m, sg) - 1
59
+ else
60
+ find_ldom(y, m, sg) + 7
61
+ end
62
+ (j - (((j - k) + 1) % 7)) + 7 * n
63
+ end
64
+
65
+ end
66
+
67
+ extend t
68
+ include t
69
+
70
+ def nth_kday? (n, k)
71
+ k == wday && jd === nth_kday_to_jd(year, mon, n, k, start)
72
+ end
73
+
74
+ private :nth_kday?
75
+
76
+ def float?
77
+ (mon == 1 && nth_kday?(2, 1) && # 2nd Mon, Jan (2000-01-01/PooD)
78
+ jd >= 2451545) ||
79
+ (mon == 7 && nth_kday?(3, 1) && # 3nd Mon, Jul (2003-01-01/PooD)
80
+ jd >= 2452641) ||
81
+ (mon == 9 && nth_kday?(3, 1) && # 3nd Mon, Sep (2003-01-01/PooD)
82
+ jd >= 2452641) ||
83
+ (mon == 10 && nth_kday?(2, 1) && # 2nd Mon, Oct (2000-01-01/PooD)
84
+ jd >= 2451545)
85
+ end
86
+
87
+ private :fixed?, :float?
88
+
89
+ def _deq(a, b, y)
90
+ (a + 0.242194 * (y - 1980) - ((y - b) / 4).to_i).to_i
91
+ end
92
+
93
+ def _veq(y)
94
+ case y
95
+ when 1851..1899; a = 19.8277; b = 1983.0
96
+ when 1900..1979; a = 20.8357; b = 1983.0
97
+ when 1980..2099; a = 20.8431; b = 1980.0
98
+ when 2100..2150; a = 21.8510; b = 1980.0
99
+ else; raise ArgumentError, 'domain error'
100
+ end
101
+ Date.new(y, 3, _deq(a, b, y)).jd
102
+ end
103
+
104
+ def _aeq(y)
105
+ case y
106
+ when 1851..1899; a = 22.2588; b = 1983.0
107
+ when 1900..1979; a = 23.2588; b = 1983.0
108
+ when 1980..2099; a = 23.2488; b = 1980.0
109
+ when 2100..2150; a = 24.2488; b = 1980.0
110
+ else; raise ArgumentError, 'domain error'
111
+ end
112
+ Date.new(y, 9, _deq(a, b, y)).jd
113
+ end
114
+
115
+ private :_deq, :_veq, :_aeq
116
+
117
+ def veq?
118
+ return false unless (2432753..2506696) === jd # 1948-07-20/2150-12-31
119
+ jd == _veq(year)
120
+ end
121
+
122
+ def aeq?
123
+ return false unless (2432753..2506696) === jd # 1948-07-20/2150-12-31
124
+ jd == _aeq(year)
125
+ end
126
+
127
+ private :veq?, :aeq?
128
+
129
+ def nhol2? () fixed? || float? || veq? || aeq? end
130
+
131
+ unless Date.new.respond_to?(:sunday?)
132
+ def sunday? () wday == 0 end
133
+ def monday? () wday == 1 end
134
+
135
+ protected :sunday?, :monday?
136
+ end
137
+
138
+ def need_subs?
139
+ nhol2? && (sunday? || (self - 1).need_subs?)
140
+ end
141
+
142
+ protected :nhol2?, :need_subs?
143
+
144
+ def nhol32?
145
+ if jd >= 2441785
146
+ if jd <= 2454101 # 1973-04-12/2006-12-31
147
+ self.monday? && (self - 1).nhol2?
148
+ else # 2007-01-01/PooD
149
+ !nhol2? && (self - 1).need_subs?
150
+ end
151
+ end
152
+ end
153
+
154
+ def nhol33?
155
+ if jd >= 2446427
156
+ if jd <= 2454101 # 1985-12-27/2006-12-31
157
+ !sunday? && !nhol32? &&
158
+ (self - 1).nhol2? && (self + 1).nhol2?
159
+ else # 2007-01-01/PooD
160
+ !nhol2? &&
161
+ (self - 1).nhol2? && (self + 1).nhol2?
162
+ end
163
+ end
164
+ end
165
+
166
+ def nholx?
167
+ jd == 2436669 || # 1959-04-10 # 16
168
+ jd == 2447582 || # 1989-02-24
169
+ jd == 2448208 || # 1990-11-12
170
+ jd == 2449148 # 1993-06-09
171
+ end
172
+
173
+ private :nhol32?, :nhol33?, :nholx?
174
+
175
+ def national_holiday?
176
+ d = if julian? then self.gregorian else self end
177
+ d.instance_eval do nhol2? || nhol32? || nhol33? || nholx? end
178
+ end
179
+
180
+ def qfixed?
181
+ return false unless (2405163..2432752) === jd # 1873-01-04/1948-07-19
182
+ *x = mon, mday
183
+ (x == [ 1, 3] && (2405446..2432752) === jd) || # 1873-10-14/1948-07-19
184
+ (x == [ 1, 5] && (2405446..2432752) === jd) || # 1873-10-14/1948-07-19
185
+ (x == [ 1, 29] && (2405143..2405224) === jd) || # 1872-12-15/1873-03-06
186
+ (x == [ 1, 30] && (2405446..2419649) === jd) || # 1873-10-14/1912-09-03
187
+ (x == [ 2, 11] && (2405225..2432752) === jd) || # 1873-03-07/1948-07-19
188
+ (x == [ 4, 3] && (2405446..2432752) === jd) || # 1873-10-14/1948-07-19
189
+ (x == [ 4, 29] && (2424943..2432752) === jd) || # 1927-03-03/1948-07-19
190
+ (x == [ 7, 30] && (2419650..2424942) === jd) || # 1912-09-04/1927-03-02
191
+ (x == [ 8, 31] && (2419650..2424942) === jd) || # 1912-09-04/1927-03-02
192
+ (x == [ 9, 17] && (2405446..2407535) === jd) || # 1873-10-14/1879-07-04
193
+ (x == [10, 17] && (2407536..2432752) === jd) || # 1879-07-05/1948-07-19
194
+ (x == [10, 31] && (2419967..2424942) === jd) || # 1913-07-18/1927-03-02
195
+ (x == [11, 3] && (2405163..2419649) === jd) || # 1873-01-04/1912-09-03
196
+ (x == [11, 3] && (2424943..2432752) === jd) || # 1927-03-03/1948-07-19
197
+ (x == [11, 23] && (2405446..2432752) === jd) || # 1873-10-14/1948-07-19
198
+ (x == [12, 25] && (2424943..2432752) === jd) # 1927-03-03/1948-07-19
199
+ end
200
+
201
+ private :qfixed?
202
+
203
+ def qveq?
204
+ return false unless (2405163..2432752) === jd # 1873-01-04/1948-07-19
205
+ jd == _veq(year)
206
+ end
207
+
208
+ def qaeq?
209
+ return false unless (2405163..2432752) === jd # 1873-01-04/1948-07-19
210
+ jd == _aeq(year)
211
+ end
212
+
213
+ private :qveq?, :qaeq?
214
+
215
+ def qnholx?
216
+ jd == 2420812 || # 1915-11-10 # 160
217
+ jd == 2420816 || # 1915-11-14 # 160
218
+ jd == 2420818 || # 1915-11-16 # 160
219
+ jd == 2425561 || # 1928-11-10 # 226
220
+ jd == 2425565 || # 1928-11-14 # 226
221
+ jd == 2425567 # 1928-11-16 # 226
222
+ end
223
+
224
+ private :qnholx?
225
+
226
+ def old_national_holiday?
227
+ d = if julian? then self.gregorian else self end
228
+ d.instance_eval do
229
+ qfixed? || qnholx? ||
230
+ ((2407141..2432752) === jd && (qveq? || qaeq?)) # 1878-06-05/1948-07-19
231
+ end
232
+ end
233
+
234
+ def self.julian_easter(y, sg=ITALY)
235
+ a = y % 4
236
+ b = y % 7
237
+ c = y % 19
238
+ d = (19 * c + 15) % 30
239
+ e = (2 * a + 4 * b - d + 34) % 7
240
+ f, g = (d + e + 114).divmod(31)
241
+ Date.new(y, f, g + 1, JULIAN).new_start(sg)
242
+ end
243
+
244
+ def self.gregorian_easter(y, sg=ITALY)
245
+ a = y % 19
246
+ b, c = y.divmod(100)
247
+ d, e = b.divmod(4)
248
+ f = ((b + 8) / 25).to_i
249
+ g = ((b - f + 1) / 3).to_i
250
+ h = (19 * a + b - d - g + 15) % 30
251
+ i, k = c.divmod(4)
252
+ l = (32 + 2 * e + 2 * i - h - k) % 7
253
+ m = ((a + 11 * h + 22 * l) / 451).to_i
254
+ n, p = (h + l - 7 * m + 114).divmod(31)
255
+ Date.new(y, n, p + 1, GREGORIAN).new_start(sg)
256
+ end
257
+
258
+ class << self; alias_method :easter, :gregorian_easter end
259
+
260
+ def easter?
261
+ self ===
262
+ (if julian?
263
+ self.class.julian_easter(year)
264
+ else
265
+ self.class.gregorian_easter(year)
266
+ end)
267
+ end
268
+
269
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: date-holiday
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tadayoshi Funaba
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-07 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: tadf@funaba.org
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - LICENSE
20
+ - MANUAL
21
+ - MANUAL.en
22
+ - MANUAL.en.html
23
+ - MANUAL.en.rd
24
+ - MANUAL.html
25
+ - MANUAL.rd
26
+ - README
27
+ - README.en
28
+ - example/goodfriday.rb
29
+ - example/ncal.rb
30
+ - lib/date/holiday.rb
31
+ homepage: http://www.funaba.org/code
32
+ licenses:
33
+ - BSD 2-Clause
34
+ metadata: {}
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubyforge_project: tadf
51
+ rubygems_version: 2.2.2
52
+ signing_key:
53
+ specification_version: 4
54
+ summary: determination of holiday
55
+ test_files: []