when_exe 0.2.100 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.ja.txt +25 -25
- data/LICENSE.txt +31 -31
- data/bin/irb.rc +5 -0
- data/bin/locales.rb +2 -2
- data/bin/when.rb +16 -0
- data/bin/when.rb.config +7 -0
- data/lib/when_exe.rb +616 -14
- data/lib/when_exe/basictypes.rb +615 -0
- data/lib/when_exe/calendartypes.rb +1700 -0
- data/lib/when_exe/coordinates.rb +1936 -0
- data/lib/when_exe/core/compatibility.rb +54 -0
- data/lib/when_exe/core/duration.rb +72 -72
- data/lib/when_exe/core/extension.rb +382 -0
- data/lib/when_exe/ephemeris.rb +1845 -0
- data/lib/when_exe/googlecalendar.rb +140 -0
- data/lib/when_exe/icalendar.rb +1587 -0
- data/lib/when_exe/inspect.rb +1237 -0
- data/lib/when_exe/locales/af.rb +90 -0
- data/lib/when_exe/locales/ar.rb +145 -0
- data/lib/when_exe/locales/az.rb +90 -0
- data/lib/when_exe/locales/bg.rb +90 -0
- data/lib/when_exe/locales/bn.rb +94 -0
- data/lib/when_exe/locales/bs.rb +121 -0
- data/lib/when_exe/locales/ca.rb +92 -0
- data/lib/when_exe/locales/cs.rb +107 -0
- data/lib/when_exe/locales/cy.rb +150 -0
- data/lib/when_exe/locales/da.rb +84 -0
- data/lib/when_exe/locales/de.rb +92 -0
- data/lib/when_exe/locales/de_AT.rb +92 -0
- data/lib/when_exe/locales/de_CH.rb +92 -0
- data/lib/when_exe/locales/el.rb +93 -0
- data/lib/when_exe/locales/en.rb +88 -0
- data/lib/when_exe/locales/en_AU.rb +88 -0
- data/lib/when_exe/locales/en_CA.rb +88 -0
- data/lib/when_exe/locales/en_GB.rb +88 -0
- data/lib/when_exe/locales/en_IN.rb +88 -0
- data/lib/when_exe/locales/en_NZ.rb +88 -0
- data/lib/when_exe/locales/eo.rb +89 -0
- data/lib/when_exe/locales/es.rb +84 -0
- data/lib/when_exe/locales/es_419.rb +84 -0
- data/lib/when_exe/locales/es_AR.rb +84 -0
- data/lib/when_exe/locales/es_CL.rb +84 -0
- data/lib/when_exe/locales/es_CO.rb +84 -0
- data/lib/when_exe/locales/es_MX.rb +84 -0
- data/lib/when_exe/locales/es_PE.rb +85 -0
- data/lib/when_exe/locales/es_VE.rb +84 -0
- data/lib/when_exe/locales/et.rb +94 -0
- data/lib/when_exe/locales/eu.rb +95 -0
- data/lib/when_exe/locales/fa.rb +80 -0
- data/lib/when_exe/locales/fi.rb +89 -0
- data/lib/when_exe/locales/fr.rb +88 -0
- data/lib/when_exe/locales/fr_CA.rb +88 -0
- data/lib/when_exe/locales/fr_CH.rb +88 -0
- data/lib/when_exe/locales/gl.rb +81 -0
- data/lib/when_exe/locales/he.rb +84 -0
- data/lib/when_exe/locales/hi.rb +80 -0
- data/lib/when_exe/locales/hi_IN.rb +84 -0
- data/lib/when_exe/locales/hr.rb +128 -0
- data/lib/when_exe/locales/hu.rb +84 -0
- data/lib/when_exe/locales/id.rb +89 -0
- data/lib/when_exe/locales/is.rb +89 -0
- data/lib/when_exe/locales/it.rb +87 -0
- data/lib/when_exe/locales/it_CH.rb +87 -0
- data/lib/when_exe/locales/ja.rb +78 -0
- data/lib/when_exe/locales/kn.rb +86 -0
- data/lib/when_exe/locales/ko.rb +78 -0
- data/lib/when_exe/locales/links.rb +2342 -0
- data/lib/when_exe/locales/lo.rb +123 -0
- data/lib/when_exe/locales/locales.rb +91 -0
- data/lib/when_exe/locales/lt.rb +111 -0
- data/lib/when_exe/locales/lv.rb +118 -0
- data/lib/when_exe/locales/mk.rb +93 -0
- data/lib/when_exe/locales/mn.rb +80 -0
- data/lib/when_exe/locales/nb.rb +81 -0
- data/lib/when_exe/locales/ne.rb +81 -0
- data/lib/when_exe/locales/nl.rb +92 -0
- data/lib/when_exe/locales/nn.rb +73 -0
- data/lib/when_exe/locales/or.rb +84 -0
- data/lib/when_exe/locales/pl.rb +128 -0
- data/lib/when_exe/locales/pt.rb +88 -0
- data/lib/when_exe/locales/pt_BR.rb +88 -0
- data/lib/when_exe/locales/rm.rb +143 -0
- data/lib/when_exe/locales/ro.rb +105 -0
- data/lib/when_exe/locales/ru.rb +128 -0
- data/lib/when_exe/locales/sk.rb +109 -0
- data/lib/when_exe/locales/sl.rb +122 -0
- data/lib/when_exe/locales/sr.rb +122 -0
- data/lib/when_exe/locales/sv.rb +83 -0
- data/lib/when_exe/locales/sw.rb +89 -0
- data/lib/when_exe/locales/th.rb +78 -0
- data/lib/when_exe/locales/tl.rb +99 -0
- data/lib/when_exe/locales/tr.rb +96 -0
- data/lib/when_exe/locales/uk.rb +128 -0
- data/lib/when_exe/locales/uz.rb +128 -0
- data/lib/when_exe/locales/vi.rb +94 -0
- data/lib/when_exe/locales/wo.rb +82 -0
- data/lib/when_exe/locales/zh_CN.rb +77 -0
- data/lib/when_exe/locales/zh_HK.rb +77 -0
- data/lib/when_exe/locales/zh_TW.rb +77 -0
- data/lib/when_exe/mini_application.rb +252 -0
- data/lib/when_exe/parts/enumerator.rb +472 -0
- data/lib/when_exe/parts/geometric_complex.rb +379 -0
- data/lib/when_exe/parts/locale.rb +513 -0
- data/lib/when_exe/parts/method_cash.rb +207 -0
- data/lib/when_exe/parts/resource.rb +806 -0
- data/lib/when_exe/parts/timezone.rb +182 -0
- data/lib/when_exe/region/bahai.rb +145 -0
- data/lib/when_exe/region/balinese.rb +627 -0
- data/lib/when_exe/region/chinese.rb +896 -0
- data/lib/when_exe/region/chinese_calendar.rb +919 -0
- data/lib/when_exe/region/chinese_epoch.rb +1245 -0
- data/lib/when_exe/region/christian.rb +644 -0
- data/lib/when_exe/region/far_east.rb +192 -0
- data/lib/when_exe/region/french.rb +66 -0
- data/lib/when_exe/region/geologicalage.rb +639 -0
- data/lib/when_exe/region/indian.rb +1066 -0
- data/lib/when_exe/region/iranian.rb +66 -0
- data/lib/when_exe/region/islamic.rb +105 -0
- data/lib/when_exe/region/japanese.rb +851 -0
- data/lib/when_exe/region/japanese_notes.rb +964 -0
- data/lib/when_exe/region/japanese_residues.rb +1149 -0
- data/lib/when_exe/region/javanese.rb +228 -0
- data/lib/when_exe/region/jewish.rb +127 -0
- data/lib/when_exe/region/korean.rb +267 -0
- data/lib/when_exe/region/m17n.rb +115 -0
- data/lib/when_exe/region/martian.rb +215 -0
- data/lib/when_exe/region/mayan.rb +122 -0
- data/lib/when_exe/region/moon.rb +333 -0
- data/lib/when_exe/region/nihon_shoki.rb +73 -0
- data/lib/when_exe/region/planets.rb +585 -0
- data/lib/when_exe/region/pope.rb +298 -0
- data/lib/when_exe/region/residue.rb +229 -0
- data/lib/when_exe/region/roman.rb +325 -0
- data/lib/when_exe/region/ryukyu.rb +98 -0
- data/lib/when_exe/region/shire.rb +254 -0
- data/lib/when_exe/region/sun.rb +210 -0
- data/lib/when_exe/region/thai.rb +227 -0
- data/lib/when_exe/region/tibetan.rb +233 -0
- data/lib/when_exe/region/v50.rb +111 -0
- data/lib/when_exe/region/vietnamese.rb +173 -0
- data/lib/when_exe/region/world.rb +197 -0
- data/lib/when_exe/timestandard.rb +547 -0
- data/lib/when_exe/tmduration.rb +330 -330
- data/lib/when_exe/tmobjects.rb +1295 -0
- data/lib/when_exe/tmposition.rb +1955 -0
- data/lib/when_exe/tmreference.rb +1547 -0
- data/lib/when_exe/version.rb +10 -3
- data/link_to_online_documents +4 -0
- data/test/examples/JapanHolidays.ics +456 -0
- data/test/examples/Millennium.ics +17 -0
- data/test/examples/NewYork.ics +61 -0
- data/test/examples/Residue.m17n +135 -0
- data/test/examples/Spatial.m17n +179 -0
- data/test/examples/Terms.m17n +39 -0
- data/test/examples/Test.ics +53 -0
- data/test/examples/USA-DST.ics +61 -0
- data/test/examples/geometric_complex.rb +41 -0
- data/test/examples/sample.xml +14 -0
- data/test/examples/today.rb +61 -0
- data/test/test.rb +54 -19
- data/test/test.rb.config +1 -0
- data/test/test/basictypes.rb +368 -0
- data/test/test/calendartypes.rb +57 -0
- data/test/test/coordinates.rb +380 -0
- data/test/test/ephemeris.rb +127 -0
- data/test/test/googlecalendar.rb +167 -0
- data/test/test/icalendar.rb +848 -0
- data/test/test/inspect.rb +115 -0
- data/test/test/parts.rb +480 -0
- data/test/test/region/chinese.rb +161 -0
- data/test/test/region/french.rb +33 -0
- data/test/test/region/geologicalage.rb +14 -0
- data/test/test/region/indian.rb +55 -0
- data/test/test/region/iran.rb +54 -0
- data/test/test/region/islamic.rb +18 -0
- data/test/test/region/japanese.rb +62 -0
- data/test/test/region/jewish.rb +61 -0
- data/test/test/region/m17n.rb +181 -0
- data/test/test/region/mayan.rb +78 -0
- data/test/test/region/moon.rb +14 -0
- data/test/test/region/planets.rb +14 -0
- data/test/test/region/residue.rb +123 -0
- data/test/test/region/sun.rb +14 -0
- data/test/test/region/thai.rb +94 -0
- data/test/test/region/tibetan.rb +30 -0
- data/test/test/tmobjects.rb +356 -57
- data/test/test/tmposition.rb +237 -0
- data/test/test/tmreference.rb +95 -0
- data/when_exe.gemspec +2 -2
- metadata +187 -7
- data/doc/COPYING +0 -31
- data/doc/COPYING.ja +0 -25
- data/doc/document_url +0 -1
@@ -0,0 +1,1066 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
=begin
|
3
|
+
Copyright (C) 2011-2013 Takashi SUGA
|
4
|
+
|
5
|
+
You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
|
6
|
+
=end
|
7
|
+
|
8
|
+
module When
|
9
|
+
class BasicTypes::M17n
|
10
|
+
|
11
|
+
IndianTerms = [self, [
|
12
|
+
"namespace:[en=http://en.wikipedia.org/wiki/, ja=http://ja.wikipedia.org/wiki/]",
|
13
|
+
"locale:[=en:, ja=ja:, alias]",
|
14
|
+
"names:[IndianTerms]",
|
15
|
+
"[IndianNationalSolar=en:Indian_national_calendar, インド国定暦]",
|
16
|
+
"[HinduSolar=en:Hindu_calendar, インド太陽暦=ja:%E3%83%92%E3%83%B3%E3%83%89%E3%82%A5%E3%83%BC%E6%9A%A6]",
|
17
|
+
"[HinduLuniSolar=en:Hindu_calendar, インド太陰太陽暦=ja:%E3%83%92%E3%83%B3%E3%83%89%E3%82%A5%E3%83%BC%E6%9A%A6]",
|
18
|
+
|
19
|
+
[self,
|
20
|
+
"names:[IntercalaryMonth=en:Intercalation, 閏月]",
|
21
|
+
"[%s Śuklapakṣa=, %s 白分= ]",
|
22
|
+
"[%s Kṛṣṇapakṣa=, %s 黒分= ]",
|
23
|
+
"[adhika %s Śuklapakṣa=, 閏%s 白分=]",
|
24
|
+
"[adhika %s Kṛṣṇapakṣa=, 閏%s 黒分=]"
|
25
|
+
],
|
26
|
+
|
27
|
+
[self,
|
28
|
+
"names:[IntercalaryDay=en:Intercalation, 閏日=ja:%E9%96%8F]",
|
29
|
+
"[Double %s=, 欠= ]",
|
30
|
+
"[Intercalary %s=, 重= ]"
|
31
|
+
],
|
32
|
+
|
33
|
+
[self,
|
34
|
+
"names:[LunarMonth=, 太陰月=ja:%E6%9C%88_(%E6%9A%A6)]",
|
35
|
+
"[Mārgaśīra=en:Margashirsha, マールガシールシャ=]",
|
36
|
+
"[Pauṣa=en:Pausha, パウシャ= ]",
|
37
|
+
"[Māgha=en:Maagha, マーガ= ]",
|
38
|
+
"[Phālguna=en:Phalguna, パールグナ= ]",
|
39
|
+
"[Caitra=en:Chaitra, チャイトラ= ]",
|
40
|
+
"[Vaiśākha=en:Vaisakha, ヴァイシャーカ= ]",
|
41
|
+
"[Jyaiṣṭha=en:Jyeshta, ジャイシュタ= ]",
|
42
|
+
"[Āṣāḍha=en:Aashaadha, アーシャーダ= ]",
|
43
|
+
"[Śrāvaṇa=en:Shraavana, シュラーヴァナ= ]",
|
44
|
+
"[Bhādrapada=en:Bhadrapada, バードラパダ= ]",
|
45
|
+
"[Āśvina=en:Ashwin, アーシュヴィナ= ]",
|
46
|
+
"[Kārttika=en:Kartika_(month), カールッティカ= ]"
|
47
|
+
],
|
48
|
+
|
49
|
+
[self,
|
50
|
+
"names:[SolarMonth=, 太陽月=ja:%E6%9C%88_(%E6%9A%A6)]",
|
51
|
+
"[Maysha=, 白羊宮 ]",
|
52
|
+
"[Vrushabha=, 金牛宮 ]",
|
53
|
+
"[Mithuna=, 双児宮 ]",
|
54
|
+
"[Karka=, 巨蟹宮 ]",
|
55
|
+
"[Simha=, 獅子宮 ]",
|
56
|
+
"[Kanya=, 処女宮 ]",
|
57
|
+
"[Tula=, 天秤宮 ]",
|
58
|
+
"[Vrushchika=, 天蝎宮 ]",
|
59
|
+
"[Dhanu=, 人馬宮 ]",
|
60
|
+
"[Makar=, 磨羯宮 ]",
|
61
|
+
"[Kumbha=, 宝瓶宮 ]",
|
62
|
+
"[Meena=, 双魚宮 ]"
|
63
|
+
]
|
64
|
+
]]
|
65
|
+
end
|
66
|
+
|
67
|
+
module Coordinates
|
68
|
+
|
69
|
+
# Location of cities in India
|
70
|
+
IndianCities = [When::BasicTypes::M17n, [
|
71
|
+
"namespace:[en=http://en.wikipedia.org/wiki/, ja=http://ja.wikipedia.org/wiki/]",
|
72
|
+
"locale:[=en:, ja=ja:, alias]",
|
73
|
+
"names:[IndianCities]",
|
74
|
+
[Spatial, "long:+82.5", "lat:N23.11", "label:[CentralIndia, インド中部]" ],
|
75
|
+
[Spatial, "long:+82.5", "lat:+29.0", "label:[NorthIndia, インド北部]" ],
|
76
|
+
[Spatial, "long:+78.0", "lat:+27.2", "label:[Agra, アーグラ]" ],
|
77
|
+
[Spatial, "long:+72.6", "lat:+23.0", "label:[Ahmedabad, アフマダーバード]" ],
|
78
|
+
[Spatial, "long:+74.6", "lat:+26.5", "label:[Ajmer, アジメール]" ],
|
79
|
+
[Spatial, "long:+78.1", "lat:+27.9", "label:[Aligarh, アリーガル]" ],
|
80
|
+
[Spatial, "long:+74.9", "lat:+31.6", "label:[Amritsar, アムリトサル]" ],
|
81
|
+
[Spatial, "long:+77.6", "lat:+13.0", "label:[Bangalore, バンガロール]" ],
|
82
|
+
[Spatial, "long:+85.8", "lat:+20.2", "label:[Bhuvaneswar, ブヴァネーシュヴァル]"],
|
83
|
+
[Spatial, "long:+80.3", "lat:+13.1", "label:[Chennai, チェンナイ, Madras]" ],
|
84
|
+
[Spatial, "long:+79.9", "lat: +6.9", "label:[Colombo, コロンボ]" ],
|
85
|
+
[Spatial, "long:+90.4", "lat:+23.7", "label:[Dacca, ダッカ]" ],
|
86
|
+
[Spatial, "long:+77.2", "lat:+28.6", "label:[Delhi, デリー]" ],
|
87
|
+
[Spatial, "long:+78.5", "lat:+17.4", "label:[Hyderabad, ハイデラバード]" ],
|
88
|
+
[Spatial, "long:+75.8", "lat:+26.9", "label:[Jaipur, ジャイプル]" ],
|
89
|
+
[Spatial, "long:+85.2", "lat:+27.7", "label:[Kathmandu, カトマンズ]" ],
|
90
|
+
[Spatial, "long:+76.2", "lat:+10.0", "label:[Kochi, コーチ, Cochin]" ],
|
91
|
+
[Spatial, "long:+88.4", "lat:+22.6", "label:[Kolkata, コルカタ, Calcutta]" ],
|
92
|
+
[Spatial, "long:+74.3", "lat:+31.6", "label:[Lahor, ラホール]" ],
|
93
|
+
[Spatial, "long:+77.7", "lat:+27.5", "label:[Mathura, マトゥラー]" ],
|
94
|
+
[Spatial, "long:+72.8", "lat:+19.0", "label:[Mumbai, ムンバイ, Bombay]" ],
|
95
|
+
[Spatial, "long:+76.6", "lat:+12.3", "label:[Mysore, マイソール]" ],
|
96
|
+
[Spatial, "long:+85.1", "lat:+25.6", "label:[Patna, パトナ]" ],
|
97
|
+
[Spatial, "long:+73.9", "lat:+18.5", "label:[Pune, プネー]" ],
|
98
|
+
[Spatial, "long:+74.8", "lat:+34.1", "label:[Srinagar, シュリーナガル]" ],
|
99
|
+
[Spatial, "long:+77.0", "lat: +8.5", "label:[Thiruvananthapuram, ティルヴァナンタプラム, Trivandrum]"],
|
100
|
+
[Spatial, "long:+83.0", "lat:+25.3", "label:[Varanasi, ワーラーナシー]" ],
|
101
|
+
[Spatial, "long:+75.8", "lat:+23.2", "label:[Ujjain, ウッジャイン]" ]
|
102
|
+
]]
|
103
|
+
end
|
104
|
+
|
105
|
+
module Ephemeris
|
106
|
+
|
107
|
+
#
|
108
|
+
# Hindu Luni-Solar Calendar Formula
|
109
|
+
#
|
110
|
+
class Hindu < Formula
|
111
|
+
|
112
|
+
# Basic Astronomical Constants for Surya-Siddhanta
|
113
|
+
Tz = 0.5+75.8/360 # time difference between JulianDayNumber and Ujjain
|
114
|
+
E = 588_466 - Tz # Yuga Epoch -3101-02-18T00:00:00
|
115
|
+
P = 180 # Precession cycles in yuga
|
116
|
+
Ep = 1_903_318 - Tz # Precession Epoch 499-01-01
|
117
|
+
Ob = 24.0 / 360.0 # Obliquity of the ecliptic
|
118
|
+
|
119
|
+
Grahas = {
|
120
|
+
'SS' => { # Previous / Newest
|
121
|
+
:Star => 1_582_237_800.0, # 1_582_237_500 / 1_582_237_800
|
122
|
+
:Sun => 4_320_000.0,
|
123
|
+
:Moon => 57_753_336.0,
|
124
|
+
:Mercury => 17_937_000.0,
|
125
|
+
:Venus => 7_022_388.0,
|
126
|
+
:Mars => 2_296_824.0,
|
127
|
+
:Jupiter => 364_220.0,
|
128
|
+
:Saturn => 146_564.0,
|
129
|
+
:Candrocca => 488_219.0, # 488_203 / 488_219
|
130
|
+
:Rahu => -232_226.0
|
131
|
+
},
|
132
|
+
'SB' => {
|
133
|
+
:Star => 1_582_237_828.0,
|
134
|
+
:Sun => 4_320_000.0,
|
135
|
+
:Moon => 57_753_336.0,
|
136
|
+
:Mercury => 17_937_060.0,
|
137
|
+
:Venus => 7_022_376.0,
|
138
|
+
:Mars => 2_296_832.0,
|
139
|
+
:Jupiter => 364_220.0,
|
140
|
+
:Saturn => 146_568.0,
|
141
|
+
:Candrocca => 488_203.0, # 488_199 / 488_203
|
142
|
+
:Rahu => -232_238.0
|
143
|
+
}
|
144
|
+
}
|
145
|
+
|
146
|
+
#
|
147
|
+
# 日月五惑星とラーフおよびケートゥ
|
148
|
+
#
|
149
|
+
# @abstract
|
150
|
+
class Graha
|
151
|
+
include When::Ephemeris
|
152
|
+
end
|
153
|
+
|
154
|
+
#
|
155
|
+
# 現代的“惑星”
|
156
|
+
#
|
157
|
+
class ModernGraha < Graha
|
158
|
+
|
159
|
+
# 真黄経
|
160
|
+
#
|
161
|
+
# @param [Numeric] t ユリウス日
|
162
|
+
#
|
163
|
+
# @return [Numeric]
|
164
|
+
#
|
165
|
+
def true_longitude(t)
|
166
|
+
@target.coords(t, @base).phi
|
167
|
+
end
|
168
|
+
|
169
|
+
# オブジェクトの生成
|
170
|
+
#
|
171
|
+
# @param [When::Ephemeris::Datum] target 天体
|
172
|
+
# @param [When::Coordinates::Spatial] base 観測地
|
173
|
+
#
|
174
|
+
def initialize(target, base)
|
175
|
+
@target = target
|
176
|
+
@base = base
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
#
|
181
|
+
# 古典的“惑星”
|
182
|
+
#
|
183
|
+
# @abstract
|
184
|
+
class ClassicGraha < Graha
|
185
|
+
|
186
|
+
# 平均黄経
|
187
|
+
#
|
188
|
+
# @param [Numeric] t ユリウス日
|
189
|
+
#
|
190
|
+
# @return [Numeric]
|
191
|
+
#
|
192
|
+
def mean_longitude(t)
|
193
|
+
_mean_rotation(t - E)
|
194
|
+
end
|
195
|
+
|
196
|
+
# 真黄経
|
197
|
+
#
|
198
|
+
# @param [Numeric] t ユリウス日
|
199
|
+
#
|
200
|
+
# @return [Numeric]
|
201
|
+
#
|
202
|
+
def true_longitude(t)
|
203
|
+
_true_rotation(t - E)
|
204
|
+
end
|
205
|
+
|
206
|
+
# 平均黄経
|
207
|
+
#
|
208
|
+
# @param [Numeric] ahar カリユガ暦元からの経過日数
|
209
|
+
#
|
210
|
+
# @return [Numeric]
|
211
|
+
#
|
212
|
+
def _mean_rotation(ahar)
|
213
|
+
@rotation * ahar / @formula.civil_days
|
214
|
+
end
|
215
|
+
|
216
|
+
# オブジェクトの生成
|
217
|
+
#
|
218
|
+
# @param [When::Ephemeris::Formula] formula 親オブジェクト
|
219
|
+
# @param [Numeric] rotation ユガあたりの回転数
|
220
|
+
#
|
221
|
+
def initialize(formula, rotation)
|
222
|
+
@formula = formula
|
223
|
+
@rotation = rotation
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
# 架空の“惑星” - ラーフ / 月軌道の遠地点としてのケートゥ
|
228
|
+
class VirtualGraha < ClassicGraha
|
229
|
+
|
230
|
+
# 平均黄経
|
231
|
+
#
|
232
|
+
# @param [Numeric] ahar カリユガ暦元からの経過日数
|
233
|
+
#
|
234
|
+
# @return [Numeric]
|
235
|
+
#
|
236
|
+
def _mean_rotation(ahar)
|
237
|
+
super + @rotation0
|
238
|
+
end
|
239
|
+
alias :_true_rotation :_mean_rotation
|
240
|
+
|
241
|
+
# オブジェクトの生成
|
242
|
+
#
|
243
|
+
# @param [When::Ephemeris::Formula] formula 親オブジェクト
|
244
|
+
# @param [Numeric] rotation ユガあたりの回転数
|
245
|
+
# @param [Numeric] rotation0 カリユガ暦元での回転量
|
246
|
+
#
|
247
|
+
def initialize(formula, rotation, rotation0)
|
248
|
+
@rotation0 = rotation0 / 360.0
|
249
|
+
super(formula, rotation)
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
# 実在の“惑星”
|
254
|
+
# @abstract
|
255
|
+
class RealGraha < ClassicGraha
|
256
|
+
|
257
|
+
# マンダ補正
|
258
|
+
#
|
259
|
+
# @param [Numeric] rot 平均近点角など / CIRCLE
|
260
|
+
#
|
261
|
+
# @return [Numeric]
|
262
|
+
#
|
263
|
+
def _manda_equation(rot)
|
264
|
+
asin(@circumm * sinc(rot)) / CIRCLE
|
265
|
+
end
|
266
|
+
|
267
|
+
# オブジェクトの生成
|
268
|
+
#
|
269
|
+
# @param [When::Ephemeris::Formula] formula 親オブジェクト
|
270
|
+
# @param [Numeric] rotation ユガあたりの回転数
|
271
|
+
# @param [Numeric] circumm マンダ円の半径
|
272
|
+
# @param [Numeric] apogee 近点黄経 / CIRCLE
|
273
|
+
#
|
274
|
+
def initialize(formula, rotation, circumm, apogee)
|
275
|
+
@circumm = circumm / 360.0
|
276
|
+
@apogee = apogee / 360.0
|
277
|
+
super(formula, rotation)
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
# 太陽と月 - 逆行しない“惑星”
|
282
|
+
# @abstract
|
283
|
+
class ConcentricGraha < RealGraha
|
284
|
+
|
285
|
+
# 平均黄経
|
286
|
+
#
|
287
|
+
# @param [Numeric] ahar カリユガ暦元からの経過日数
|
288
|
+
#
|
289
|
+
# @return [Numeric]
|
290
|
+
#
|
291
|
+
def _mean_rotation(ahar)
|
292
|
+
super + @epoch
|
293
|
+
end
|
294
|
+
|
295
|
+
# オブジェクトの生成
|
296
|
+
#
|
297
|
+
# @param [When::Ephemeris::Formula] formula 親オブジェクト
|
298
|
+
# @param [Numeric] rotation ユガあたりの回転数
|
299
|
+
# @param [Numeric] circumm マンダ円の半径
|
300
|
+
# @param [Numeric] apogee 近点黄経 / CIRCLE
|
301
|
+
# @param [Numeric] epoch カリユガ暦元での黄経 / CIRCLE
|
302
|
+
#
|
303
|
+
def initialize(formula, rotation, circumm, apogee, epoch)
|
304
|
+
@epoch = epoch
|
305
|
+
super(formula, rotation, circumm, apogee)
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
# 太陽
|
310
|
+
class Sun < ConcentricGraha
|
311
|
+
|
312
|
+
# 真黄経
|
313
|
+
#
|
314
|
+
# @param [Numeric] ahar カリユガ暦元からの経過日数
|
315
|
+
#
|
316
|
+
# @return [Numeric]
|
317
|
+
#
|
318
|
+
def _true_rotation(ahar)
|
319
|
+
mean = _mean_rotation(ahar)
|
320
|
+
mean - _manda_equation(mean - @apogee)
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
# 月
|
325
|
+
class Moon < ConcentricGraha
|
326
|
+
|
327
|
+
# 真黄経
|
328
|
+
#
|
329
|
+
# @param [Numeric] ahar カリユガ暦元からの経過日数
|
330
|
+
#
|
331
|
+
# @return [Numeric]
|
332
|
+
#
|
333
|
+
def _true_rotation(ahar)
|
334
|
+
mean = _mean_rotation(ahar)
|
335
|
+
mean - _manda_equation(mean - @formula.graha[:Candrocca]._mean_rotation(ahar))
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
# 惑星 - 逆行するもの
|
340
|
+
# @abstract
|
341
|
+
class Planet < RealGraha
|
342
|
+
|
343
|
+
# シグラ補正
|
344
|
+
#
|
345
|
+
# @param [Numeric] anomaly 平均近点角 / CIRCLE
|
346
|
+
#
|
347
|
+
# @return [Numeric]
|
348
|
+
#
|
349
|
+
def _sighra_equation(anomaly)
|
350
|
+
atan2(@circums * sinc(anomaly), @circums * cosc(anomaly) + 1) / CIRCLE
|
351
|
+
end
|
352
|
+
|
353
|
+
# 平均シグラ
|
354
|
+
#
|
355
|
+
# @param [Numeric] ahar カリユガ暦元からの経過日数
|
356
|
+
#
|
357
|
+
# @return [Numeric]
|
358
|
+
#
|
359
|
+
def _mean_sighra(ahar)
|
360
|
+
@sighra * ahar / @formula.civil_days
|
361
|
+
end
|
362
|
+
|
363
|
+
# 真黄経
|
364
|
+
#
|
365
|
+
# @param [Numeric] ahar カリユガ暦元からの経過日数
|
366
|
+
# @param [Numeric] rotation 基準回転量 / CIRCLE
|
367
|
+
#
|
368
|
+
# @return [Numeric]
|
369
|
+
#
|
370
|
+
def _true_rotation(ahar, rotation)
|
371
|
+
# first sighra correction
|
372
|
+
delta = _sighra_equation(_mean_sighra(ahar) - rotation) / 2
|
373
|
+
|
374
|
+
# first manda correction
|
375
|
+
mean = _mean_rotation(ahar) + delta
|
376
|
+
delta = _manda_equation(mean - @apogee) / 2
|
377
|
+
|
378
|
+
# second manda correction
|
379
|
+
mean -= delta
|
380
|
+
delta = _manda_equation(mean - @apogee)
|
381
|
+
|
382
|
+
# second sighra correction
|
383
|
+
mean = _mean_rotation(ahar) - delta
|
384
|
+
delta = _sighra_equation(_mean_sighra(ahar) - mean)
|
385
|
+
|
386
|
+
# true rotation
|
387
|
+
mean + delta
|
388
|
+
end
|
389
|
+
|
390
|
+
# オブジェクトの生成
|
391
|
+
#
|
392
|
+
# @param [When::Ephemeris::Formula] formula 親オブジェクト
|
393
|
+
# @param [Numeric] rotation ユガあたりの回転数
|
394
|
+
# @param [Numeric] circumm マンダ円の半径
|
395
|
+
# @param [Numeric] apogee 近点黄経 / CIRCLE
|
396
|
+
# @param [Numeric] sighra シグラ対象のカリユガあたりの回転数
|
397
|
+
# @param [Numeric] circums シグラ円の半径
|
398
|
+
#
|
399
|
+
def initialize(formula, rotation, circumm, apogee, sighra, circums)
|
400
|
+
@sighra = sighra
|
401
|
+
@circums = circums / 360.0
|
402
|
+
super(formula, rotation, circumm, apogee)
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
# 内惑星 - 水金
|
407
|
+
class InferiorPlanet < Planet
|
408
|
+
|
409
|
+
# 真黄経
|
410
|
+
#
|
411
|
+
# @param [Numeric] t ユリウス日
|
412
|
+
#
|
413
|
+
# @return [Numeric]
|
414
|
+
#
|
415
|
+
def true_longitude(t)
|
416
|
+
ahar = t - E
|
417
|
+
_true_rotation(ahar, @formula.graha[:Sun]._mean_rotation(ahar))
|
418
|
+
end
|
419
|
+
end
|
420
|
+
|
421
|
+
# 外惑星 - 火木土
|
422
|
+
class SuperiorPlanet < Planet
|
423
|
+
|
424
|
+
# 真黄経
|
425
|
+
#
|
426
|
+
# @param [Numeric] t ユリウス日
|
427
|
+
#
|
428
|
+
# @return [Numeric]
|
429
|
+
#
|
430
|
+
def true_longitude(t)
|
431
|
+
ahar = t - E
|
432
|
+
_true_rotation(ahar, _mean_rotation(ahar))
|
433
|
+
end
|
434
|
+
end
|
435
|
+
|
436
|
+
#
|
437
|
+
# ユガの太陽日数
|
438
|
+
#
|
439
|
+
# @return [Numeric]
|
440
|
+
#
|
441
|
+
attr_reader :civil_days
|
442
|
+
|
443
|
+
# 日の出の日時
|
444
|
+
#
|
445
|
+
# @param [Numeric] sdn ユリウス日
|
446
|
+
# @param [When::TM::TemporalPosition] sdn
|
447
|
+
# @param [nil] height 太陽高度(本クラスでは使用しない)
|
448
|
+
#
|
449
|
+
# @return [Integer, When::TM::DateAndTime] 日の出の日時
|
450
|
+
#
|
451
|
+
def sun_rise(sdn, height=nil)
|
452
|
+
t = sdn.to_i - @long / 360.0 - 0.25
|
453
|
+
p = _mean_sun(t) + P * (t - Ep) / @civil_days
|
454
|
+
_to_seed_type(t - asin(tand(@lat)*tan(asin(sinc(p)*sinc(Ob)))) / CIRCLE, sdn)
|
455
|
+
end
|
456
|
+
|
457
|
+
# 日の入りの日時
|
458
|
+
#
|
459
|
+
# @param [Numeric] sdn ユリウス日
|
460
|
+
# @param [When::TM::TemporalPosition] sdn
|
461
|
+
# @param [nil] height 太陽高度(本クラスでは使用しない)
|
462
|
+
#
|
463
|
+
# @return [Integer, When::TM::DateAndTime] 日の入りの日時
|
464
|
+
#
|
465
|
+
def sun_set(sdn, height=nil)
|
466
|
+
t = sdn.to_i - @long / 360.0 + 0.25
|
467
|
+
p = _mean_sun(t) + P * (t - Ep) / @civil_days
|
468
|
+
_to_seed_type(t + asin(tand(@lat)*tan(asin(sinc(p)*sinc(Ob)))) / CIRCLE, sdn)
|
469
|
+
end
|
470
|
+
|
471
|
+
# 太陽の南中の日時
|
472
|
+
#
|
473
|
+
# @param [Numeric] sdn ユリウス日
|
474
|
+
# @param [When::TM::TemporalPosition] sdn
|
475
|
+
#
|
476
|
+
# @return [Integer, When::TM::DateAndTime] 太陽の南中の日時
|
477
|
+
#
|
478
|
+
def sun_noon(sdn)
|
479
|
+
_to_seed_type(sdn.to_i - @long / 360.0, sdn)
|
480
|
+
end
|
481
|
+
|
482
|
+
private
|
483
|
+
|
484
|
+
# オブジェクトの正規化
|
485
|
+
def _normalize(args=[], options={})
|
486
|
+
@time_standard ||= 'universal'
|
487
|
+
@bija ||= 'SB'
|
488
|
+
super
|
489
|
+
end
|
490
|
+
|
491
|
+
# 九惑星オブジェクトの生成
|
492
|
+
def _normalize_grahas
|
493
|
+
grahas = Grahas[@bija]
|
494
|
+
|
495
|
+
# ユガあたりの暦定数
|
496
|
+
@sidereal_days = grahas[:Star] # 恒星日
|
497
|
+
@solar_years = grahas[:Sun] # 太陽年
|
498
|
+
@civil_days = @sidereal_days - @solar_years # 太陽日
|
499
|
+
@sidereal_months = grahas[:Moon] # 恒星月
|
500
|
+
@synodic_months = @sidereal_months - @solar_years # 朔望月
|
501
|
+
@adhimasas = @synodic_months - 12 * @solar_years # 閏月
|
502
|
+
@tithis = 30 * @sidereal_months # 太陰日
|
503
|
+
@ksayadinas = @tithis - @civil_days # 欠日
|
504
|
+
|
505
|
+
# 九惑星
|
506
|
+
@graha = {}
|
507
|
+
@graha.update({
|
508
|
+
:Sun => Sun.new( self, @solar_years, 13+50/60.0, 77+17/60.0, -3101)
|
509
|
+
}) if @formula =~ /[SL]/i
|
510
|
+
@graha.update({
|
511
|
+
:Moon => Moon.new( self, @sidereal_months, 31+50/60.0, 0, -28086),
|
512
|
+
:Candrocca => VirtualGraha.new( self, grahas[:Candrocca], 90.0)
|
513
|
+
}) if @formula =~ /[ML]/i
|
514
|
+
@graha.update({
|
515
|
+
:Mercury => InferiorPlanet.new(self, @solar_years, 29.0, 220+27/60.0, grahas[:Mercury], 131.5),
|
516
|
+
:Venus => InferiorPlanet.new(self, @solar_years, 11.5, 79+50/60.0, grahas[:Venus], 261.0),
|
517
|
+
:Mars => SuperiorPlanet.new(self, grahas[:Mars], 73.5, 130+02/60.0, @solar_years, 233.5),
|
518
|
+
:Jupiter => SuperiorPlanet.new(self, grahas[:Jupiter], 32.5, 171+18/60.0, @solar_years, 71.0),
|
519
|
+
:Saturn => SuperiorPlanet.new(self, grahas[:Saturn], 48.5, 236+37/60.0, @solar_years, 39.5),
|
520
|
+
:Rahu => VirtualGraha.new( self, grahas[:Rahu], 180.0)
|
521
|
+
}) if @formula == '2L'
|
522
|
+
end
|
523
|
+
end
|
524
|
+
end
|
525
|
+
|
526
|
+
class TM::CalendarEra
|
527
|
+
|
528
|
+
Indian = [self, [
|
529
|
+
"namespace:[en=http://en.wikipedia.org/wiki/, ja=http://ja.wikipedia.org/wiki/]",
|
530
|
+
"locale:[=en:, ja=ja:, alias]",
|
531
|
+
"area:[IndianNationalSolar=en:Indian_national_calendar, インド国定暦]",
|
532
|
+
["[SE=, サカ暦=, alias:Saka_Era]1.1.1", "Calendar Epoch", "79-01-01^IndianNationalSolar"]
|
533
|
+
]]
|
534
|
+
end
|
535
|
+
|
536
|
+
module CalendarTypes
|
537
|
+
|
538
|
+
#
|
539
|
+
# Indian national solar calendar
|
540
|
+
#
|
541
|
+
IndianNationalSolar = [CyclicTableBased, {
|
542
|
+
'label' => When.Resource('_m:IndianTerms::IndianNationalSolar'),
|
543
|
+
'origin_of_LSC' => 1721140,
|
544
|
+
'indices' => [
|
545
|
+
When::Coordinates::Index.new({:unit =>12, :trunk=>When.Resource('_m:IndianTerms::LunarMonth::*'), :shift=>4}),
|
546
|
+
When::Coordinates::Index.new
|
547
|
+
],
|
548
|
+
'rule_table' => {
|
549
|
+
'T' => {'Rule' =>['LC', 'SC', 'SC', 'SC']},
|
550
|
+
'SC' => {'Rule' =>[365]*4 + [366, 365, 365, 365]*24},
|
551
|
+
'LC' => {'Rule' =>[366, 365, 365, 365]*25},
|
552
|
+
365 => {'Length'=>[30] + [31]*5 + [30]*6},
|
553
|
+
366 => {'Length'=> [31]*6 + [30]*6}
|
554
|
+
},
|
555
|
+
}]
|
556
|
+
|
557
|
+
#
|
558
|
+
# Hindu Solar Calendar
|
559
|
+
#
|
560
|
+
class HinduSolar < EphemerisBasedSolar
|
561
|
+
|
562
|
+
# protected
|
563
|
+
|
564
|
+
# 月初の通日
|
565
|
+
#
|
566
|
+
# @param [Integer] m 通月
|
567
|
+
#
|
568
|
+
# @return [Integer] 月初の通日
|
569
|
+
#
|
570
|
+
def _new_month_(m)
|
571
|
+
new_month_time = @formula[0].cn_to_time(m + @cycle_offset)
|
572
|
+
new_month_date = (new_month_time + 0.5 + @formula[0].long/360.0).floor
|
573
|
+
sun_rise_time = @formula[0].sun_rise(new_month_date)
|
574
|
+
(sun_rise_time <= new_month_time) ? new_month_date : new_month_date-1
|
575
|
+
end
|
576
|
+
|
577
|
+
private
|
578
|
+
|
579
|
+
# オブジェクトの正規化
|
580
|
+
#
|
581
|
+
# @formula[0] = 位相の計算に用いる太陽の Formula
|
582
|
+
# @cycle_offset = 位相のオフセット
|
583
|
+
# @start_month = 暦年の最初の月
|
584
|
+
#
|
585
|
+
def _normalize(args=[], options={})
|
586
|
+
@label ||= When.Resource('_m:IndianTerms::HinduSolar')
|
587
|
+
@type ||= 'SBS'
|
588
|
+
raise ArgumentError, "Irregal formula: #{@formula}" unless @type.upcase =~ /^(M|SS|SB)(V|S|VZ|SZ)$/
|
589
|
+
|
590
|
+
@location ||= HinduLuniSolar::Location[$1]
|
591
|
+
@cycle_offset ||= HinduLuniSolar::CycleOffset[$1]
|
592
|
+
@origin_of_MSC ||= -HinduLuniSolar::YearEpoch[$2]
|
593
|
+
@epoch_in_CE ||= 0
|
594
|
+
@start_month ||= 1 # Maysha
|
595
|
+
@start_month = @start_month.to_i
|
596
|
+
@cycle_offset = @cycle_offset.to_f + (@start_month - 1)
|
597
|
+
formula = @formula || HinduLuniSolar::Formula[$1]
|
598
|
+
if formula.kind_of?(String)
|
599
|
+
formula += (formula =~ /\?/) ? '&' : '?'
|
600
|
+
@formula = [When.Resource("_ep:#{formula}location=#{@location}&formula=12S")]
|
601
|
+
end
|
602
|
+
@indices ||= [
|
603
|
+
Coordinates::Index.new({:trunk=>When.Resource('_m:IndianTerms::SolarMonth::*'),
|
604
|
+
:shift=>@start_month-1}),
|
605
|
+
Coordinates::Index.new
|
606
|
+
]
|
607
|
+
|
608
|
+
super
|
609
|
+
end
|
610
|
+
end
|
611
|
+
|
612
|
+
#
|
613
|
+
# Hindu Luni-Solar Calendar
|
614
|
+
#
|
615
|
+
class HinduLuniSolar < EphemerisBasedLuniSolar
|
616
|
+
|
617
|
+
# Calendar Type
|
618
|
+
Formula = {'M'=>'Formula', 'SS'=>'Hindu?bija=SS', 'SB'=>'Hindu?bija=SB'}
|
619
|
+
Location = {'M'=>'_co:IndianCities::CentralIndia', 'SS'=>'_co:IndianCities::Ujjain', 'SB'=>'_co:IndianCities::Ujjain'}
|
620
|
+
CycleOffset = {'M'=>+23.25/30, 'SS'=>0.0, 'SB'=>0.0}
|
621
|
+
HinduStyle = {'A'=>0, 'P'=>1, 'PX'=>2}
|
622
|
+
YearEpoch = {'V'=>-58,'VZ'=>-57,'S'=>78, 'SZ'=>79}
|
623
|
+
|
624
|
+
# White / black month and leap month identification table
|
625
|
+
|
626
|
+
#[w]/b [n]/l #0 #1 #2
|
627
|
+
LEAP_MAP = {[nil, false] => [ 0, 0, 0 ],
|
628
|
+
[nil, true ] => [-1.5, -1.5, -1.5],
|
629
|
+
[true, false] => [+0.5, -0.5, -2.5],
|
630
|
+
[true, true ] => [-1, -2, -1 ]}
|
631
|
+
|
632
|
+
# protected
|
633
|
+
|
634
|
+
# 月初の通日
|
635
|
+
#
|
636
|
+
# @param [Integer] m 通月
|
637
|
+
#
|
638
|
+
# @return [Integer] 月初の通日
|
639
|
+
#
|
640
|
+
def _new_month_(m)
|
641
|
+
new_moon_time = @formula[-1].cn_to_time(m)
|
642
|
+
new_moon_date = (new_moon_time + 0.5 + @formula[-1].long/360.0).floor
|
643
|
+
sun_rise_time = @formula[-1].sun_rise(new_moon_date)
|
644
|
+
(sun_rise_time >= new_moon_time) ? new_moon_date : new_moon_date+1
|
645
|
+
end
|
646
|
+
|
647
|
+
# 年初の通月
|
648
|
+
#
|
649
|
+
# @param [Integer] y 年
|
650
|
+
#
|
651
|
+
# @return [Integer] 年初の通月
|
652
|
+
#
|
653
|
+
def _new_year_month_(y)
|
654
|
+
(Residue.mod(y-1) {|t| _tithi_to_coordinates(t*15)[0]})[0] + 1
|
655
|
+
end
|
656
|
+
|
657
|
+
# 朔望日 -> 年・月・日
|
658
|
+
#
|
659
|
+
# tithi : 朔望日(月の位相 / (CIRCLE/30))
|
660
|
+
#
|
661
|
+
# @return [Array<Numeric>] ( y, m, d )
|
662
|
+
# [ y - 年(Integer) ]
|
663
|
+
# [ m - 月(When::Coordinates::Pair) ]
|
664
|
+
# [ d - 日(Integer) ]
|
665
|
+
#
|
666
|
+
def _tithi_to_coordinates(tithi)
|
667
|
+
m, d = tithi.divmod(30)
|
668
|
+
s = [0,1,2].map {|i| (@formula[1].time_to_cn(30*(m+i)) - @cycle_offset).floor + 1 }
|
669
|
+
f = s[0]==s[1]
|
670
|
+
if (d >= 15.0)
|
671
|
+
d -= 15
|
672
|
+
b = true
|
673
|
+
n = true unless @hindu_style==0
|
674
|
+
f = s[1]==s[2] if @hindu_style==1
|
675
|
+
end
|
676
|
+
y, m = (n ? s[1] : s[0]).divmod(12)
|
677
|
+
return [y, Pair._force_pair(m+1, LEAP_MAP[[b,f]][@hindu_style]), d.floor]
|
678
|
+
end
|
679
|
+
|
680
|
+
# 日時要素の翻訳表の取得
|
681
|
+
#
|
682
|
+
# @overload _ids_(date)
|
683
|
+
# @param [Array<Numeric>] date ( 年 )
|
684
|
+
# @return [Array<When::Coordinates::Pair>] 1年の月の配置の翻訳表
|
685
|
+
#
|
686
|
+
# @overload _ids_(date)
|
687
|
+
# @param [Array<Numeric>] date ( 年 月 )
|
688
|
+
# @return [Array<When::Coordinates::Pair>] 1月の日の配置の翻訳表
|
689
|
+
# @note 月は 0 始まりの通番
|
690
|
+
#
|
691
|
+
def _ids_(date)
|
692
|
+
y, m = date
|
693
|
+
y = +y
|
694
|
+
mm = _new_year_month(y)
|
695
|
+
return (_table(_new_month_(mm+m.to_i)) {|i| _new_month(mm+m+i/15.0)}) if m
|
696
|
+
table = (0...26).to_a.map {|i| _tithi_to_coordinates((mm+i)*15)[1]}
|
697
|
+
table.pop while table[-1].trunk < 11
|
698
|
+
return table
|
699
|
+
end
|
700
|
+
|
701
|
+
private
|
702
|
+
|
703
|
+
# 日時要素の翻訳表の作成
|
704
|
+
def _table(b0)
|
705
|
+
table = [Pair._force_pair(0,0)]
|
706
|
+
(1..16).each do |i|
|
707
|
+
b1 = yield(i)
|
708
|
+
case b1-b0
|
709
|
+
when 0 ; table[-1] = Pair._force_pair(i-1, -2)
|
710
|
+
when 1 ; table << Pair._force_pair(i, 0)
|
711
|
+
when 2 ; table << Pair._force_pair(i, 0) << Pair._force_pair(i, 1)
|
712
|
+
else ; raise ArgumentError, "Irregal date span: #{b1-b0}"
|
713
|
+
end
|
714
|
+
b0 = b1
|
715
|
+
end
|
716
|
+
table.pop while table[-1].trunk >= 16
|
717
|
+
table.shift
|
718
|
+
return table
|
719
|
+
end
|
720
|
+
|
721
|
+
# オブジェクトの正規化
|
722
|
+
#
|
723
|
+
# @formula = 位相の計算に用いる太陽・変換・月の Formula
|
724
|
+
# @cycle_offset = 位相のオフセット
|
725
|
+
# @hindu_style = 閏月の表現方法
|
726
|
+
# @start_month = 暦年の最初の月
|
727
|
+
#
|
728
|
+
def _normalize(args=[], options={})
|
729
|
+
@label ||= When.Resource('_m:IndianTerms::HinduLuniSolar')
|
730
|
+
@type ||= 'SBSA'
|
731
|
+
raise ArgumentError, "Irregal formula: #{@formula}" unless @type.upcase =~ /^(M|SS|SB)(V|S|VZ|SZ)(A|P|PX)$/
|
732
|
+
|
733
|
+
@location ||= Location[$1]
|
734
|
+
@cycle_offset ||= CycleOffset[$1]
|
735
|
+
@origin_of_MSC ||= -YearEpoch[$2]
|
736
|
+
@hindu_style ||= HinduStyle[$3]
|
737
|
+
@epoch_in_CE ||= 0
|
738
|
+
@start_month ||= 5 # Chaitra
|
739
|
+
@start_month = @start_month.to_i
|
740
|
+
@cycle_offset = @cycle_offset.to_f + (@start_month - 5)
|
741
|
+
@hindu_style = @hindu_style.to_i
|
742
|
+
@origin_of_MSC = @origin_of_MSC.to_i
|
743
|
+
formula = @formula || Formula[$1]
|
744
|
+
if formula.kind_of?(String)
|
745
|
+
formula += (formula =~ /\?/) ? '&' : '?'
|
746
|
+
@formula = When.Resource(["_ep:#{formula}formula=12S",
|
747
|
+
"_ep:#{formula}formula=30L->12S",
|
748
|
+
"_ep:#{formula}location=#{@location}&formula=2L"])
|
749
|
+
end
|
750
|
+
intercalary_month = When.Resource('_m:IndianTerms::IntercalaryMonth::*')
|
751
|
+
intercalary_day = When.Resource('_m:IndianTerms::IntercalaryDay::*')
|
752
|
+
@indices ||= [
|
753
|
+
Coordinates::Index.new({:branch=>{-2.5 => intercalary_month[1], # 黒分
|
754
|
+
-2 => intercalary_month[3], # 閏黒分
|
755
|
+
-1.5 => intercalary_month[2], # 閏白分
|
756
|
+
-1 => intercalary_month[3], # 閏黒分
|
757
|
+
-0.5 => intercalary_month[1], # 黒分
|
758
|
+
0 => intercalary_month[0], # 白分
|
759
|
+
+0.5 => intercalary_month[1]}, # 黒分
|
760
|
+
:trunk=>When.Resource('_m:IndianTerms::LunarMonth::*'),
|
761
|
+
:shift=>@start_month-1}),
|
762
|
+
Coordinates::Index.new({:branch=>{-2=>intercalary_day[0], -1=>intercalary_day[1]}})
|
763
|
+
]
|
764
|
+
|
765
|
+
super
|
766
|
+
end
|
767
|
+
end
|
768
|
+
|
769
|
+
class CalendarNote
|
770
|
+
#
|
771
|
+
# ヒンドゥー系の暦注
|
772
|
+
#
|
773
|
+
class HinduNote < self
|
774
|
+
|
775
|
+
NoteObjects = [When::BasicTypes::M17n, [
|
776
|
+
"namespace:[en=http://en.wikipedia.org/wiki/, ja=http://ja.wikipedia.org/wiki/]",
|
777
|
+
"locale:[=en:, ja=ja:, alias=ja:]",
|
778
|
+
"names:[Hindu]",
|
779
|
+
|
780
|
+
# 年の暦注 ----------------------------
|
781
|
+
[When::BasicTypes::M17n,
|
782
|
+
"names:[year]"
|
783
|
+
],
|
784
|
+
|
785
|
+
# 月の暦注 ----------------------------
|
786
|
+
[When::BasicTypes::M17n,
|
787
|
+
"names:[month]",
|
788
|
+
[When::BasicTypes::M17n,
|
789
|
+
"names:[Month]"
|
790
|
+
]
|
791
|
+
],
|
792
|
+
|
793
|
+
# 日の暦注 ----------------------------
|
794
|
+
[When::BasicTypes::M17n,
|
795
|
+
"names:[day]",
|
796
|
+
|
797
|
+
[When::BasicTypes::M17n,
|
798
|
+
"names:[tithi=, ティティ=ja:%E3%83%86%E3%82%A3%E3%83%86%E3%82%A3]",
|
799
|
+
"[Amavasya ]", # 新月
|
800
|
+
"[Pratipad=en:Prathama_(day)]", # 1
|
801
|
+
"[Dwitiya ]", # 2
|
802
|
+
"[Tritiya ]", # 3
|
803
|
+
"[Chaturthi ]", # 4
|
804
|
+
"[Panchami ]", # 5
|
805
|
+
"[Ṣaṣṭhī=en:Shashti ]", # 6
|
806
|
+
"[Saptami ]", # 7
|
807
|
+
"[Ashtami ]", # 8
|
808
|
+
"[Navami ]", # 9
|
809
|
+
"[Dashami ]", # 10
|
810
|
+
"[Ekadashi ]", # 11
|
811
|
+
"[Dwadashi ]", # 12
|
812
|
+
"[Thrayodashi ]", # 13
|
813
|
+
"[Chaturdashi ]", # 14
|
814
|
+
"[Purnima ]" # 満月
|
815
|
+
],
|
816
|
+
|
817
|
+
[When::BasicTypes::M17n,
|
818
|
+
"names:[vāra=, ヴァーラ=, *vara=]",
|
819
|
+
"[Ravi=en:S%C5%ABrya, 日曜日]",
|
820
|
+
"[Soma, 月曜日]",
|
821
|
+
"[Maṅgala=en:Mangala, 火曜日]",
|
822
|
+
"[Budha, 水曜日]",
|
823
|
+
"[Guru, 木曜日]",
|
824
|
+
"[Śukra=en:Shukra, 金曜日]",
|
825
|
+
"[Śani=en:Shani, 土曜日]"
|
826
|
+
],
|
827
|
+
|
828
|
+
[When::BasicTypes::M17n,
|
829
|
+
"names:[nakṣatra=, ナクシャトラ=, *naksatra=]",
|
830
|
+
"[Aśvinī=en:Ashvin%C4%AB, アシュヴィニー=, 婁宿]", # 1
|
831
|
+
"[Bharaṇī=en:Bharan%C4%AB, バラニー=, 胃宿]", # 2
|
832
|
+
"[Kṛttikā=en:Krittik%C4%81, クリッティカー=, 昴宿]", # 3
|
833
|
+
"[Rohiṇī=en:Rohini_(nakshatra), ローヒニ―=, 畢宿]", # 4
|
834
|
+
"[Mṛgaśiras=en:Mrigash%C4%ABrsha, ムリガシラス=, 觜宿]", # 5
|
835
|
+
"[Ārdrā=en:Ardra_(nakshatra), アールドラー=, 參宿]", # 6
|
836
|
+
"[Punarvasu=en:Punarvasu, プナルヴァス=, 井宿]", # 7
|
837
|
+
"[Puṣya=en:Pushya, プシュヤ=, 鬼宿]", # 8
|
838
|
+
"[Aśleṣā=en:%C4%80shlesh%C4%81, アーシュレーシャー=, 柳宿]", # 9
|
839
|
+
"[Maghā=en:Magh%C4%81, マガー=, 星宿]", # 10
|
840
|
+
"[P. Phalguṇī=en:P%C5%ABrva_Phalgun%C4%AB, P. パールグニー=, 張宿]", # 11
|
841
|
+
"[U. Phalguṇī=en:Uttara_Phalgun%C4%AB, U. パールグニー=, 翼宿]", # 12
|
842
|
+
"[Hasta=en:Nakshatra#Divisions, ハスタ=, 軫宿]", # 13
|
843
|
+
"[Citrā=en:Nakshatra#Divisions, チトラー=, 角宿]", # 14
|
844
|
+
"[Svāti=en:Sv%C4%81t%C4%AB, スヴァーティー=, 亢宿]", # 15
|
845
|
+
"[Viśākha=en:Vish%C4%81kh%C4%81, ヴィシャーカー=, 氐宿]", # 16
|
846
|
+
"[Anurādhā=en:Anur%C4%81dh%C4%81, アヌラーダー=, 房宿]", # 17
|
847
|
+
"[Jyeṣṭha=en:Jyeshtha, ジェーシュター=, 心宿]", # 18
|
848
|
+
"[Mūla=en:Mula_(astrology), ムーラ=, 尾宿]", # 19
|
849
|
+
"[P. āṣāḍha=en:P%C5%ABrva_Ash%C4%81dh%C4%81, P. アーシャーダー=, 箕宿]", # 20
|
850
|
+
"[U. āṣāḍha=en:Uttara_Ash%C4%81dh%C4%81, U. アーシャーダー=, 斗宿]", # 21
|
851
|
+
"[Śravaṇa=en:Shravana, シュラヴァナ=, 女宿]", # 22
|
852
|
+
"[Śraviṣṭhā=en:Dhanishta, ダニシュター=, 虛宿]", # 23
|
853
|
+
"[Śatabhiṣak=en:Shatabhish%C4%81, シャタビシャジュ=, 危宿]", # 24
|
854
|
+
"[P. Bhādrapadā=en:P%C5%ABrva_Bh%C4%81drapad%C4%81, P. バードラパダー=, 室宿]", # 25
|
855
|
+
"[U. Bhādrapadā=en:Uttara_Bh%C4%81drapad%C4%81, U. バードラパダー=, 壁宿]", # 26
|
856
|
+
"[Revatī=en:Revati_(nakshatra), レーヴァティー=, 奎宿]" # 27
|
857
|
+
],
|
858
|
+
|
859
|
+
[When::BasicTypes::M17n,
|
860
|
+
"names:[yoga=, ヨーガ=]",
|
861
|
+
"[iṣkambha=]", # 1
|
862
|
+
"[rīti= ]", # 2
|
863
|
+
"[yuśmān= ]", # 3
|
864
|
+
"[aubhāgya=]", # 4
|
865
|
+
"[obhana= ]", # 5
|
866
|
+
"[tigaṇḍa= ]", # 6
|
867
|
+
"[ukarma= ]", # 7
|
868
|
+
"[hṛti= ]", # 8
|
869
|
+
"[ūla= ]", # 9
|
870
|
+
"[aṇḍa= ]", # 10
|
871
|
+
"[ṛddhi= ]", # 11
|
872
|
+
"[hruva= ]", # 12
|
873
|
+
"[yāghatā= ]", # 13
|
874
|
+
"[arṣaṇa= ]", # 14
|
875
|
+
"[ajra= ]", # 15
|
876
|
+
"[iddhi= ]", # 16
|
877
|
+
"[yatipāta=]", # 17
|
878
|
+
"[ariyas= ]", # 18
|
879
|
+
"[arigha= ]", # 19
|
880
|
+
"[iva= ]", # 20
|
881
|
+
"[iddha= ]", # 21
|
882
|
+
"[ādhya= ]", # 22
|
883
|
+
"[ubha= ]", # 23
|
884
|
+
"[ukla= ]", # 24
|
885
|
+
"[rahma= ]", # 25
|
886
|
+
"[āhendra= ]", # 26
|
887
|
+
"[aidhṛti= ]" # 27
|
888
|
+
],
|
889
|
+
|
890
|
+
[When::BasicTypes::M17n,
|
891
|
+
"names:[Karaṇa=, カラナ=, *karana]",
|
892
|
+
"[Bava=, バヴァ= ]", # 1
|
893
|
+
"[Bālava=, バーラヴァ= ]", # 2
|
894
|
+
"[Kaulava=, カウラヴァ= ]", # 3
|
895
|
+
"[Taitila=, タイティラ= ]", # 4
|
896
|
+
"[Gara=, ガラ= ]", # 5
|
897
|
+
"[Vaṇija=, ヴァニジュ= ]", # 6
|
898
|
+
"[Viṣṭi=, ヴィシュティ= ]", # 7
|
899
|
+
"[Kiṃtughna=, キンストゥグナ=]", # A
|
900
|
+
"[Śakuni=, シャクニ= ]", # B
|
901
|
+
"[Catuṣpāda=, チャトシュパダ=]", # C
|
902
|
+
"[Nāga=, ナーガ= ]" # D
|
903
|
+
]
|
904
|
+
]
|
905
|
+
]]
|
906
|
+
|
907
|
+
NoteConsts = {
|
908
|
+
'tithi' => {
|
909
|
+
:formula => 15,
|
910
|
+
:range => (-1..2),
|
911
|
+
:index => [ 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,
|
912
|
+
15,1,2,3,4,5,6,7,8,9,10,11,12,13,14]
|
913
|
+
},
|
914
|
+
'naksatra' => {
|
915
|
+
:formula => '27M',
|
916
|
+
:range => (-1..2),
|
917
|
+
:index => (0...27).to_a
|
918
|
+
},
|
919
|
+
'yoga' => {
|
920
|
+
:formula => '27M+27S',
|
921
|
+
:range => (-1..2),
|
922
|
+
:index => (0...27).to_a
|
923
|
+
},
|
924
|
+
'karana' => {
|
925
|
+
:formula => 30,
|
926
|
+
:range => (-2..3),
|
927
|
+
:index => [7] + (0...7).to_a * 8 + [8,9,10]
|
928
|
+
}
|
929
|
+
}
|
930
|
+
|
931
|
+
#
|
932
|
+
# pancanga 計算に必要となる情報をまとめた内部クラス
|
933
|
+
#
|
934
|
+
class Dates
|
935
|
+
|
936
|
+
# @private
|
937
|
+
attr_reader :o_date, :l_date, :root, :formula, :iri, :rises
|
938
|
+
|
939
|
+
# 初期設定
|
940
|
+
# @private
|
941
|
+
def initialize(date)
|
942
|
+
@o_date = date
|
943
|
+
clock = date.clock
|
944
|
+
frame = date.frame if date.frame.kind_of?(When::CalendarTypes::HinduLuniSolar)
|
945
|
+
@l_date = (clock && frame) ? date :
|
946
|
+
(frame || When.Calendar('HinduLuniSolar?note=HinduNote')).jul_trans(date, {:clock=>clock||'+05:30'})
|
947
|
+
@root = When.CalendarNote('HinduNote/NoteObjects')['day']
|
948
|
+
@formula = @l_date.frame.formula[-1]
|
949
|
+
@iri = @formula.iri.gsub(/%3A%3A/, '::')
|
950
|
+
@rises = [@formula.sun_rise(@l_date), @formula.sun_rise(@l_date+When.Duration('P1D'))]
|
951
|
+
end
|
952
|
+
|
953
|
+
# その他のメソッドは @l_date に移譲する
|
954
|
+
def method_missing(name, *args, &block)
|
955
|
+
@l_date.send(name.to_sym, *args, &block)
|
956
|
+
end
|
957
|
+
end
|
958
|
+
|
959
|
+
#
|
960
|
+
# 任意の暦をインド太陰太陽暦日に変換
|
961
|
+
# @private
|
962
|
+
def _to_date_for_note(date)
|
963
|
+
Dates.new(date)
|
964
|
+
end
|
965
|
+
|
966
|
+
#
|
967
|
+
# ヴァーラ (七曜)
|
968
|
+
#
|
969
|
+
# @param [Dates] dates
|
970
|
+
#
|
971
|
+
# @return [Array<When::TM::TemporalPosition>] 日の出の時刻をイベント時刻とする
|
972
|
+
#
|
973
|
+
def vara(dates)
|
974
|
+
rise = dates.rises[0]
|
975
|
+
rise.events = [dates.root['vara'][(rise.to_i+1) % 7]]
|
976
|
+
[rise]
|
977
|
+
end
|
978
|
+
|
979
|
+
#
|
980
|
+
# ヴァーラ以外
|
981
|
+
#
|
982
|
+
|
983
|
+
# 当該日付中でティティが変わる日時
|
984
|
+
# @method tithi(dates)
|
985
|
+
# @param [Dates] dates
|
986
|
+
# @return [Array<When::TM::TemporalPosition>] イベント日時
|
987
|
+
|
988
|
+
# 当該日付中でナクシャトラが変わる日時
|
989
|
+
# @method naksatra(dates)
|
990
|
+
# @param [Dates] dates
|
991
|
+
# @return [Array<When::TM::TemporalPosition>] イベント日時
|
992
|
+
|
993
|
+
# 当該日付中でヨーガが変わる日時
|
994
|
+
# @method yoga(dates)
|
995
|
+
# @param [Dates] dates
|
996
|
+
# @return [Array<When::TM::TemporalPosition>] イベント日時
|
997
|
+
|
998
|
+
# 当該日付中でカラナが変わる日時
|
999
|
+
# @method karana(dates)
|
1000
|
+
# @param [Dates] dates
|
1001
|
+
# @return [Array<When::TM::TemporalPosition>] イベント日時
|
1002
|
+
#
|
1003
|
+
|
1004
|
+
# @private
|
1005
|
+
NoteConsts.keys.each do |key|
|
1006
|
+
module_eval %Q{
|
1007
|
+
def #{key}(dates)
|
1008
|
+
pancanga(dates, '#{key}')
|
1009
|
+
end
|
1010
|
+
}
|
1011
|
+
end
|
1012
|
+
|
1013
|
+
#
|
1014
|
+
# ヴァーラ以外のイベント日時
|
1015
|
+
#
|
1016
|
+
# @param [Dates] dates
|
1017
|
+
# @param [String] key 'tithi', 'naksatra', 'yoga', 'karana' のいずれか
|
1018
|
+
# @return [Array<When::TM::TemporalPosition>] イベント日時
|
1019
|
+
#
|
1020
|
+
def pancanga(dates, key)
|
1021
|
+
pattern = NoteConsts[key]
|
1022
|
+
note = dates.root[key]
|
1023
|
+
if pattern[:formula].kind_of?(Numeric)
|
1024
|
+
factor = pattern[:formula].to_f
|
1025
|
+
formula = dates.formula
|
1026
|
+
else
|
1027
|
+
factor = 1.0
|
1028
|
+
formula = When.Resource(dates.iri.sub(/formula=2L/, "formula=#{pattern[:formula]}"))
|
1029
|
+
end
|
1030
|
+
cn = (formula.time_to_cn(dates.l_date) * factor).floor
|
1031
|
+
events = []
|
1032
|
+
pattern[:range].each do |i|
|
1033
|
+
event = formula._to_seed_type(formula.cn_to_time((cn+i)/factor), dates.l_date)
|
1034
|
+
break if +event >= +dates.rises[1]
|
1035
|
+
next if +event < +dates.rises[0]
|
1036
|
+
event.events = [note[pattern[:index][(cn+i) % pattern[:index].length]]]
|
1037
|
+
events << event
|
1038
|
+
end
|
1039
|
+
events
|
1040
|
+
end
|
1041
|
+
end
|
1042
|
+
|
1043
|
+
#
|
1044
|
+
# 日の出の九惑星の位置まで計算
|
1045
|
+
#
|
1046
|
+
class HinduNoteDetailed < HinduNote
|
1047
|
+
#
|
1048
|
+
# ヴァーラ (七曜)と九惑星の位置
|
1049
|
+
#
|
1050
|
+
# @param [Dates] dates
|
1051
|
+
# @return [Array<When::TM::TemporalPosition, Hash{ 惑星シンボル=>惑星の真黄経 }>]
|
1052
|
+
# 日の出の時刻をイベント時刻とし、その時刻での九惑星の位置を計算
|
1053
|
+
#
|
1054
|
+
def vara(dates)
|
1055
|
+
rise = dates.rises[0]
|
1056
|
+
rise.events = [dates.root['vara'][(rise.to_i+1) % 7]]
|
1057
|
+
t = dates.formula.is_dynamical ? +rise : rise.to_f
|
1058
|
+
[rise, dates.formula.graha.keys.inject({}) {|h,p|
|
1059
|
+
h.store(p, dates.formula.graha[p].true_longitude(t))
|
1060
|
+
h
|
1061
|
+
}]
|
1062
|
+
end
|
1063
|
+
end
|
1064
|
+
end
|
1065
|
+
end
|
1066
|
+
end
|