when_exe 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +36 -33
  3. data/bin/locales.rb +1 -1
  4. data/bin/make_ttl.rb.config +1 -1
  5. data/lib/when_exe.rb +27 -16
  6. data/lib/when_exe/basictypes.rb +772 -771
  7. data/lib/when_exe/calendartypes.rb +1485 -1453
  8. data/lib/when_exe/coordinates.rb +5 -0
  9. data/lib/when_exe/core/compatibility.rb +1 -1
  10. data/lib/when_exe/core/duration.rb +147 -116
  11. data/lib/when_exe/core/extension.rb +499 -497
  12. data/lib/when_exe/ephemeris.rb +1952 -1951
  13. data/lib/when_exe/ephemeris/eclipse.rb +5 -4
  14. data/lib/when_exe/ephemeris/notes.rb +457 -421
  15. data/lib/when_exe/ephemeris/planets.rb +585 -585
  16. data/lib/when_exe/ephemeris/sun.rb +214 -214
  17. data/lib/when_exe/google_api.rb +153 -0
  18. data/lib/when_exe/icalendar.rb +1640 -1632
  19. data/lib/when_exe/inspect.rb +42 -20
  20. data/lib/when_exe/linkeddata.rb +28 -7
  21. data/lib/when_exe/locales/autoload.rb +2 -1
  22. data/lib/when_exe/locales/locale.rb +35 -15
  23. data/lib/when_exe/locales/zh.rb +77 -0
  24. data/lib/when_exe/mini_application.rb +3 -1
  25. data/lib/when_exe/{googlecalendar.rb → obsolete/googlecalendar.rb} +144 -144
  26. data/lib/when_exe/parts/enumerator.rb +498 -486
  27. data/lib/when_exe/parts/geometric_complex.rb +397 -397
  28. data/lib/when_exe/parts/timezone.rb +246 -241
  29. data/lib/when_exe/region/armenian.rb +55 -56
  30. data/lib/when_exe/region/babylonian.rb +406 -405
  31. data/lib/when_exe/region/bahai.rb +107 -106
  32. data/lib/when_exe/region/balinese.rb +624 -622
  33. data/lib/when_exe/region/chinese.rb +1071 -1026
  34. data/lib/when_exe/region/chinese/epochs.rb +28 -28
  35. data/lib/when_exe/region/chinese/notes.rb +219 -0
  36. data/lib/when_exe/region/chinese/twins.rb +803 -803
  37. data/lib/when_exe/region/christian.rb +21 -15
  38. data/lib/when_exe/region/coptic.rb +107 -106
  39. data/lib/when_exe/region/discordian.rb +218 -218
  40. data/lib/when_exe/region/east_asian.rb +1 -1
  41. data/lib/when_exe/region/french.rb +126 -56
  42. data/lib/when_exe/region/geologicalage.rb +639 -639
  43. data/lib/when_exe/region/goddess.rb +60 -58
  44. data/lib/when_exe/region/hanke_henry.rb +2 -2
  45. data/lib/when_exe/region/indian.rb +1225 -1222
  46. data/lib/when_exe/region/international_fixed.rb +96 -97
  47. data/lib/when_exe/region/iranian.rb +206 -203
  48. data/lib/when_exe/region/islamic.rb +102 -102
  49. data/lib/when_exe/region/japanese.rb +126 -71
  50. data/lib/when_exe/region/japanese/epochs.rb +426 -426
  51. data/lib/when_exe/region/japanese/notes.rb +101 -81
  52. data/lib/when_exe/region/japanese/residues.rb +1345 -1311
  53. data/lib/when_exe/region/japanese/twins.rb +225 -225
  54. data/lib/when_exe/region/japanese/weeks.rb +112 -112
  55. data/lib/when_exe/region/javanese.rb +230 -230
  56. data/lib/when_exe/region/jewish.rb +130 -131
  57. data/lib/when_exe/region/m17n.rb +114 -114
  58. data/lib/when_exe/region/martian.rb +258 -258
  59. data/lib/when_exe/region/mayan.rb +11 -8
  60. data/lib/when_exe/region/pax.rb +4 -5
  61. data/lib/when_exe/region/pope.rb +1 -1
  62. data/lib/when_exe/region/positivist.rb +100 -100
  63. data/lib/when_exe/region/residue.rb +162 -162
  64. data/lib/when_exe/region/roman.rb +333 -333
  65. data/lib/when_exe/region/{soviet.rb → russian.rb} +221 -209
  66. data/lib/when_exe/region/shire.rb +222 -223
  67. data/lib/when_exe/region/symmetry.rb +50 -50
  68. data/lib/when_exe/region/thai.rb +336 -336
  69. data/lib/when_exe/region/tibetan.rb +315 -316
  70. data/lib/when_exe/region/tranquility.rb +207 -208
  71. data/lib/when_exe/region/vanishing_leprechaun.rb +3 -1
  72. data/lib/when_exe/region/vietnamese.rb +449 -440
  73. data/lib/when_exe/region/weekdate.rb +80 -80
  74. data/lib/when_exe/region/world.rb +170 -171
  75. data/lib/when_exe/region/world_season.rb +89 -89
  76. data/lib/when_exe/region/yerm.rb +3 -3
  77. data/lib/when_exe/region/zoroastrian.rb +205 -205
  78. data/lib/when_exe/timestandard.rb +708 -707
  79. data/lib/when_exe/tmduration.rb +338 -338
  80. data/lib/when_exe/tmobjects.rb +1356 -1356
  81. data/lib/when_exe/tmposition.rb +66 -31
  82. data/lib/when_exe/version.rb +16 -2
  83. data/test/examples/Residue.m17n +83 -83
  84. data/test/examples/Terms.m17n +2 -2
  85. data/test/test.rb +2 -2
  86. data/test/test/google_api.rb +65 -0
  87. data/test/test/linkeddata.rb +1 -1
  88. data/test/test/{googlecalendar.rb → obsolete/googlecalendar.rb} +194 -194
  89. data/test/test/region/indian.rb +90 -85
  90. data/test/test/region/m17n.rb +7 -7
  91. data/test/test/region/mayan.rb +195 -195
  92. data/test/test/region/residue.rb +153 -153
  93. data/test/test/tmposition.rb +11 -1
  94. data/when_exe.gemspec +2 -2
  95. metadata +95 -8
  96. data/test/test.rb.config +0 -1
@@ -1,58 +1,60 @@
1
- # -*- coding: utf-8 -*-
2
- =begin
3
- Copyright (C) 2014 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
- =begin
9
-
10
- References
11
-
12
- (1) http://calendars.wikia.com/wiki/Goddess_Lunar_Calendar
13
- (2) http://www.fractal-timewave.com/mmgc/mmgc.htm
14
-
15
- =end
16
-
17
- module When
18
-
19
- class BasicTypes::M17n
20
-
21
- Goddess = [self, [
22
- "locale:[=en:, ja]",
23
- "names:[Goddess=]",
24
- "[Goddess(MMG)=http://calendars.wikia.com/wiki/Goddess_Lunar_Calendar, ゴッデス暦, *alias:Goddess]",
25
-
26
- [self,
27
- "names:[Month]",
28
- "[Athena]", "[Brigid]", "[Cerridwen]", "[Diana ]",
29
- "[Epona ]", "[Freya ]", "[Gaea ]", "[Hathor]",
30
- "[Inanna]", "[Juno ]", "[Kore ]", "[Lilith]",
31
- "[Maria ]"
32
- ]
33
- ]]
34
- end
35
-
36
- module CalendarTypes
37
-
38
- #
39
- # Goddess Calendar
40
- #
41
- Goddess = [CyclicTableBased, {
42
- 'label' => 'Goddess::Goddess',
43
- 'origin_of_LSC' => 2415611 - 180432, # 1901-08-14 Base Cycle = No.1
44
- 'indices' => [
45
- When.Index({:unit=>470}),
46
- When.Index('Goddess::Month'),
47
- When::Coordinates::DefaultDayIndex,
48
- ],
49
- 'rule_table' => {
50
- 'T' => {'Rule' =>(['L'] * 9 + ['S']) * 23 +
51
- (['L'] * 4 + ['S']) * 2 +
52
- (['L'] * 9 + ['S']) * 23},
53
- 'L' => {'Length'=>[30, 29] * 6 + [30]},
54
- 'S' => {'Length'=>[30, 29] * 6 + [29]}
55
- }
56
- }]
57
- end
58
- end
1
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ Copyright (C) 2014-2015 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
+ =begin
9
+
10
+ References
11
+
12
+ (1) http://calendars.wikia.com/wiki/Goddess_Lunar_Calendar
13
+ (2) http://www.fractal-timewave.com/mmgc/mmgc.htm
14
+
15
+ =end
16
+
17
+ module When
18
+
19
+ class BasicTypes::M17n
20
+
21
+ Goddess = [self, [
22
+ "locale:[=en:, ja, zh]",
23
+ "names:[ Peter Meyer's Goddes Lunar Calendar=, Peter Meyer のゴッデス暦=, *alias:Goddess=]",
24
+ "[Goddess(MMG)=http://calendars.wikia.com/wiki/Goddess_Lunar_Calendar, ゴッデス暦(MMG), 女神曆(MMG), *alias:Goddess]",
25
+
26
+ [self,
27
+ "names:[month name=en:Month, 月の名前=ja:%%<月_(暦)>, 該月的名稱=, *alias:Month=]",
28
+ "[Athena]", "[Brigid]", "[Cerridwen]", "[Diana ]",
29
+ "[Epona ]", "[Freya ]", "[Gaea ]", "[Hathor]",
30
+ "[Inanna]", "[Juno ]", "[Kore ]", "[Lilith]",
31
+ "[Maria ]"
32
+ ]
33
+ ]]
34
+ end
35
+
36
+ module CalendarTypes
37
+
38
+ #
39
+ # Goddess Calendar
40
+ #
41
+ Goddess = [CyclicTableBased, {
42
+ 'label' => 'Goddess::Goddess',
43
+ 'origin_of_LSC' => 2415611 - 180432, # 1901-08-14 Base Cycle = No.1
44
+ 'note' => [['_m:Calendar::Month'],
45
+ ['_co:Common::Week', '_n:Ephemeris/Notes::day::Moon_Age']],
46
+ 'indices' => [
47
+ When.Index({:unit=>470}),
48
+ When.Index('Goddess::Month'),
49
+ When::Coordinates::DefaultDayIndex,
50
+ ],
51
+ 'rule_table' => {
52
+ 'T' => {'Rule' =>(['L'] * 9 + ['S']) * 23 +
53
+ (['L'] * 4 + ['S']) * 2 +
54
+ (['L'] * 9 + ['S']) * 23},
55
+ 'L' => {'Length'=>[30, 29] * 6 + [30]},
56
+ 'S' => {'Length'=>[30, 29] * 6 + [29]}
57
+ }
58
+ }]
59
+ end
60
+ end
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  =begin
3
- Copyright (C) 2014 Takashi SUGA
3
+ Copyright (C) 2014-2015 Takashi SUGA
4
4
 
5
5
  You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
6
6
  =end
@@ -15,7 +15,7 @@ module When
15
15
  "[HankeHenry=en:Hanke-Henry_Permanent_Calendar, ハンキ=ヘンリー暦=ja:%%<ハンキ=ヘンリー・パーマネント・カレンダー>]",
16
16
 
17
17
  [self,
18
- "names:[Month, 月=ja:%%<月_(暦)>]",
18
+ "names:[month name=en:Month, 月の名前=ja:%%<月_(暦)>, zh:該月的名稱=, *alias:Month=]",
19
19
  "[January, 1月, /date/month_names/1] ",
20
20
  "[February, 2月, /date/month_names/2] ",
21
21
  "[March, 3月, /date/month_names/3] ",
@@ -1,1222 +1,1225 @@
1
- # -*- coding: utf-8 -*-
2
- =begin
3
- Copyright (C) 2011-2014 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
- require 'when_exe/locales/iast'
9
-
10
- module When
11
- class BasicTypes::M17n
12
-
13
- Indian = [self, [
14
- "locale:[=en:, ja=ja:, hi=hi:, alias]",
15
- "names:[Indian=]",
16
- "[IndianNationalSolar=en:Indian_national_calendar, インド国定暦, era:SE=]",
17
- "[Nanakshahi=en:Nanakshahi_calendar, ナーナク暦=]",
18
- "[RevisedBengali=en:Bengali_calendar, 改訂ベンガル暦=]",
19
- "[HinduSolar=en:Hindu_calendar, インド太陽暦=ja:%%<ヒンドゥー暦>]",
20
- "[HinduLuniSolar=en:Hindu_calendar, インド太陰太陽暦=ja:%%<ヒンドゥー暦>]",
21
-
22
- [self,
23
- "names:[IntercalaryMonth=en:Intercalation, 閏月]",
24
- "[%s Śuklapakṣa=, %s 白分=, _IAST_=]",
25
- "[%s Kṛṣṇapakṣa=, %s 黒分=, _IAST_=]",
26
- "[adhika %s Śuklapakṣa=, 閏%s 白分=, _IAST_=]",
27
- "[adhika %s Kṛṣṇapakṣa=, 閏%s 黒分=, _IAST_=]"
28
- ],
29
-
30
- [self,
31
- "names:[IntercalaryDay=en:Intercalation, 閏日=ja:%%<閏>]",
32
- "[%s and next day=, %sと翌日=]",
33
- "[Intercalary %s=, 重%s=]"
34
- ],
35
-
36
- [self,
37
- "names:[LunarMonth=, 太陰月=ja:%%<月_(暦)>]",
38
- "[Mārgaśīra=en:Margashirsha, マールガシールシャ=, _IAST_=]",
39
- "[Pauṣa=en:Pausha, パウシャ=, _IAST_=]",
40
- "[Māgha=en:Maagha, マーガ=, _IAST_=]",
41
- "[Phālguna=en:Phalguna, パールグナ=, _IAST_=]",
42
- "[Caitra=en:Chaitra, チャイトラ=, _IAST_=]",
43
- "[Vaiśākha=en:Vaisakha, ヴァイシャーカ=, _IAST_=]",
44
- "[Jyaiṣṭha=en:Jyeshta, ジャイシュタ=, _IAST_=]",
45
- "[Āṣāḍha=en:Aashaadha, アーシャーダ=, _IAST_=]",
46
- "[Śrāvaṇa=en:Shraavana, シュラーヴァナ=, _IAST_=]",
47
- "[Bhādrapada=en:Bhadrapada, バードラパダ=, _IAST_=]",
48
- "[Āśvina=en:Ashwin, アーシュヴィナ=, _IAST_=]",
49
- "[Kārttika=en:Kartika_(month), カールッティカ=, _IAST_=]"
50
- ],
51
-
52
- [self,
53
- "names:[SolarMonth=, 太陽月=ja:%%<月_(暦)>]",
54
- "[Maysha=, 白羊宮, _IAST_=]",
55
- "[Vrushabha=, 金牛宮, _IAST_=]",
56
- "[Mithuna=, 双児宮, _IAST_=]",
57
- "[Karka=, 巨蟹宮, _IAST_=]",
58
- "[Simha=, 獅子宮, _IAST_=]",
59
- "[Kanya=, 処女宮, _IAST_=]",
60
- "[Tula=, 天秤宮, _IAST_=]",
61
- "[Vrushchika=, 天蝎宮, _IAST_=]",
62
- "[Dhanu=, 人馬宮, _IAST_=]",
63
- "[Makar=, 磨羯宮, _IAST_=]",
64
- "[Kumbha=, 宝瓶宮, _IAST_=]",
65
- "[Meena=, 双魚宮, _IAST_=]"
66
- ],
67
-
68
- [self,
69
- "names:[NanakshahiMonth=, 太陽月=ja:%%<月_(暦)>]",
70
- "[Maghar=en:Maghar_(month) ]",
71
- "[Poh ]",
72
- "[Magh=en:Magh_(Sikh_calendar)]",
73
- "[Phagun ]",
74
- "[Chet=en:Chet_(month) ]",
75
- "[Vaisakh ]",
76
- "[Jeth ]",
77
- "[Harh ]",
78
- "[Sawan ]",
79
- "[Bhadon ]",
80
- "[Assu ]",
81
- "[Katak ]"
82
- ],
83
-
84
- [self,
85
- "names:[BengaliMonth=, 太陽月=ja:%%<月_(暦)>]",
86
- "[Ogrôhayôn=]",
87
- "[Poush= ]",
88
- "[Magh= ]",
89
- "[Falgun= ]",
90
- "[Chôitrô= ]",
91
- "[Bôishakh= ]",
92
- "[Jyôishţhô=]",
93
- "[Ashaŗh= ]",
94
- "[Shrabôn= ]",
95
- "[Bhadrô= ]",
96
- "[Ashbin= ]",
97
- "[Kartik= ]"
98
- ]
99
- ]]
100
- end
101
-
102
- module Coordinates
103
-
104
- # Location of cities in India
105
- Indian = [When::BasicTypes::M17n, [
106
- "locale:[=en:, ja=ja:, alias]",
107
- "names:[Indian]",
108
- [Spatial, "long:+82.5", "lat:N23.11", "label:[CentralIndia=, インド中部=]" ],
109
- [Spatial, "long:+82.5", "lat:+29.0", "label:[NorthIndia=, インド北部]" ],
110
- [Spatial, "long:+78.0", "lat:+27.2", "label:[Agra, アーグラ]" ],
111
- [Spatial, "long:+72.6", "lat:+23.0", "label:[Ahmedabad, アフマダーバード]" ],
112
- [Spatial, "long:+74.6", "lat:+26.5", "label:[Ajmer, アジメール]" ],
113
- [Spatial, "long:+78.1", "lat:+27.9", "label:[Aligarh, アリーガル]" ],
114
- [Spatial, "long:+74.9", "lat:+31.6", "label:[Amritsar, アムリトサル]" ],
115
- [Spatial, "long:+77.6", "lat:+13.0", "label:[Bangalore, バンガロール]" ],
116
- [Spatial, "long:+85.8", "lat:+20.2", "label:[Bhuvaneswar, ブヴァネーシュヴァル]"],
117
- [Spatial, "long:+80.3", "lat:+13.1", "label:[Chennai, チェンナイ, Madras]" ],
118
- [Spatial, "long:+79.9", "lat: +6.9", "label:[Colombo, コロンボ]" ],
119
- [Spatial, "long:+90.4", "lat:+23.7", "label:[Dacca, ダッカ]" ],
120
- [Spatial, "long:+77.2", "lat:+28.6", "label:[Delhi, デリー]" ],
121
- [Spatial, "long:+78.5", "lat:+17.4", "label:[Hyderabad, ハイデラバード]" ],
122
- [Spatial, "long:+75.8", "lat:+26.9", "label:[Jaipur, ジャイプル]" ],
123
- [Spatial, "long:+85.2", "lat:+27.7", "label:[Kathmandu, カトマンズ]" ],
124
- [Spatial, "long:+76.2", "lat:+10.0", "label:[Kochi, コーチ, Cochin]" ],
125
- [Spatial, "long:+88.4", "lat:+22.6", "label:[Kolkata, コルカタ, Calcutta]" ],
126
- [Spatial, "long:+74.3", "lat:+31.6", "label:[Lahor, ラホール]" ],
127
- [Spatial, "long:+77.7", "lat:+27.5", "label:[Mathura, マトゥラー]" ],
128
- [Spatial, "long:+72.8", "lat:+19.0", "label:[Mumbai, ムンバイ, Bombay]" ],
129
- [Spatial, "long:+76.6", "lat:+12.3", "label:[Mysore, マイソール]" ],
130
- [Spatial, "long:+85.1", "lat:+25.6", "label:[Patna, パトナ]" ],
131
- [Spatial, "long:+73.9", "lat:+18.5", "label:[Pune, プネー]" ],
132
- [Spatial, "long:+74.8", "lat:+34.1", "label:[Srinagar, シュリーナガル]" ],
133
- [Spatial, "long:+77.0", "lat: +8.5", "label:[Thiruvananthapuram, ティルヴァナンタプラム, Trivandrum]"],
134
- [Spatial, "long:+83.0", "lat:+25.3", "label:[Varanasi, ワーラーナシー]" ],
135
- [Spatial, "long:+75.8", "lat:+23.2", "label:[Ujjain, ウッジャイン=]" ]
136
- ]]
137
- end
138
-
139
- module Ephemeris
140
-
141
- #
142
- # Hindu Luni-Solar Calendar Formula
143
- #
144
- class Hindu < Formula
145
-
146
- # Basic Astronomical Constants for Surya-Siddhanta
147
- Tz = 0.5+75.8/360 # time difference between JulianDayNumber and Ujjain
148
- E = 588_466 - Tz # Yuga Epoch -3101-02-18T00:00:00
149
- P = 180 # Precession cycles in yuga
150
- Ep = 1_903_318 - Tz # Precession Epoch 499-01-01
151
- Ob = 24.0 / 360.0 # Obliquity of the ecliptic
152
-
153
- Grahas = {
154
- 'SS' => { # Previous / Newest
155
- :Star => 1_582_237_800.0, # 1_582_237_500 / 1_582_237_800
156
- :Sun => 4_320_000.0,
157
- :Moon => 57_753_336.0,
158
- :Mercury => 17_937_000.0,
159
- :Venus => 7_022_388.0,
160
- :Mars => 2_296_824.0,
161
- :Jupiter => 364_220.0,
162
- :Saturn => 146_564.0,
163
- :Candrocca => 488_219.0, # 488_203 / 488_219
164
- :Rahu => -232_226.0
165
- },
166
- 'SB' => {
167
- :Star => 1_582_237_828.0,
168
- :Sun => 4_320_000.0,
169
- :Moon => 57_753_336.0,
170
- :Mercury => 17_937_060.0,
171
- :Venus => 7_022_376.0,
172
- :Mars => 2_296_832.0,
173
- :Jupiter => 364_220.0,
174
- :Saturn => 146_568.0,
175
- :Candrocca => 488_203.0, # 488_199 / 488_203
176
- :Rahu => -232_238.0
177
- }
178
- }
179
-
180
- #
181
- # 日月五惑星とラーフおよびケートゥ
182
- #
183
- # @abstract
184
- class Graha
185
- include When::Ephemeris
186
- end
187
-
188
- #
189
- # 現代的“惑星”
190
- #
191
- class ModernGraha < Graha
192
-
193
- # 真黄経
194
- #
195
- # @param [Numeric] t ユリウス日
196
- #
197
- # @return [Numeric]
198
- #
199
- def true_longitude(t)
200
- @target.coords(t, @base).phi
201
- end
202
-
203
- # オブジェクトの生成
204
- #
205
- # @param [When::Ephemeris::Datum] target 天体
206
- # @param [When::Coordinates::Spatial] base 観測地
207
- #
208
- def initialize(target, base)
209
- @target = target
210
- @base = base
211
- end
212
- end
213
-
214
- #
215
- # 古典的“惑星”
216
- #
217
- # @abstract
218
- class ClassicGraha < Graha
219
-
220
- # 平均黄経
221
- #
222
- # @param [Numeric] t ユリウス日
223
- #
224
- # @return [Numeric]
225
- #
226
- def mean_longitude(t)
227
- _mean_rotation(t - E)
228
- end
229
-
230
- # 真黄経
231
- #
232
- # @param [Numeric] t ユリウス日
233
- #
234
- # @return [Numeric]
235
- #
236
- def true_longitude(t)
237
- _true_rotation(t - E)
238
- end
239
-
240
- # 平均黄経
241
- #
242
- # @param [Numeric] ahar カリユガ暦元からの経過日数
243
- #
244
- # @return [Numeric]
245
- #
246
- def _mean_rotation(ahar)
247
- @rotation * ahar / @formula.civil_days
248
- end
249
-
250
- # オブジェクトの生成
251
- #
252
- # @param [When::Ephemeris::Formula] formula 親オブジェクト
253
- # @param [Numeric] rotation ユガあたりの回転数
254
- #
255
- def initialize(formula, rotation)
256
- @formula = formula
257
- @rotation = rotation
258
- end
259
- end
260
-
261
- # 架空の“惑星” - ラーフ / 月軌道の遠地点としてのケートゥ
262
- class VirtualGraha < ClassicGraha
263
-
264
- # 平均黄経
265
- #
266
- # @param [Numeric] ahar カリユガ暦元からの経過日数
267
- #
268
- # @return [Numeric]
269
- #
270
- def _mean_rotation(ahar)
271
- super + @rotation0
272
- end
273
- alias :_true_rotation :_mean_rotation
274
-
275
- # オブジェクトの生成
276
- #
277
- # @param [When::Ephemeris::Formula] formula 親オブジェクト
278
- # @param [Numeric] rotation ユガあたりの回転数
279
- # @param [Numeric] rotation0 カリユガ暦元での回転量
280
- #
281
- def initialize(formula, rotation, rotation0)
282
- @rotation0 = rotation0 / 360.0
283
- super(formula, rotation)
284
- end
285
- end
286
-
287
- # 実在の“惑星”
288
- # @abstract
289
- class RealGraha < ClassicGraha
290
-
291
- # マンダ補正
292
- #
293
- # @param [Numeric] rot 平均近点角など / CIRCLE
294
- #
295
- # @return [Numeric]
296
- #
297
- def _manda_equation(rot)
298
- asin(@circumm * sinc(rot)) / CIRCLE
299
- end
300
-
301
- # オブジェクトの生成
302
- #
303
- # @param [When::Ephemeris::Formula] formula 親オブジェクト
304
- # @param [Numeric] rotation ユガあたりの回転数
305
- # @param [Numeric] circumm マンダ円の半径
306
- # @param [Numeric] apogee 近点黄経 / CIRCLE
307
- #
308
- def initialize(formula, rotation, circumm, apogee)
309
- @circumm = circumm / 360.0
310
- @apogee = apogee / 360.0
311
- super(formula, rotation)
312
- end
313
- end
314
-
315
- # 太陽と月 - 逆行しない“惑星”
316
- # @abstract
317
- class ConcentricGraha < RealGraha
318
-
319
- # 平均黄経
320
- #
321
- # @param [Numeric] ahar カリユガ暦元からの経過日数
322
- #
323
- # @return [Numeric]
324
- #
325
- def _mean_rotation(ahar)
326
- super + @epoch
327
- end
328
-
329
- # オブジェクトの生成
330
- #
331
- # @param [When::Ephemeris::Formula] formula 親オブジェクト
332
- # @param [Numeric] rotation ユガあたりの回転数
333
- # @param [Numeric] circumm マンダ円の半径
334
- # @param [Numeric] apogee 近点黄経 / CIRCLE
335
- # @param [Numeric] epoch カリユガ暦元での黄経 / CIRCLE
336
- #
337
- def initialize(formula, rotation, circumm, apogee, epoch)
338
- @epoch = epoch
339
- super(formula, rotation, circumm, apogee)
340
- end
341
- end
342
-
343
- # 太陽
344
- class Sun < ConcentricGraha
345
-
346
- # 真黄経
347
- #
348
- # @param [Numeric] ahar カリユガ暦元からの経過日数
349
- #
350
- # @return [Numeric]
351
- #
352
- def _true_rotation(ahar)
353
- mean = _mean_rotation(ahar)
354
- mean - _manda_equation(mean - @apogee)
355
- end
356
- end
357
-
358
- # 月
359
- class Moon < ConcentricGraha
360
-
361
- # 真黄経
362
- #
363
- # @param [Numeric] ahar カリユガ暦元からの経過日数
364
- #
365
- # @return [Numeric]
366
- #
367
- def _true_rotation(ahar)
368
- mean = _mean_rotation(ahar)
369
- mean - _manda_equation(mean - @formula.graha[:Candrocca]._mean_rotation(ahar))
370
- end
371
- end
372
-
373
- # 惑星 - 逆行するもの
374
- # @abstract
375
- class Planet < RealGraha
376
-
377
- # シグラ補正
378
- #
379
- # @param [Numeric] anomaly 平均近点角 / CIRCLE
380
- #
381
- # @return [Numeric]
382
- #
383
- def _sighra_equation(anomaly)
384
- atan2(@circums * sinc(anomaly), @circums * cosc(anomaly) + 1) / CIRCLE
385
- end
386
-
387
- # 平均シグラ
388
- #
389
- # @param [Numeric] ahar カリユガ暦元からの経過日数
390
- #
391
- # @return [Numeric]
392
- #
393
- def _mean_sighra(ahar)
394
- @sighra * ahar / @formula.civil_days
395
- end
396
-
397
- # 真黄経
398
- #
399
- # @param [Numeric] ahar カリユガ暦元からの経過日数
400
- # @param [Numeric] rotation 基準回転量 / CIRCLE
401
- #
402
- # @return [Numeric]
403
- #
404
- def _true_rotation(ahar, rotation)
405
- # first sighra correction
406
- delta = _sighra_equation(_mean_sighra(ahar) - rotation) / 2
407
-
408
- # first manda correction
409
- mean = _mean_rotation(ahar) + delta
410
- delta = _manda_equation(mean - @apogee) / 2
411
-
412
- # second manda correction
413
- mean -= delta
414
- delta = _manda_equation(mean - @apogee)
415
-
416
- # second sighra correction
417
- mean = _mean_rotation(ahar) - delta
418
- delta = _sighra_equation(_mean_sighra(ahar) - mean)
419
-
420
- # true rotation
421
- mean + delta
422
- end
423
-
424
- # オブジェクトの生成
425
- #
426
- # @param [When::Ephemeris::Formula] formula 親オブジェクト
427
- # @param [Numeric] rotation ユガあたりの回転数
428
- # @param [Numeric] circumm マンダ円の半径
429
- # @param [Numeric] apogee 近点黄経 / CIRCLE
430
- # @param [Numeric] sighra シグラ対象のカリユガあたりの回転数
431
- # @param [Numeric] circums シグラ円の半径
432
- #
433
- def initialize(formula, rotation, circumm, apogee, sighra, circums)
434
- @sighra = sighra
435
- @circums = circums / 360.0
436
- super(formula, rotation, circumm, apogee)
437
- end
438
- end
439
-
440
- # 内惑星 - 水金
441
- class InferiorPlanet < Planet
442
-
443
- # 真黄経
444
- #
445
- # @param [Numeric] t ユリウス日
446
- #
447
- # @return [Numeric]
448
- #
449
- def true_longitude(t)
450
- ahar = t - E
451
- _true_rotation(ahar, @formula.graha[:Sun]._mean_rotation(ahar))
452
- end
453
- end
454
-
455
- # 外惑星 - 火木土
456
- class SuperiorPlanet < Planet
457
-
458
- # 真黄経
459
- #
460
- # @param [Numeric] t ユリウス日
461
- #
462
- # @return [Numeric]
463
- #
464
- def true_longitude(t)
465
- ahar = t - E
466
- _true_rotation(ahar, _mean_rotation(ahar))
467
- end
468
- end
469
-
470
- #
471
- # ユガの太陽日数
472
- #
473
- # @return [Numeric]
474
- #
475
- attr_reader :civil_days
476
-
477
- # 日の出の日時
478
- #
479
- # @param [Numeric] sdn ユリウス日
480
- # @param [When::TM::TemporalPosition] sdn
481
- # @param [nil] height 太陽高度(本クラスでは使用しない)
482
- #
483
- # @return [Integer, When::TM::DateAndTime] 日の出の日時
484
- #
485
- def sunrise(sdn, height=nil)
486
- t = sdn.to_i - @long / 360.0 - 0.25
487
- p = _mean_sun(t) + P * (t - Ep) / @civil_days
488
- _to_seed_type(t - asin(tand(@lat)*tan(asin(sinc(p)*sinc(Ob)))) / CIRCLE, sdn)
489
- end
490
-
491
- # 日の入りの日時
492
- #
493
- # @param [Numeric] sdn ユリウス日
494
- # @param [When::TM::TemporalPosition] sdn
495
- # @param [nil] height 太陽高度(本クラスでは使用しない)
496
- #
497
- # @return [Integer, When::TM::DateAndTime] 日の入りの日時
498
- #
499
- def sunset(sdn, height=nil)
500
- t = sdn.to_i - @long / 360.0 + 0.25
501
- p = _mean_sun(t) + P * (t - Ep) / @civil_days
502
- _to_seed_type(t + asin(tand(@lat)*tan(asin(sinc(p)*sinc(Ob)))) / CIRCLE, sdn)
503
- end
504
-
505
- # 太陽の南中の日時
506
- #
507
- # @param [Numeric] sdn ユリウス日
508
- # @param [When::TM::TemporalPosition] sdn
509
- #
510
- # @return [Integer, When::TM::DateAndTime] 太陽の南中の日時
511
- #
512
- def sun_noon(sdn)
513
- _to_seed_type(sdn.to_i - @long / 360.0, sdn)
514
- end
515
-
516
- private
517
-
518
- # オブジェクトの正規化
519
- def _normalize(args=[], options={})
520
- @time_standard ||= 'universal'
521
- @bija ||= 'SB'
522
- super
523
- end
524
-
525
- # 9惑星オブジェクトの生成
526
- def _normalize_grahas
527
- grahas = Grahas[@bija]
528
-
529
- # ユガあたりの暦定数
530
- @sidereal_days = grahas[:Star] # 恒星日
531
- @solar_years = grahas[:Sun] # 太陽年
532
- @civil_days = @sidereal_days - @solar_years # 太陽日
533
- @sidereal_months = grahas[:Moon] # 恒星月
534
- @synodic_months = @sidereal_months - @solar_years # 朔望月
535
- @adhimasas = @synodic_months - 12 * @solar_years # 閏月
536
- @tithis = 30 * @sidereal_months # 太陰日
537
- @ksayadinas = @tithis - @civil_days # 欠日
538
-
539
- # 9惑星
540
- @graha = {}
541
- @graha.update({
542
- :Sun => Sun.new( self, @solar_years, 13+50/60.0, 77+17/60.0, -3101)
543
- }) if @formula =~ /[SL]/i
544
- @graha.update({
545
- :Moon => Moon.new( self, @sidereal_months, 31+50/60.0, 0, -28086),
546
- :Candrocca => VirtualGraha.new( self, grahas[:Candrocca], 90.0)
547
- }) if @formula =~ /[ML]/i
548
- @graha.update({
549
- :Mercury => InferiorPlanet.new(self, @solar_years, 29.0, 220+27/60.0, grahas[:Mercury], 131.5),
550
- :Venus => InferiorPlanet.new(self, @solar_years, 11.5, 79+50/60.0, grahas[:Venus], 261.0),
551
- :Mars => SuperiorPlanet.new(self, grahas[:Mars], 73.5, 130+02/60.0, @solar_years, 233.5),
552
- :Jupiter => SuperiorPlanet.new(self, grahas[:Jupiter], 32.5, 171+18/60.0, @solar_years, 71.0),
553
- :Saturn => SuperiorPlanet.new(self, grahas[:Saturn], 48.5, 236+37/60.0, @solar_years, 39.5),
554
- :Rahu => VirtualGraha.new( self, grahas[:Rahu], 180.0)
555
- }) if @formula == '2L'
556
- end
557
- end
558
- end
559
-
560
- module CalendarTypes
561
-
562
- #
563
- # Indian national solar calendar
564
- #
565
- IndianNationalSolar = [SolarYearTableBasedWithSunrise, {
566
- 'label' => 'Indian::IndianNationalSolar',
567
- 'origin_of_MSC' => -78,
568
- 'diff_to_CE' => 0,
569
- 'engine_month' => 2, # February
570
- 'engine_day' => 28+22, # 22nd of next month
571
- 'indices' => [
572
- When.Index('Indian::LunarMonth', {:unit =>12, :shift=>4}),
573
- When::Coordinates::DefaultDayIndex
574
- ],
575
- 'rule_table' => {
576
- 365 => {'Length'=>[30] + [31]*5 + [30]*6},
577
- 366 => {'Length'=> [31]*6 + [30]*6}
578
- }
579
- }]
580
-
581
- #
582
- # Nanakshahi Calendar
583
- #
584
- Nanakshahi = [SolarYearTableBased, {
585
- 'label' => 'Indian::Nanakshahi',
586
- 'origin_of_MSC' => -1468,
587
- 'diff_to_CE' => 0,
588
- 'engine_month' => 3,
589
- 'engine_day' => 14,
590
- 'indices' => [
591
- When.Index('Indian::NanakshahiMonth', {:unit=>12, :shift=>4}),
592
- When::Coordinates::DefaultDayIndex
593
- ],
594
- 'rule_table' => {
595
- 365 => {'Length'=> [31]*5 + [30]*7},
596
- 366 => {'Length'=> [31]*5 + [30]*6 + [31]}
597
- }
598
- }]
599
-
600
- #
601
- # Revised Bengali Calendar
602
- #
603
- RevisedBengali = [SolarYearTableBased, {
604
- 'label' => 'Indian::RevisedBengali',
605
- 'origin_of_MSC' => -593,
606
- 'diff_to_CE' => 0,
607
- 'engine_month' => 4,
608
- 'engine_day' => 14,
609
- 'indices' => [
610
- When.Index('Indian::BengaliMonth', {:unit=>12, :shift=>5}),
611
- When::Coordinates::DefaultDayIndex
612
- ],
613
- 'rule_table' => {
614
- 365 => {'Length'=> [31]*5 + [30]*7},
615
- 366 => {'Length'=> [31]*5 + [30]*5 + [31, 30]}
616
- }
617
- }]
618
-
619
- #
620
- # Hindu Solar Calendar
621
- #
622
- class HinduSolar < EphemerisBasedSolar
623
-
624
- # protected
625
-
626
- # 月初の通日
627
- #
628
- # @param [Integer] m 通月
629
- #
630
- # @return [Integer] 月初の通日
631
- #
632
- def _new_month_(m)
633
- new_month_time = @formula[0].cn_to_time(m + @cycle_offset)
634
- new_month_date = (new_month_time + 0.5 + @formula[0].long/360.0).floor
635
- sunrise_time = @formula[0].sunrise(new_month_date)
636
- (sunrise_time <= new_month_time) ? new_month_date : new_month_date-1
637
- end
638
-
639
- private
640
-
641
- # オブジェクトの正規化
642
- #
643
- # @formula[0] = 位相の計算に用いる太陽の Formula
644
- # @cycle_offset = 位相のオフセット
645
- # @start_month = 暦年の最初の月
646
- #
647
- def _normalize(args=[], options={})
648
- @label ||= 'Indian::HinduSolar'
649
- @type ||= 'SBS'
650
- raise ArgumentError, "Irregal formula: #{@formula}" unless @type.upcase =~ /\A(M|SS|SB)(V|S|B|H|VZ|SZ|BZ|HZ)\z/
651
-
652
- @location ||= HinduLuniSolar::Location_E[$2] || HinduLuniSolar::Location_F[$1]
653
- @cycle_offset ||= HinduLuniSolar::CycleOffset[$1]
654
- @origin_of_MSC ||= -HinduLuniSolar::YearEpoch[$2]
655
- @diff_to_CE ||= 0
656
- @start_month ||= 1 # Maysha
657
- @start_month = @start_month.to_i
658
- @cycle_offset = @cycle_offset.to_f + (@start_month - 1)
659
- formula = @formula || HinduLuniSolar::Formula[$1]
660
- if formula.kind_of?(String)
661
- formula += (formula =~ /\?/) ? '&' : '?'
662
- @formula = [When.Resource("_ep:#{formula}location=(#{@location})&formula=12S")]
663
- end
664
- @indices ||= [
665
- When.Index('Indian::SolarMonth', {:shift=>@start_month-1}),
666
- When::Coordinates::DefaultDayIndex
667
- ]
668
-
669
- super
670
- end
671
- end
672
-
673
- #
674
- # Hindu Luni-Solar Calendar
675
- #
676
- class HinduLuniSolar < EphemerisBasedLuniSolar
677
-
678
- # Calendar Type
679
- Formula = {'M'=>'Formula', 'SS'=>'Hindu?bija=SS', 'SB'=>'Hindu?bija=SB'}
680
- Location_F = {'M'=>'_co:Indian::CentralIndia', 'SS'=>'_co:Indian::Ujjain', 'SB'=>'_co:Indian::Ujjain'}
681
- Location_E = {'B'=>'_co:Indian::Dacca', 'BZ'=>'_co:Indian::Dacca', 'H'=>'_co:Iranian::Tehran', 'HZ'=>'_co:Iranian::Tehran'}
682
- CycleOffset = {'M'=>+23.25/30, 'SS'=>0.0, 'SB'=>0.0}
683
- HinduStyle = {'A'=>0, 'P'=>1, 'PX'=>2}
684
- YearEpoch = {'V'=>-58,'VZ'=>-57,'S'=>78, 'SZ'=>79, 'B'=> 593, 'BZ'=>594, 'H'=> 621, 'HZ'=> 622}
685
-
686
- # White / black month and leap month identification table
687
-
688
- #[w]/b [n]/l #0 #1 #2
689
- LEAP_MAP = {[nil, false] => [ 0, 0, 0 ],
690
- [nil, true ] => [-1.5, -1.5, -1.5],
691
- [true, false] => [+0.5, -0.5, -2.5],
692
- [true, true ] => [-1, -2, -1 ]}
693
-
694
- # protected
695
-
696
- # 月初の通日
697
- #
698
- # @param [Integer] m 通月
699
- #
700
- # @return [Integer] 月初の通日
701
- #
702
- def _new_month_(m)
703
- new_moon_time = @formula[-1].cn_to_time(m)
704
- new_moon_date = (new_moon_time + 0.5 + @formula[-1].long/360.0).floor
705
- sunrise_time = @formula[-1].sunrise(new_moon_date)
706
- (sunrise_time >= new_moon_time) ? new_moon_date : new_moon_date+1
707
- end
708
-
709
- # 年初の通月
710
- #
711
- # @param [Integer] y 年
712
- #
713
- # @return [Integer] 年初の通月
714
- #
715
- def _new_year_month_(y)
716
- (Residue.mod(y-1) {|t| _tithi_to_coordinates(t*15)[0]})[0] + 1
717
- end
718
-
719
- # 朔望日 -> 年・月・日
720
- #
721
- # tithi : 朔望日(月の位相 / (CIRCLE/30))
722
- #
723
- # @return [Array<Numeric>] ( y, m, d )
724
- # [ y - (Integer) ]
725
- # [ m - 月(When::Coordinates::Pair) ]
726
- # [ d - 日(Integer) ]
727
- #
728
- def _tithi_to_coordinates(tithi)
729
- m, d = tithi.divmod(30)
730
- s = [0,1,2].map {|i| (@formula[1].time_to_cn(30*(m+i)) - @cycle_offset).floor + 1 }
731
- f = s[0]==s[1]
732
- if (d >= 15.0)
733
- d -= 15
734
- b = true
735
- n = true unless @hindu_style==0
736
- f = s[1]==s[2] if @hindu_style==1
737
- end
738
- y, m = (n ? s[1] : s[0]).divmod(12)
739
- return [y, Pair._force_pair(m+1, LEAP_MAP[[b,f]][@hindu_style]), d.floor]
740
- end
741
-
742
- # 日時要素の翻訳表の取得
743
- #
744
- # @overload _ids_(date)
745
- # @param [Array<Numeric>] date ( 年 )
746
- # @return [Array<When::Coordinates::Pair>] 1年の月の配置の翻訳表
747
- #
748
- # @overload _ids_(date)
749
- # @param [Array<Numeric>] date ( 年 月 )
750
- # @return [Array<When::Coordinates::Pair>] 1月の日の配置の翻訳表
751
- # @note 月は 0 始まりの通番
752
- #
753
- def _ids_(date)
754
- y, m = date
755
- y = +y
756
- mm = _new_year_month(y)
757
- return (_table(_new_month_(mm+m.to_i)) {|i| _new_month(mm+m+i/15.0)}) if m
758
- table = (0...26).to_a.map {|i| _tithi_to_coordinates((mm+i)*15)[1]}
759
- table.pop while table[-1].trunk < 11
760
- return table
761
- end
762
-
763
- private
764
-
765
- # 日時要素の翻訳表の作成
766
- def _table(b0)
767
- table = [Pair._force_pair(0,0)]
768
- (1..16).each do |i|
769
- b1 = yield(i)
770
- case b1-b0
771
- when 0 ; table[-1] = Pair._force_pair(i-1, -2)
772
- when 1 ; table << Pair._force_pair(i, 0)
773
- when 2 ; table << Pair._force_pair(i, 0) << Pair._force_pair(i, 1)
774
- else ; raise ArgumentError, "Irregal date span: #{b1-b0}"
775
- end
776
- b0 = b1
777
- end
778
- table.pop while table[-1].trunk >= 16
779
- table.shift
780
- return table
781
- end
782
-
783
- # オブジェクトの正規化
784
- #
785
- # @formula = 位相の計算に用いる太陽・変換・月の Formula
786
- # @cycle_offset = 位相のオフセット
787
- # @hindu_style = 閏月の表現方法
788
- # @start_month = 暦年の最初の月
789
- #
790
- def _normalize(args=[], options={})
791
- @label ||= 'Indian::HinduLuniSolar'
792
- @type ||= 'SBSA'
793
- raise ArgumentError, "Irregal formula: #{@formula}" unless @type.upcase =~ /\A(M|SS|SB)(V|S|B|H|VZ|SZ|BZ|HZ)(A|P|PX)\z/
794
-
795
- @location ||= Location_E[$2] || Location_F[$1]
796
- @cycle_offset ||= CycleOffset[$1]
797
- @origin_of_MSC ||= -YearEpoch[$2]
798
- @hindu_style ||= HinduStyle[$3]
799
- @diff_to_CE ||= 0
800
- @start_month ||= 5 # Chaitra
801
- @start_month = @start_month.to_i
802
- @cycle_offset = @cycle_offset.to_f + (@start_month - 5)
803
- @hindu_style = @hindu_style.to_i
804
- @origin_of_MSC = @origin_of_MSC.to_i
805
- formula = @formula || Formula[$1]
806
- if formula.kind_of?(String)
807
- formula += (formula =~ /\?/) ? '&' : '?'
808
- @formula = When.Resource(["_ep:#{formula}formula=12S",
809
- "_ep:#{formula}formula=30L->12S",
810
- "_ep:#{formula}location=(#{@location})&formula=2L"])
811
- end
812
- intercalary_month = When.Resource('_m:Indian::IntercalaryMonth::*')
813
- intercalary_day = When.Resource('_m:Indian::IntercalaryDay::*')
814
- @indices ||= [
815
- When.Index('Indian::LunarMonth', {:branch=>{-2.5 => intercalary_month[1], # 黒分
816
- -2 => intercalary_month[3], # 閏黒分
817
- -1.5 => intercalary_month[2], # 閏白分
818
- -1 => intercalary_month[3], # 閏黒分
819
- -0.5 => intercalary_month[1], # 黒分
820
- 0 => intercalary_month[0], # 白分
821
- +0.5 => intercalary_month[1]}, # 黒分
822
- :shift=>@start_month-1}),
823
- When.Index({:branch=>{-2=>intercalary_day[0], +1=>intercalary_day[1]}})
824
- ]
825
-
826
- super
827
- end
828
- end
829
- end
830
-
831
- class CalendarNote
832
- #
833
- # ヒンドゥー系の暦注
834
- #
835
- class HinduNote < self
836
-
837
- Notes = [When::BasicTypes::M17n, [
838
- "locale:[=en:, ja=ja:, hi=hi:, alias]",
839
- "names:[Hindu]",
840
-
841
- # 年の暦注 ----------------------------
842
- [When::BasicTypes::M17n,
843
- "names:[year]",
844
- [When::BasicTypes::M17n,
845
- "names:[samvatsara, 木星年=]",
846
- "[Prabhava=, プラバヴァ=, _IAST_=]", # 1
847
- "[Vibhava=, ヴィバヴァ=, _IAST_=]", # 2
848
- "[Sukha=, スカ=, _IAST_=]", # 3
849
- "[Pramoda=, プラモーダ=, _IAST_=]", # 4
850
- "[Prajāpati=, プラジャーパティ=, _IAST_=]", # 5
851
- "[Aṅgiras=, アンギラス=, _IAST_=]", # 6
852
- "[Śrīmukha=, シュリームカ=, _IAST_=]", # 7
853
- "[Bhāva=, バーヴァ=, _IAST_=]", # 8
854
- "[Yuvan=, ユヴァン=, _IAST_=]", # 9
855
- "[Dhātṛ=, ダートリ=, _IAST_=]", # 10
856
- "[Īśvara=, イーシュヴァラ=, _IAST_=]", # 11
857
- "[Bahudhānya=, バフダーニャ=, _IAST_=]", # 12
858
- "[Pramāthin=, プラマーティン=, _IAST_=]", # 13
859
- "[Vikrama=, ヴィクラマ=, _IAST_=]", # 14
860
- "[Vṛṣa=, ヴリシャ=, _IAST_=]", # 15
861
- "[Chitrabhānu=, チトラバーヌ=, _IAST_=]", # 16
862
- "[Subhānu=, スバーヌ=, _IAST_=]", # 17
863
- "[Tāraṇa=, ターラナ=, _IAST_=]", # 18
864
- "[Pārthiva=, パールティヴァ=, _IAST_=]", # 19
865
- "[Vyaya=, ヴヤヤ=, _IAST_=]", # 20
866
- "[Sarvajit=, サルヴァジト=, _IAST_=]", # 21
867
- "[Sarvadhārin=, サルヴァダーリン=, _IAST_=]", # 22
868
- "[Virodhin=, ヴィローディン=, _IAST_=]", # 23
869
- "[Vikṛta=, ヴィクリタ=, _IAST_=]", # 24
870
- "[Khara=, カラ=, _IAST_=]", # 25
871
- "[Nandana=, ナンダナ=, _IAST_=]", # 26
872
- "[Vijaya=, ヴィジャヤ=, _IAST_=]", # 27
873
- "[Jaya=, ジャヤ=, _IAST_=]", # 28
874
- "[Manmatha=, マンマタ=, _IAST_=]", # 29
875
- "[Durmukha=, ドゥルムカ=, _IAST_=]", # 30
876
- "[Hemalamba=, ヘマラムバ=, _IAST_=]", # 31
877
- "[Vilambin=, ヴィラムビン=, _IAST_=]", # 32
878
- "[Vikārin=, ヴィカーリン=, _IAST_=]", # 33
879
- "[Śārvarin=, シャールヴァリン=, _IAST_=]", # 34
880
- "[Plava=, プラヴァ=, _IAST_=]", # 35
881
- "[Śubhakṛt=, シュバクリト=, _IAST_=]", # 36
882
- "[Śobhana=, ショバナ=, _IAST_=]", # 37
883
- "[Krodhin=, クロディン=, _IAST_=]", # 38
884
- "[Viśvāvasu=, ヴィシュヴァーヴァス=, _IAST_=]", # 39
885
- "[Parābhava=, パラーバヴァ=, _IAST_=]", # 40
886
- "[Plavaṅga=, プラヴァンガ=, _IAST_=]", # 41
887
- "[Kīlaka=, キーラカ=, _IAST_=]", # 42
888
- "[Saumya=, サウムヤ=, _IAST_=]", # 43
889
- "[Sādhāraṇa=, サーダーラナ=, _IAST_=]", # 44
890
- "[Virodhakṛt=, ヴィローダクリト=, _IAST_=]", # 45
891
- "[Paridhāvin=, パリダーヴィン=, _IAST_=]", # 46
892
- "[Pramādin=, プラマーディン=, _IAST_=]", # 47
893
- "[Ānanda=, アーナンダ=, _IAST_=]", # 48
894
- "[Rākṣasa=, ラークシャサ=, _IAST_=]", # 49
895
- "[Anala=, アナラ=, _IAST_=]", # 50
896
- "[Piṅgala=, ピンガラ=, _IAST_=]", # 51
897
- "[Kālayukta=, カーラユクタ=, _IAST_=]", # 52
898
- "[Siddhārthin=, シッダールティン=, _IAST_=]", # 53
899
- "[Raudra=, ラウドラ=, _IAST_=]", # 54
900
- "[Durmati=, ドゥルマティ=, _IAST_=]", # 55
901
- "[Dundubhi=, ドゥンドゥビ=, _IAST_=]", # 56
902
- "[Rudhirodgārin=, ルディロードガーリン=, _IAST_=]", # 57
903
- "[Raktākṣin=, ラクタークシン=, _IAST_=]", # 58
904
- "[Krodhana=, クローダナ=, _IAST_=]", # 59
905
- "[Kṣaya=, クシャヤ=, _IAST_=]" # 60
906
- ]
907
- ],
908
-
909
- # 月の暦注 ----------------------------
910
- [When::BasicTypes::M17n,
911
- "names:[month]",
912
- [When::BasicTypes::M17n,
913
- "names:[Month]"
914
- ]
915
- ],
916
-
917
- # 日の暦注 ----------------------------
918
- [When::BasicTypes::M17n,
919
- "names:[day]",
920
-
921
- [When::BasicTypes::M17n,
922
- "names:[tithi=, ティティ=ja:%%<ティティ>]",
923
- "[Amavasya, 新月, _IAST_=]", # 新月
924
- "[Pratipad=en:Prathama_(day), 1日=, _IAST_=]", # 1
925
- "[Dwitiya, 2日=, _IAST_=]", # 2
926
- "[Tritiya, 3日=, _IAST_=]", # 3
927
- "[Chaturthi, 4日=, _IAST_=]", # 4
928
- "[Panchami, 5日=, _IAST_=]", # 5
929
- "[Ṣaṣṭhī=en:Shashti, 6日=, _IAST_=]", # 6
930
- "[Saptami, 7日=, _IAST_=]", # 7
931
- "[Ashtami, 8日=, _IAST_=]", # 8
932
- "[Navami, 9日=, _IAST_=]", # 9
933
- "[Dashami, 10日=, _IAST_=]", # 10
934
- "[Ekadashi, 11日=, _IAST_=]", # 11
935
- "[Dwadashi, 12日=, _IAST_=]", # 12
936
- "[Thrayodashi, 13日=, _IAST_=]", # 13
937
- "[Chaturdashi, 14日=, _IAST_=]", # 14
938
- "[Purnima, 満月, _IAST_=]" # 満月
939
- ],
940
-
941
- [When::BasicTypes::M17n,
942
- "names:[vāra=, ヴァーラ=, _IAST_=, *vara=]",
943
- "[Ravi=en:S%C5%ABrya, 日曜日, _IAST_=]",
944
- "[Soma, 月曜日, _IAST_=]",
945
- "[Maṅgala=en:Mangala, 火曜日, _IAST_=]",
946
- "[Budha, 水曜日, _IAST_=]",
947
- "[Guru, 木曜日, _IAST_=]",
948
- "[Śukra=en:Shukra, 金曜日, _IAST_=]",
949
- "[Śani=en:Shani, 土曜日, _IAST_=]"
950
- ],
951
-
952
- [When::BasicTypes::M17n,
953
- "names:[nakṣatra=, ナクシャトラ=, _IAST_=, *naksatra=]",
954
- "[Aśvinī=en:Ashvin%C4%AB, アシュヴィニー=, _IAST_=, 婁宿]", # 1
955
- "[Bharaṇī=en:Bharan%C4%AB, バラニー=, _IAST_=, 胃宿]", # 2
956
- "[Kṛttikā=en:Krittik%C4%81, クリッティカー=, _IAST_=, 昴宿]", # 3
957
- "[Rohiṇī=en:Rohini_(nakshatra), ローヒニ―=, _IAST_=, 畢宿]", # 4
958
- "[Mṛgaśiras=en:Mrigash%C4%ABrsha, ムリガシラス=, _IAST_=, 觜宿]", # 5
959
- "[Ārdrā=en:Ardra_(nakshatra), アールドラー=, _IAST_=, 參宿]", # 6
960
- "[Punarvasu=en:Punarvasu, プナルヴァス=, _IAST_=, 井宿]", # 7
961
- "[Puṣya=en:Pushya, プシュヤ=, _IAST_=, 鬼宿]", # 8
962
- "[Aśleṣā=en:%C4%80shlesh%C4%81, アーシュレーシャー=, _IAST_=, 柳宿]", # 9
963
- "[Maghā=en:Magh%C4%81, マガー=, _IAST_=, 星宿]", # 10
964
- "[Pū. Phalguṇī=en:P%C5%ABrva_Phalgun%C4%AB, P. パールグニー=, _IAST_=, 張宿]", # 11
965
- "[U. Phalguṇī=en:Uttara_Phalgun%C4%AB, U. パールグニー=, _IAST_=, 翼宿]", # 12
966
- "[Hasta=en:Nakshatra#Divisions, ハスタ=, _IAST_=, 軫宿]", # 13
967
- "[Citrā=en:Nakshatra#Divisions, チトラー=, _IAST_=, 角宿]", # 14
968
- "[Svāti=en:Sv%C4%81t%C4%AB, スヴァーティー=, _IAST_=, 亢宿]", # 15
969
- "[Viśākha=en:Vish%C4%81kh%C4%81, ヴィシャーカー=, _IAST_=, 氐宿]", # 16
970
- "[Anurādhā=en:Anur%C4%81dh%C4%81, アヌラーダー=, _IAST_=, 房宿]", # 17
971
- "[Jyeṣṭha=en:Jyeshtha, ジェーシュター=, _IAST_=, 心宿]", # 18
972
- "[Mūla=en:Mula_(astrology), ムーラ=, _IAST_=, 尾宿]", # 19
973
- "[Pū. āṣāḍha=en:P%C5%ABrva_Ash%C4%81dh%C4%81, P. アーシャーダー=, _IAST_=, 箕宿]", # 20
974
- "[U. āṣāḍha=en:Uttara_Ash%C4%81dh%C4%81, U. アーシャーダー=, _IAST_=, 斗宿]", # 21
975
- "[Śravaṇa=en:Shravana, シュラヴァナ=, _IAST_=, 女宿]", # 22
976
- "[Śraviṣṭhā=en:Dhanishta, ダニシュター=, _IAST_=, 虛宿]", # 23
977
- "[Śatabhiṣak=en:Shatabhish%C4%81, シャタビシャジュ=, _IAST_=, 危宿]", # 24
978
- "[Pū. Bhādrapadā=en:P%C5%ABrva_Bh%C4%81drapad%C4%81,P. バードラパダー=, _IAST_=, 室宿]", # 25
979
- "[U. Bhādrapadā=en:Uttara_Bh%C4%81drapad%C4%81, U. バードラパダー=, _IAST_=, 壁宿]", # 26
980
- "[Revatī=en:Revati_(nakshatra), レーヴァティー=, _IAST_=, 奎宿]" # 27
981
- ],
982
-
983
- [When::BasicTypes::M17n,
984
- "names:[yoga=, ヨーガ=, _IAST_=]",
985
- "[Viṣkambha=, ヴィシュカムバ=, _IAST_=]", # 1
986
- "[Prīti=, プリーティ=, _IAST_=]", # 2
987
- "[Āyuśmān=, アーユシュマー=, _IAST_=]", # 3
988
- "[Saubhāgya=, サウバーギャ=, _IAST_=]", # 4
989
- "[Śobhana=, ショーバナ=, _IAST_=]", # 5
990
- "[Atigaṇḍa=, アティガンダ=, _IAST_=]", # 6
991
- "[Sukarma=, スカルマ=, _IAST_=]", # 7
992
- "[Dhṛti=, ドゥリティ=, _IAST_=]", # 8
993
- "[Śūla=, シューラ=, _IAST_=]", # 9
994
- "[Gaṇḍa=, ガンダ=, _IAST_=]", # 10
995
- "[Vṛddhi=, ヴリッディ=, _IAST_=]", # 11
996
- "[Dhruva=, ドルヴァ=, _IAST_=]", # 12
997
- "[Vyāghāta=, ヴヤーガータ=, _IAST_=]", # 13
998
- "[Harṣaṇa=, ハルシャナ=, _IAST_=]", # 14
999
- "[Vajra=, ヴァジュラ=, _IAST_=]", # 15
1000
- "[Siddhi=, シッディ=, _IAST_=]", # 16
1001
- "[Vyatīpāta=, ヴヤティーパータ=, _IAST_=]", # 17
1002
- "[Varīyas=, ヴァリーヤス=, _IAST_=]", # 18
1003
- "[Parigha=, パリガ=, _IAST_=]", # 19
1004
- "[Śiva=, シヴァ=, _IAST_=]", # 20
1005
- "[Siddha=, シッダ=, _IAST_=]", # 21
1006
- "[Sādhya=, サーディヤ=, _IAST_=]", # 22
1007
- "[Śubha=, シュバ=, _IAST_=]", # 23
1008
- "[Śukla=, シュクラ=, _IAST_=]", # 24
1009
- "[Brahman=, ブラフマン=, _IAST_=]", # 25
1010
- "[Māhendra=, マーヘンドラ=, _IAST_=]", # 26
1011
- "[Vaidhṛti=, ヴァイドリティ=, _IAST_=]" # 27
1012
- ],
1013
-
1014
- [When::BasicTypes::M17n,
1015
- "names:[Karaṇa=, カラナ=, _IAST_=, *karana]",
1016
- "[Bava=, バヴァ=, _IAST_=]", # 1
1017
- "[Bālava=, バーラヴァ=, _IAST_=]", # 2
1018
- "[Kaulava=, カウラヴァ=, _IAST_=]", # 3
1019
- "[Taitila=, タイティラ=, _IAST_=]", # 4
1020
- "[Gara=, ガラ=, _IAST_=]", # 5
1021
- "[Vaṇija=, ヴァニジュ=, _IAST_=]", # 6
1022
- "[Viṣṭi=, ヴィシュティ=, _IAST_=]", # 7
1023
- "[Kiṃtughna=, キンストゥグナ=, _IAST_=]", # A
1024
- "[Śakuni=, シャクニ=, _IAST_=]", # B
1025
- "[Catuṣpāda=, チャトシュパダ=, _IAST_=]", # C
1026
- "[Nāga=, ナーガ=, _IAST_=]" # D
1027
- ]
1028
- ]
1029
- ]]
1030
-
1031
- NoteConsts = {
1032
- 'tithi' => {
1033
- :formula => 15,
1034
- :range => (-1..2),
1035
- :index => [ 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,
1036
- 15,1,2,3,4,5,6,7,8,9,10,11,12,13,14]
1037
- },
1038
- 'naksatra' => {
1039
- :formula => '27M',
1040
- :range => (-1..2),
1041
- :index => (0...27).to_a
1042
- },
1043
- 'yoga' => {
1044
- :formula => '27M+27S',
1045
- :range => (-1..2),
1046
- :index => (0...27).to_a
1047
- },
1048
- 'karana' => {
1049
- :formula => 30,
1050
- :range => (-2..3),
1051
- :index => [7] + (0...7).to_a * 8 + [8,9,10]
1052
- }
1053
- }
1054
-
1055
- #
1056
- # pancanga 計算に必要となる情報をまとめた内部クラス
1057
- #
1058
- class Dates
1059
-
1060
- # @private
1061
- attr_reader :o_date, :l_date, :root, :formula, :iri, :rises
1062
-
1063
- # 初期設定
1064
- # @private
1065
- def initialize(date)
1066
- @o_date = date
1067
- clock = date.clock
1068
- frame = date.frame if date.frame.kind_of?(When::CalendarTypes::HinduLuniSolar)
1069
- @l_date = (frame || When.Calendar('HinduLuniSolar?note=HinduNote')).jul_trans(date.to_i, {:clock=>'+05:30'})
1070
- @root = When.CalendarNote('HinduNote/Notes')['day']
1071
- @formula = @l_date.frame.formula[-1]
1072
- @iri = @formula.iri
1073
- @rises = [@formula.sunrise(@l_date), @formula.sunrise(@l_date+When.Duration('P1D'))]
1074
- end
1075
-
1076
- # その他のメソッドは @l_date に移譲する
1077
- def method_missing(name, *args, &block)
1078
- self.class.module_eval %Q{
1079
- def #{name}(*args, &block)
1080
- @l_date.send("#{name}", *args, &block)
1081
- end
1082
- } unless When::Parts::MethodCash.escape(name)
1083
- @l_date.send(name, *args, &block)
1084
- end
1085
- end
1086
-
1087
- #
1088
- # 任意の暦をインド太陰太陽暦日に変換
1089
- # @private
1090
- def _to_date_for_note(date)
1091
- Dates.new(date)
1092
- end
1093
-
1094
- #
1095
- # 木星年
1096
- #
1097
- # @param [Dates] dates
1098
- #
1099
- # @return [When::BasicTypes::M17n] 木星年の名称
1100
- #
1101
- # see {http://en.wikipedia.org/wiki/Samvatsara Samvatsara}
1102
- #
1103
- def samvatsara(dates)
1104
- year_kali = dates.l_date.most_significant_coordinate + dates.l_date.frame.epoch_in_CE + 3101
1105
- year_mod = year_kali >= jovian ? (year_kali + 12) % 60 :
1106
- ((year_kali * 211 - 108).div(18000) + year_kali + 26) % 60
1107
- When.CalendarNote('HinduNote/Notes')['year']['samvatsara'][year_mod]
1108
- end
1109
-
1110
- #
1111
- # 木星年の計算方式に“South”を適用開始する年
1112
- #
1113
- # @return [Integer] 年(カリユガ紀元)
1114
- #
1115
- def jovian
1116
- return @jovian if @jovian.kind_of?(Integer)
1117
- @jovian = @jovian ? @jovian.to_i : 4009
1118
- end
1119
-
1120
- #
1121
- # ヴァーラ (七曜)
1122
- #
1123
- # @param [Dates] dates
1124
- #
1125
- # @return [Array<When::TM::TemporalPosition>] 日の出の時刻をイベント時刻とする
1126
- #
1127
- def vara(dates)
1128
- rise = dates.rises[0]
1129
- rise.events = [dates.root['vara'][(rise.to_i+1) % 7]]
1130
- ['V:-', rise]
1131
- end
1132
-
1133
- #
1134
- # ヴァーラ以外
1135
- #
1136
-
1137
- # 当該日付中でティティが変わる日時
1138
- # @method tithi(dates)
1139
- # @param [Dates] dates
1140
- # @return [Array<When::TM::TemporalPosition>] イベント日時
1141
-
1142
- # 当該日付中でナクシャトラが変わる日時
1143
- # @method naksatra(dates)
1144
- # @param [Dates] dates
1145
- # @return [Array<When::TM::TemporalPosition>] イベント日時
1146
-
1147
- # 当該日付中でヨーガが変わる日時
1148
- # @method yoga(dates)
1149
- # @param [Dates] dates
1150
- # @return [Array<When::TM::TemporalPosition>] イベント日時
1151
-
1152
- # 当該日付中でカラナが変わる日時
1153
- # @method karana(dates)
1154
- # @param [Dates] dates
1155
- # @return [Array<When::TM::TemporalPosition>] イベント日時
1156
- #
1157
-
1158
- # @private
1159
- NoteConsts.keys.each do |key|
1160
- module_eval %Q{
1161
- def #{key}(dates)
1162
- pancanga(dates, '#{key}').map {|event| ['#{key[0..0].upcase}:-', event]}
1163
- end
1164
- }
1165
- end
1166
-
1167
- #
1168
- # ヴァーラ以外のイベント日時
1169
- #
1170
- # @param [Dates] dates
1171
- # @param [String] key 'tithi', 'naksatra', 'yoga', 'karana' のいずれか
1172
- # @return [Array<When::TM::TemporalPosition>] イベント日時
1173
- #
1174
- def pancanga(dates, key)
1175
- pattern = NoteConsts[key]
1176
- note = dates.root[key]
1177
- if pattern[:formula].kind_of?(Numeric)
1178
- factor = pattern[:formula].to_f
1179
- formula = dates.formula
1180
- else
1181
- factor = 1.0
1182
- formula = When.Resource(dates.iri.sub(/formula=2L/, "formula=#{pattern[:formula]}"))
1183
- end
1184
- cn = (formula.time_to_cn(dates.l_date) * factor).floor
1185
- events = []
1186
- pattern[:range].each do |i|
1187
- event = formula._to_seed_type(formula.cn_to_time((cn+i)/factor), dates.l_date)
1188
- break if +event >= +dates.rises[1]
1189
- next if +event < +dates.rises[0]
1190
- event.events = [note[pattern[:index][(cn+i) % pattern[:index].length]]]
1191
- events << event
1192
- end
1193
- events
1194
- end
1195
- end
1196
-
1197
- #
1198
- # 日の出の九惑星の位置まで計算
1199
- #
1200
- class HinduNoteDetailed < HinduNote
1201
-
1202
- Notes = HinduNote::Notes
1203
-
1204
- #
1205
- # ヴァーラ (七曜)と九惑星の位置
1206
- #
1207
- # @param [Dates] dates
1208
- # @return [Array<When::TM::TemporalPosition, Hash{ 惑星シンボル=>惑星の真黄経 }>]
1209
- # 日の出の時刻をイベント時刻とし、その時刻での九惑星の位置を計算
1210
- #
1211
- def vara(dates)
1212
- rise = dates.rises[0]
1213
- rise.events = [dates.root['vara'][(rise.to_i+1) % 7]]
1214
- t = dates.formula.is_dynamical ? +rise : rise.to_f
1215
- [['V:-', rise], dates.formula.graha.keys.inject({}) {|h,p|
1216
- h.store(p, dates.formula.graha[p].true_longitude(t))
1217
- h
1218
- }]
1219
- end
1220
- end
1221
- end
1222
- end
1
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ Copyright (C) 2011-2015 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
+ require 'when_exe/locales/iast'
9
+
10
+ module When
11
+ class BasicTypes::M17n
12
+
13
+ Indian = [self, [
14
+ "locale:[=en:, ja=ja:, zh=zh:, alias]",
15
+ "names:[Indian=en:India, インド, 印度]",
16
+ "[IndianNationalSolar=en:Indian_national_calendar, インド国定暦, 印度國定曆, era:SE=]",
17
+ "[Nanakshahi=en:Nanakshahi_calendar, ナーナク暦=, 拿那克曆=]",
18
+ "[RevisedBengali=en:Bengali_calendar, 改訂ベンガル暦=, 改变孟加拉曆=]",
19
+ "[HinduSolar=en:Hindu_calendar, インド太陽暦=ja:%%<ヒンドゥー暦>, 印度陽曆=]",
20
+ "[HinduLuniSolar=en:Hindu_calendar, インド太陰太陽暦=ja:%%<ヒンドゥー暦>, 印度陰陽曆=]",
21
+
22
+ [self,
23
+ "locale:[=en:, ja=ja:, hi=hi:, alias]",
24
+ "names:[HalfMonth=, 半月=, pakṣa=, zh:半月=, *IntercalaryMonth=en:Intercalation]",
25
+ "[%s Śuklapakṣa=, %s 白分=, _IAST_=]",
26
+ "[%s Kṛṣṇapakṣa=, %s 黒分=, _IAST_=]",
27
+ "[adhika %s Śuklapakṣa=, 閏%s 白分=, _IAST_=]",
28
+ "[adhika %s Kṛṣṇapakṣa=, 閏%s 黒分=, _IAST_=]"
29
+ ],
30
+
31
+ [self,
32
+ "names:[IntercalaryDay=en:Intercalation, 閏日=ja:%%<閏>]",
33
+ "[%s and next day=, %sと翌日=]",
34
+ "[Intercalary %s=, 重%s=]"
35
+ ],
36
+
37
+ [self,
38
+ "locale:[=en:, ja=ja:, hi=hi:, alias]",
39
+ "names:[month name named after the star mansion=, 二十七宿にちなむ月名=, zh:對應於星宿月份名稱=, *alias:LunarMonth=]",
40
+ "[Mārgaśīra=en:Margashirsha, マールガシールシャ=, _IAST_=]",
41
+ "[Pauṣa=en:Pausha, パウシャ=, _IAST_=]",
42
+ "[Māgha=en:Maagha, マーガ=, _IAST_=]",
43
+ "[Phālguna=en:Phalguna, パールグナ=, _IAST_=]",
44
+ "[Caitra=en:Chaitra, チャイトラ=, _IAST_=]",
45
+ "[Vaiśākha=en:Vaisakha, ヴァイシャーカ=, _IAST_=]",
46
+ "[Jyaiṣṭha=en:Jyeshta, ジャイシュタ=, _IAST_=]",
47
+ "[Āṣāḍha=en:Aashaadha, アーシャーダ=, _IAST_=]",
48
+ "[Śrāvaṇa=en:Shraavana, シュラーヴァナ=, _IAST_=]",
49
+ "[Bhādrapada=en:Bhadrapada, バードラパダ=, _IAST_=]",
50
+ "[Āśvina=en:Ashwin, アーシュヴィナ=, _IAST_=]",
51
+ "[Kārttika=en:Kartika_(month), カールッティカ=, _IAST_=]"
52
+ ],
53
+
54
+ [self,
55
+ "locale:[=en:, ja=ja:, hi=hi:, alias]",
56
+ "names:[month name named after the zodiac=, 黄道十二宮にちなむ月名=, zh:對應於黃道十二宮月份名稱=, *alias:SolarMonth=]",
57
+ "[Maysha=, 白羊宮, _IAST_=]",
58
+ "[Vrushabha=, 金牛宮, _IAST_=]",
59
+ "[Mithuna=, 双児宮, _IAST_=]",
60
+ "[Karka=, 巨蟹宮, _IAST_=]",
61
+ "[Simha=, 獅子宮, _IAST_=]",
62
+ "[Kanya=, 処女宮, _IAST_=]",
63
+ "[Tula=, 天秤宮, _IAST_=]",
64
+ "[Vrushchika=, 天蝎宮, _IAST_=]",
65
+ "[Dhanu=, 人馬宮, _IAST_=]",
66
+ "[Makar=, 磨羯宮, _IAST_=]",
67
+ "[Kumbha=, 宝瓶宮, _IAST_=]",
68
+ "[Meena=, 双魚宮, _IAST_=]"
69
+ ],
70
+
71
+ [self,
72
+ "names:[month name named after the star mansion=, 二十七宿にちなむ月名=, zh:對應於星宿月份名稱=, *alias:NanakshahiMonth=]",
73
+ "[Maghar=en:Maghar_(month) ]",
74
+ "[Poh ]",
75
+ "[Magh=en:Magh_(Sikh_calendar)]",
76
+ "[Phagun ]",
77
+ "[Chet=en:Chet_(month) ]",
78
+ "[Vaisakh ]",
79
+ "[Jeth ]",
80
+ "[Harh ]",
81
+ "[Sawan ]",
82
+ "[Bhadon ]",
83
+ "[Assu ]",
84
+ "[Katak ]"
85
+ ],
86
+
87
+ [self,
88
+ "names:[month name named after the star mansion=, 二十七宿にちなむ月名=, zh:對應於星宿月份名稱=, *alias:BengaliMonth=]",
89
+ "[Ogrôhayôn=]",
90
+ "[Poush= ]",
91
+ "[Magh= ]",
92
+ "[Falgun= ]",
93
+ "[Chôitrô= ]",
94
+ "[Bôishakh= ]",
95
+ "[Jyôishţhô=]",
96
+ "[Ashaŗh= ]",
97
+ "[Shrabôn= ]",
98
+ "[Bhadrô= ]",
99
+ "[Ashbin= ]",
100
+ "[Kartik= ]"
101
+ ]
102
+ ]]
103
+ end
104
+
105
+ module Coordinates
106
+
107
+ # Location of cities in India
108
+ Indian = [When::BasicTypes::M17n, [
109
+ "locale:[=en:, ja=ja:, alias]",
110
+ "names:[Indian=en:India, インド, zh:印度]",
111
+ [Spatial, "long:+82.5", "lat:N23.11", "label:[CentralIndia=, インド中部=]" ],
112
+ [Spatial, "long:+82.5", "lat:+29.0", "label:[NorthIndia=, インド北部]" ],
113
+ [Spatial, "long:+78.0", "lat:+27.2", "label:[Agra, アーグラ]" ],
114
+ [Spatial, "long:+72.6", "lat:+23.0", "label:[Ahmedabad, アフマダーバード]" ],
115
+ [Spatial, "long:+74.6", "lat:+26.5", "label:[Ajmer, アジメール]" ],
116
+ [Spatial, "long:+78.1", "lat:+27.9", "label:[Aligarh, アリーガル]" ],
117
+ [Spatial, "long:+74.9", "lat:+31.6", "label:[Amritsar, アムリトサル]" ],
118
+ [Spatial, "long:+77.6", "lat:+13.0", "label:[Bangalore, バンガロール]" ],
119
+ [Spatial, "long:+85.8", "lat:+20.2", "label:[Bhuvaneswar, ブヴァネーシュヴァル]"],
120
+ [Spatial, "long:+80.3", "lat:+13.1", "label:[Chennai, チェンナイ, Madras]" ],
121
+ [Spatial, "long:+79.9", "lat: +6.9", "label:[Colombo, コロンボ]" ],
122
+ [Spatial, "long:+90.4", "lat:+23.7", "label:[Dacca, ダッカ]" ],
123
+ [Spatial, "long:+77.2", "lat:+28.6", "label:[Delhi, デリー]" ],
124
+ [Spatial, "long:+78.5", "lat:+17.4", "label:[Hyderabad, ハイデラバード]" ],
125
+ [Spatial, "long:+75.8", "lat:+26.9", "label:[Jaipur, ジャイプル]" ],
126
+ [Spatial, "long:+85.2", "lat:+27.7", "label:[Kathmandu, カトマンズ]" ],
127
+ [Spatial, "long:+76.2", "lat:+10.0", "label:[Kochi, コーチ, Cochin]" ],
128
+ [Spatial, "long:+88.4", "lat:+22.6", "label:[Kolkata, コルカタ, Calcutta]" ],
129
+ [Spatial, "long:+74.3", "lat:+31.6", "label:[Lahor, ラホール]" ],
130
+ [Spatial, "long:+77.7", "lat:+27.5", "label:[Mathura, マトゥラー]" ],
131
+ [Spatial, "long:+72.8", "lat:+19.0", "label:[Mumbai, ムンバイ, Bombay]" ],
132
+ [Spatial, "long:+76.6", "lat:+12.3", "label:[Mysore, マイソール]" ],
133
+ [Spatial, "long:+85.1", "lat:+25.6", "label:[Patna, パトナ]" ],
134
+ [Spatial, "long:+73.9", "lat:+18.5", "label:[Pune, プネー]" ],
135
+ [Spatial, "long:+74.8", "lat:+34.1", "label:[Srinagar, シュリーナガル]" ],
136
+ [Spatial, "long:+77.0", "lat: +8.5", "label:[Thiruvananthapuram, ティルヴァナンタプラム, Trivandrum]"],
137
+ [Spatial, "long:+83.0", "lat:+25.3", "label:[Varanasi, ワーラーナシー]" ],
138
+ [Spatial, "long:+75.8", "lat:+23.2", "label:[Ujjain, ウッジャイン=]" ]
139
+ ]]
140
+ end
141
+
142
+ module Ephemeris
143
+
144
+ #
145
+ # Hindu Luni-Solar Calendar Formula
146
+ #
147
+ class Hindu < Formula
148
+
149
+ # Basic Astronomical Constants for Surya-Siddhanta
150
+ Tz = 0.5+75.8/360 # time difference between JulianDayNumber and Ujjain
151
+ E = 588_466 - Tz # Yuga Epoch -3101-02-18T00:00:00
152
+ P = 180 # Precession cycles in yuga
153
+ Ep = 1_903_318 - Tz # Precession Epoch 499-01-01
154
+ Ob = 24.0 / 360.0 # Obliquity of the ecliptic
155
+
156
+ Grahas = {
157
+ 'SS' => { # Previous / Newest
158
+ :Star => 1_582_237_800.0, # 1_582_237_500 / 1_582_237_800
159
+ :Sun => 4_320_000.0,
160
+ :Moon => 57_753_336.0,
161
+ :Mercury => 17_937_000.0,
162
+ :Venus => 7_022_388.0,
163
+ :Mars => 2_296_824.0,
164
+ :Jupiter => 364_220.0,
165
+ :Saturn => 146_564.0,
166
+ :Candrocca => 488_219.0, # 488_203 / 488_219
167
+ :Rahu => -232_226.0
168
+ },
169
+ 'SB' => {
170
+ :Star => 1_582_237_828.0,
171
+ :Sun => 4_320_000.0,
172
+ :Moon => 57_753_336.0,
173
+ :Mercury => 17_937_060.0,
174
+ :Venus => 7_022_376.0,
175
+ :Mars => 2_296_832.0,
176
+ :Jupiter => 364_220.0,
177
+ :Saturn => 146_568.0,
178
+ :Candrocca => 488_203.0, # 488_199 / 488_203
179
+ :Rahu => -232_238.0
180
+ }
181
+ }
182
+
183
+ #
184
+ # 日月五惑星とラーフおよびケートゥ
185
+ #
186
+ # @abstract
187
+ class Graha
188
+ include When::Ephemeris
189
+ end
190
+
191
+ #
192
+ # 現代的“惑星”
193
+ #
194
+ class ModernGraha < Graha
195
+
196
+ # 真黄経
197
+ #
198
+ # @param [Numeric] t ユリウス日
199
+ #
200
+ # @return [Numeric]
201
+ #
202
+ def true_longitude(t)
203
+ @target.coords(t, @base).phi
204
+ end
205
+
206
+ # オブジェクトの生成
207
+ #
208
+ # @param [When::Ephemeris::Datum] target 天体
209
+ # @param [When::Coordinates::Spatial] base 観測地
210
+ #
211
+ def initialize(target, base)
212
+ @target = target
213
+ @base = base
214
+ end
215
+ end
216
+
217
+ #
218
+ # 古典的“惑星”
219
+ #
220
+ # @abstract
221
+ class ClassicGraha < Graha
222
+
223
+ # 平均黄経
224
+ #
225
+ # @param [Numeric] t ユリウス日
226
+ #
227
+ # @return [Numeric]
228
+ #
229
+ def mean_longitude(t)
230
+ _mean_rotation(t - E)
231
+ end
232
+
233
+ # 真黄経
234
+ #
235
+ # @param [Numeric] t ユリウス日
236
+ #
237
+ # @return [Numeric]
238
+ #
239
+ def true_longitude(t)
240
+ _true_rotation(t - E)
241
+ end
242
+
243
+ # 平均黄経
244
+ #
245
+ # @param [Numeric] ahar カリユガ暦元からの経過日数
246
+ #
247
+ # @return [Numeric]
248
+ #
249
+ def _mean_rotation(ahar)
250
+ @rotation * ahar / @formula.civil_days
251
+ end
252
+
253
+ # オブジェクトの生成
254
+ #
255
+ # @param [When::Ephemeris::Formula] formula 親オブジェクト
256
+ # @param [Numeric] rotation ユガあたりの回転数
257
+ #
258
+ def initialize(formula, rotation)
259
+ @formula = formula
260
+ @rotation = rotation
261
+ end
262
+ end
263
+
264
+ # 架空の“惑星” - ラーフ / 月軌道の遠地点としてのケートゥ
265
+ class VirtualGraha < ClassicGraha
266
+
267
+ # 平均黄経
268
+ #
269
+ # @param [Numeric] ahar カリユガ暦元からの経過日数
270
+ #
271
+ # @return [Numeric]
272
+ #
273
+ def _mean_rotation(ahar)
274
+ super + @rotation0
275
+ end
276
+ alias :_true_rotation :_mean_rotation
277
+
278
+ # オブジェクトの生成
279
+ #
280
+ # @param [When::Ephemeris::Formula] formula 親オブジェクト
281
+ # @param [Numeric] rotation ユガあたりの回転数
282
+ # @param [Numeric] rotation0 カリユガ暦元での回転量
283
+ #
284
+ def initialize(formula, rotation, rotation0)
285
+ @rotation0 = rotation0 / 360.0
286
+ super(formula, rotation)
287
+ end
288
+ end
289
+
290
+ # 実在の“惑星”
291
+ # @abstract
292
+ class RealGraha < ClassicGraha
293
+
294
+ # マンダ補正
295
+ #
296
+ # @param [Numeric] rot 平均近点角など / CIRCLE
297
+ #
298
+ # @return [Numeric]
299
+ #
300
+ def _manda_equation(rot)
301
+ asin(@circumm * sinc(rot)) / CIRCLE
302
+ end
303
+
304
+ # オブジェクトの生成
305
+ #
306
+ # @param [When::Ephemeris::Formula] formula 親オブジェクト
307
+ # @param [Numeric] rotation ユガあたりの回転数
308
+ # @param [Numeric] circumm マンダ円の半径
309
+ # @param [Numeric] apogee 近点黄経 / CIRCLE
310
+ #
311
+ def initialize(formula, rotation, circumm, apogee)
312
+ @circumm = circumm / 360.0
313
+ @apogee = apogee / 360.0
314
+ super(formula, rotation)
315
+ end
316
+ end
317
+
318
+ # 太陽と月 - 逆行しない“惑星”
319
+ # @abstract
320
+ class ConcentricGraha < RealGraha
321
+
322
+ # 平均黄経
323
+ #
324
+ # @param [Numeric] ahar カリユガ暦元からの経過日数
325
+ #
326
+ # @return [Numeric]
327
+ #
328
+ def _mean_rotation(ahar)
329
+ super + @epoch
330
+ end
331
+
332
+ # オブジェクトの生成
333
+ #
334
+ # @param [When::Ephemeris::Formula] formula 親オブジェクト
335
+ # @param [Numeric] rotation ユガあたりの回転数
336
+ # @param [Numeric] circumm マンダ円の半径
337
+ # @param [Numeric] apogee 近点黄経 / CIRCLE
338
+ # @param [Numeric] epoch カリユガ暦元での黄経 / CIRCLE
339
+ #
340
+ def initialize(formula, rotation, circumm, apogee, epoch)
341
+ @epoch = epoch
342
+ super(formula, rotation, circumm, apogee)
343
+ end
344
+ end
345
+
346
+ # 太陽
347
+ class Sun < ConcentricGraha
348
+
349
+ # 真黄経
350
+ #
351
+ # @param [Numeric] ahar カリユガ暦元からの経過日数
352
+ #
353
+ # @return [Numeric]
354
+ #
355
+ def _true_rotation(ahar)
356
+ mean = _mean_rotation(ahar)
357
+ mean - _manda_equation(mean - @apogee)
358
+ end
359
+ end
360
+
361
+ #
362
+ class Moon < ConcentricGraha
363
+
364
+ # 真黄経
365
+ #
366
+ # @param [Numeric] ahar カリユガ暦元からの経過日数
367
+ #
368
+ # @return [Numeric]
369
+ #
370
+ def _true_rotation(ahar)
371
+ mean = _mean_rotation(ahar)
372
+ mean - _manda_equation(mean - @formula.graha[:Candrocca]._mean_rotation(ahar))
373
+ end
374
+ end
375
+
376
+ # 惑星 - 逆行するもの
377
+ # @abstract
378
+ class Planet < RealGraha
379
+
380
+ # シグラ補正
381
+ #
382
+ # @param [Numeric] anomaly 平均近点角 / CIRCLE
383
+ #
384
+ # @return [Numeric]
385
+ #
386
+ def _sighra_equation(anomaly)
387
+ atan2(@circums * sinc(anomaly), @circums * cosc(anomaly) + 1) / CIRCLE
388
+ end
389
+
390
+ # 平均シグラ
391
+ #
392
+ # @param [Numeric] ahar カリユガ暦元からの経過日数
393
+ #
394
+ # @return [Numeric]
395
+ #
396
+ def _mean_sighra(ahar)
397
+ @sighra * ahar / @formula.civil_days
398
+ end
399
+
400
+ # 真黄経
401
+ #
402
+ # @param [Numeric] ahar カリユガ暦元からの経過日数
403
+ # @param [Numeric] rotation 基準回転量 / CIRCLE
404
+ #
405
+ # @return [Numeric]
406
+ #
407
+ def _true_rotation(ahar, rotation)
408
+ # first sighra correction
409
+ delta = _sighra_equation(_mean_sighra(ahar) - rotation) / 2
410
+
411
+ # first manda correction
412
+ mean = _mean_rotation(ahar) + delta
413
+ delta = _manda_equation(mean - @apogee) / 2
414
+
415
+ # second manda correction
416
+ mean -= delta
417
+ delta = _manda_equation(mean - @apogee)
418
+
419
+ # second sighra correction
420
+ mean = _mean_rotation(ahar) - delta
421
+ delta = _sighra_equation(_mean_sighra(ahar) - mean)
422
+
423
+ # true rotation
424
+ mean + delta
425
+ end
426
+
427
+ # オブジェクトの生成
428
+ #
429
+ # @param [When::Ephemeris::Formula] formula 親オブジェクト
430
+ # @param [Numeric] rotation ユガあたりの回転数
431
+ # @param [Numeric] circumm マンダ円の半径
432
+ # @param [Numeric] apogee 近点黄経 / CIRCLE
433
+ # @param [Numeric] sighra シグラ対象のカリユガあたりの回転数
434
+ # @param [Numeric] circums シグラ円の半径
435
+ #
436
+ def initialize(formula, rotation, circumm, apogee, sighra, circums)
437
+ @sighra = sighra
438
+ @circums = circums / 360.0
439
+ super(formula, rotation, circumm, apogee)
440
+ end
441
+ end
442
+
443
+ # 内惑星 - 水金
444
+ class InferiorPlanet < Planet
445
+
446
+ # 真黄経
447
+ #
448
+ # @param [Numeric] t ユリウス日
449
+ #
450
+ # @return [Numeric]
451
+ #
452
+ def true_longitude(t)
453
+ ahar = t - E
454
+ _true_rotation(ahar, @formula.graha[:Sun]._mean_rotation(ahar))
455
+ end
456
+ end
457
+
458
+ # 外惑星 - 火木土
459
+ class SuperiorPlanet < Planet
460
+
461
+ # 真黄経
462
+ #
463
+ # @param [Numeric] t ユリウス日
464
+ #
465
+ # @return [Numeric]
466
+ #
467
+ def true_longitude(t)
468
+ ahar = t - E
469
+ _true_rotation(ahar, _mean_rotation(ahar))
470
+ end
471
+ end
472
+
473
+ #
474
+ # ユガの太陽日数
475
+ #
476
+ # @return [Numeric]
477
+ #
478
+ attr_reader :civil_days
479
+
480
+ # 日の出の日時
481
+ #
482
+ # @param [Numeric] sdn ユリウス日
483
+ # @param [When::TM::TemporalPosition] sdn
484
+ # @param [nil] height 太陽高度(本クラスでは使用しない)
485
+ #
486
+ # @return [Integer, When::TM::DateAndTime] 日の出の日時
487
+ #
488
+ def sunrise(sdn, height=nil)
489
+ t = sdn.to_i - @long / 360.0 - 0.25
490
+ p = _mean_sun(t) + P * (t - Ep) / @civil_days
491
+ _to_seed_type(t - asin(tand(@lat)*tan(asin(sinc(p)*sinc(Ob)))) / CIRCLE, sdn)
492
+ end
493
+
494
+ # 日の入りの日時
495
+ #
496
+ # @param [Numeric] sdn ユリウス日
497
+ # @param [When::TM::TemporalPosition] sdn
498
+ # @param [nil] height 太陽高度(本クラスでは使用しない)
499
+ #
500
+ # @return [Integer, When::TM::DateAndTime] 日の入りの日時
501
+ #
502
+ def sunset(sdn, height=nil)
503
+ t = sdn.to_i - @long / 360.0 + 0.25
504
+ p = _mean_sun(t) + P * (t - Ep) / @civil_days
505
+ _to_seed_type(t + asin(tand(@lat)*tan(asin(sinc(p)*sinc(Ob)))) / CIRCLE, sdn)
506
+ end
507
+
508
+ # 太陽の南中の日時
509
+ #
510
+ # @param [Numeric] sdn ユリウス日
511
+ # @param [When::TM::TemporalPosition] sdn
512
+ #
513
+ # @return [Integer, When::TM::DateAndTime] 太陽の南中の日時
514
+ #
515
+ def sun_noon(sdn)
516
+ _to_seed_type(sdn.to_i - @long / 360.0, sdn)
517
+ end
518
+
519
+ private
520
+
521
+ # オブジェクトの正規化
522
+ def _normalize(args=[], options={})
523
+ @time_standard ||= 'universal'
524
+ @bija ||= 'SB'
525
+ super
526
+ end
527
+
528
+ # 9惑星オブジェクトの生成
529
+ def _normalize_grahas
530
+ grahas = Grahas[@bija]
531
+
532
+ # ユガあたりの暦定数
533
+ @sidereal_days = grahas[:Star] # 恒星日
534
+ @solar_years = grahas[:Sun] # 太陽年
535
+ @civil_days = @sidereal_days - @solar_years # 太陽日
536
+ @sidereal_months = grahas[:Moon] # 恒星月
537
+ @synodic_months = @sidereal_months - @solar_years # 朔望月
538
+ @adhimasas = @synodic_months - 12 * @solar_years # 閏月
539
+ @tithis = 30 * @sidereal_months # 太陰日
540
+ @ksayadinas = @tithis - @civil_days # 欠日
541
+
542
+ # 9惑星
543
+ @graha = {}
544
+ @graha.update({
545
+ :Sun => Sun.new( self, @solar_years, 13+50/60.0, 77+17/60.0, -3101)
546
+ }) if @formula =~ /[SL]/i
547
+ @graha.update({
548
+ :Moon => Moon.new( self, @sidereal_months, 31+50/60.0, 0, -28086),
549
+ :Candrocca => VirtualGraha.new( self, grahas[:Candrocca], 90.0)
550
+ }) if @formula =~ /[ML]/i
551
+ @graha.update({
552
+ :Mercury => InferiorPlanet.new(self, @solar_years, 29.0, 220+27/60.0, grahas[:Mercury], 131.5),
553
+ :Venus => InferiorPlanet.new(self, @solar_years, 11.5, 79+50/60.0, grahas[:Venus], 261.0),
554
+ :Mars => SuperiorPlanet.new(self, grahas[:Mars], 73.5, 130+02/60.0, @solar_years, 233.5),
555
+ :Jupiter => SuperiorPlanet.new(self, grahas[:Jupiter], 32.5, 171+18/60.0, @solar_years, 71.0),
556
+ :Saturn => SuperiorPlanet.new(self, grahas[:Saturn], 48.5, 236+37/60.0, @solar_years, 39.5),
557
+ :Rahu => VirtualGraha.new( self, grahas[:Rahu], 180.0)
558
+ }) if @formula == '2L'
559
+ end
560
+ end
561
+ end
562
+
563
+ module CalendarTypes
564
+
565
+ #
566
+ # Indian national solar calendar
567
+ #
568
+ IndianNationalSolar = [SolarYearTableBasedWithSunrise, {
569
+ 'label' => 'Indian::IndianNationalSolar',
570
+ 'origin_of_MSC' => -78,
571
+ 'diff_to_CE' => 0,
572
+ 'engine_month' => 2, # February
573
+ 'engine_day' => 28+22, # 22nd of next month
574
+ 'indices' => [
575
+ When.Index('Indian::LunarMonth', {:unit =>12, :shift=>4}),
576
+ When::Coordinates::DefaultDayIndex
577
+ ],
578
+ 'rule_table' => {
579
+ 365 => {'Length'=>[30] + [31]*5 + [30]*6},
580
+ 366 => {'Length'=> [31]*6 + [30]*6}
581
+ }
582
+ }]
583
+
584
+ #
585
+ # Nanakshahi Calendar
586
+ #
587
+ Nanakshahi = [SolarYearTableBased, {
588
+ 'label' => 'Indian::Nanakshahi',
589
+ 'origin_of_MSC' => -1468,
590
+ 'diff_to_CE' => 0,
591
+ 'engine_month' => 3,
592
+ 'engine_day' => 14,
593
+ 'indices' => [
594
+ When.Index('Indian::NanakshahiMonth', {:unit=>12, :shift=>4}),
595
+ When::Coordinates::DefaultDayIndex
596
+ ],
597
+ 'rule_table' => {
598
+ 365 => {'Length'=> [31]*5 + [30]*7},
599
+ 366 => {'Length'=> [31]*5 + [30]*6 + [31]}
600
+ }
601
+ }]
602
+
603
+ #
604
+ # Revised Bengali Calendar
605
+ #
606
+ RevisedBengali = [SolarYearTableBased, {
607
+ 'label' => 'Indian::RevisedBengali',
608
+ 'origin_of_MSC' => -593,
609
+ 'diff_to_CE' => 0,
610
+ 'engine_month' => 4,
611
+ 'engine_day' => 14,
612
+ 'indices' => [
613
+ When.Index('Indian::BengaliMonth', {:unit=>12, :shift=>5}),
614
+ When::Coordinates::DefaultDayIndex
615
+ ],
616
+ 'rule_table' => {
617
+ 365 => {'Length'=> [31]*5 + [30]*7},
618
+ 366 => {'Length'=> [31]*5 + [30]*5 + [31, 30]}
619
+ }
620
+ }]
621
+
622
+ #
623
+ # Hindu Solar Calendar
624
+ #
625
+ class HinduSolar < EphemerisBasedSolar
626
+
627
+ # protected
628
+
629
+ # 月初の通日
630
+ #
631
+ # @param [Integer] m 通月
632
+ #
633
+ # @return [Integer] 月初の通日
634
+ #
635
+ def _new_month_(m)
636
+ new_month_time = @formula[0].cn_to_time(m + @cycle_offset)
637
+ new_month_date = (new_month_time + 0.5 + @formula[0].long/360.0).floor
638
+ sunrise_time = @formula[0].sunrise(new_month_date)
639
+ (sunrise_time <= new_month_time) ? new_month_date : new_month_date-1
640
+ end
641
+
642
+ private
643
+
644
+ # オブジェクトの正規化
645
+ #
646
+ # @formula[0] = 位相の計算に用いる太陽の Formula
647
+ # @cycle_offset = 位相のオフセット
648
+ # @start_month = 暦年の最初の月
649
+ #
650
+ def _normalize(args=[], options={})
651
+ @label ||= 'Indian::HinduSolar'
652
+ @type ||= 'SBS'
653
+ raise ArgumentError, "Irregal formula: #{@formula}" unless @type.upcase =~ /\A(M|SS|SB)(V|S|B|H|VZ|SZ|BZ|HZ)\z/
654
+
655
+ @location ||= HinduLuniSolar::Location_E[$2] || HinduLuniSolar::Location_F[$1]
656
+ @cycle_offset ||= HinduLuniSolar::CycleOffset[$1]
657
+ @origin_of_MSC ||= -HinduLuniSolar::YearEpoch[$2]
658
+ @diff_to_CE ||= 0
659
+ @start_month ||= 1 # Maysha
660
+ @start_month = @start_month.to_i
661
+ @cycle_offset = @cycle_offset.to_f + (@start_month - 1)
662
+ formula = @formula || HinduLuniSolar::Formula[$1]
663
+ if formula.kind_of?(String)
664
+ formula += (formula =~ /\?/) ? '&' : '?'
665
+ @formula = [When.Resource("_ep:#{formula}location=(#{@location})&formula=12S")]
666
+ end
667
+ @indices ||= [
668
+ When.Index('Indian::SolarMonth', {:shift=>@start_month-1}),
669
+ When::Coordinates::DefaultDayIndex
670
+ ]
671
+
672
+ super
673
+ end
674
+ end
675
+
676
+ #
677
+ # Hindu Luni-Solar Calendar
678
+ #
679
+ class HinduLuniSolar < EphemerisBasedLuniSolar
680
+
681
+ # Calendar Type
682
+ Formula = {'M'=>'Formula', 'SS'=>'Hindu?bija=SS', 'SB'=>'Hindu?bija=SB'}
683
+ Location_F = {'M'=>'_co:Indian::CentralIndia', 'SS'=>'_co:Indian::Ujjain', 'SB'=>'_co:Indian::Ujjain'}
684
+ Location_E = {'B'=>'_co:Indian::Dacca', 'BZ'=>'_co:Indian::Dacca', 'H'=>'_co:Iranian::Tehran', 'HZ'=>'_co:Iranian::Tehran'}
685
+ CycleOffset = {'M'=>+23.25/30, 'SS'=>0.0, 'SB'=>0.0}
686
+ HinduStyle = {'A'=>0, 'P'=>1, 'PX'=>2}
687
+ YearEpoch = {'V'=>-58,'VZ'=>-57,'S'=>78, 'SZ'=>79, 'B'=> 593, 'BZ'=>594, 'H'=> 621, 'HZ'=> 622}
688
+
689
+ # White / black month and leap month identification table
690
+
691
+ #[w]/b [n]/l #0 #1 #2
692
+ LEAP_MAP = {[nil, false] => [ 0, 0, 0 ],
693
+ [nil, true ] => [-1.5, -1.5, -1.5],
694
+ [true, false] => [+0.5, -0.5, -2.5],
695
+ [true, true ] => [-1, -2, -1 ]}
696
+
697
+ # protected
698
+
699
+ # 月初の通日
700
+ #
701
+ # @param [Integer] m 通月
702
+ #
703
+ # @return [Integer] 月初の通日
704
+ #
705
+ def _new_month_(m)
706
+ new_moon_time = @formula[-1].cn_to_time(m)
707
+ new_moon_date = (new_moon_time + 0.5 + @formula[-1].long/360.0).floor
708
+ sunrise_time = @formula[-1].sunrise(new_moon_date)
709
+ (sunrise_time >= new_moon_time) ? new_moon_date : new_moon_date+1
710
+ end
711
+
712
+ # 年初の通月
713
+ #
714
+ # @param [Integer] y 年
715
+ #
716
+ # @return [Integer] 年初の通月
717
+ #
718
+ def _new_year_month_(y)
719
+ (Residue.mod(y-1) {|t| _tithi_to_coordinates(t*15)[0]})[0] + 1
720
+ end
721
+
722
+ # 朔望日 -> 年・月・日
723
+ #
724
+ # tithi : 朔望日(月の位相 / (CIRCLE/30))
725
+ #
726
+ # @return [Array<Numeric>] ( y, m, d )
727
+ # [ y - 年(Integer) ]
728
+ # [ m - 月(When::Coordinates::Pair) ]
729
+ # [ d - (Integer) ]
730
+ #
731
+ def _tithi_to_coordinates(tithi)
732
+ m, d = tithi.divmod(30)
733
+ s = [0,1,2].map {|i| (@formula[1].time_to_cn(30*(m+i)) - @cycle_offset).floor + 1 }
734
+ f = s[0]==s[1]
735
+ if (d >= 15.0)
736
+ d -= 15
737
+ b = true
738
+ n = true unless @hindu_style==0
739
+ f = s[1]==s[2] if @hindu_style==1
740
+ end
741
+ y, m = (n ? s[1] : s[0]).divmod(12)
742
+ return [y, Pair._force_pair(m+1, LEAP_MAP[[b,f]][@hindu_style]), d.floor]
743
+ end
744
+
745
+ # 日時要素の翻訳表の取得
746
+ #
747
+ # @overload _ids_(date)
748
+ # @param [Array<Numeric>] date ()
749
+ # @return [Array<When::Coordinates::Pair>] 1年の月の配置の翻訳表
750
+ #
751
+ # @overload _ids_(date)
752
+ # @param [Array<Numeric>] date ( 年 月 )
753
+ # @return [Array<When::Coordinates::Pair>] 1月の日の配置の翻訳表
754
+ # @note 月は 0 始まりの通番
755
+ #
756
+ def _ids_(date)
757
+ y, m = date
758
+ y = +y
759
+ mm = _new_year_month(y)
760
+ return (_table(_new_month_(mm+m.to_i)) {|i| _new_month(mm+m+i/15.0)}) if m
761
+ table = (0...26).to_a.map {|i| _tithi_to_coordinates((mm+i)*15)[1]}
762
+ table.pop while table[-1].trunk < 11
763
+ return table
764
+ end
765
+
766
+ private
767
+
768
+ # 日時要素の翻訳表の作成
769
+ def _table(b0)
770
+ table = [Pair._force_pair(0,0)]
771
+ (1..16).each do |i|
772
+ b1 = yield(i)
773
+ case b1-b0
774
+ when 0 ; table[-1] = Pair._force_pair(i-1, -2)
775
+ when 1 ; table << Pair._force_pair(i, 0)
776
+ when 2 ; table << Pair._force_pair(i, 0) << Pair._force_pair(i, 1)
777
+ else ; raise ArgumentError, "Irregal date span: #{b1-b0}"
778
+ end
779
+ b0 = b1
780
+ end
781
+ table.pop while table[-1].trunk >= 16
782
+ table.shift
783
+ return table
784
+ end
785
+
786
+ # オブジェクトの正規化
787
+ #
788
+ # @formula = 位相の計算に用いる太陽・変換・月の Formula
789
+ # @cycle_offset = 位相のオフセット
790
+ # @hindu_style = 閏月の表現方法
791
+ # @start_month = 暦年の最初の月
792
+ #
793
+ def _normalize(args=[], options={})
794
+ @label ||= 'Indian::HinduLuniSolar'
795
+ @type ||= 'SBSA'
796
+ raise ArgumentError, "Irregal formula: #{@formula}" unless @type.upcase =~ /\A(M|SS|SB)(V|S|B|H|VZ|SZ|BZ|HZ)(A|P|PX)\z/
797
+
798
+ @location ||= Location_E[$2] || Location_F[$1]
799
+ @cycle_offset ||= CycleOffset[$1]
800
+ @origin_of_MSC ||= -YearEpoch[$2]
801
+ @hindu_style ||= HinduStyle[$3]
802
+ @diff_to_CE ||= 0
803
+ @start_month ||= 5 # Chaitra
804
+ @start_month = @start_month.to_i
805
+ @cycle_offset = @cycle_offset.to_f + (@start_month - 5)
806
+ @hindu_style = @hindu_style.to_i
807
+ @origin_of_MSC = @origin_of_MSC.to_i
808
+ formula = @formula || Formula[$1]
809
+ if formula.kind_of?(String)
810
+ formula += (formula =~ /\?/) ? '&' : '?'
811
+ @formula = When.Resource(["_ep:#{formula}formula=12S",
812
+ "_ep:#{formula}formula=30L->12S",
813
+ "_ep:#{formula}location=(#{@location})&formula=2L"])
814
+ end
815
+ intercalary_month = When.Resource('_m:Indian::IntercalaryMonth::*')
816
+ intercalary_day = When.Resource('_m:Indian::IntercalaryDay::*')
817
+ @indices ||= [
818
+ When.Index('Indian::LunarMonth', {:branch=>{-2.5 => intercalary_month[1], # 黒分
819
+ -2 => intercalary_month[3], # 閏黒分
820
+ -1.5 => intercalary_month[2], # 閏白分
821
+ -1 => intercalary_month[3], # 閏黒分
822
+ -0.5 => intercalary_month[1], # 黒分
823
+ 0 => intercalary_month[0], # 白分
824
+ +0.5 => intercalary_month[1]}, # 黒分
825
+ :shift=>@start_month-1}),
826
+ When.Index({:branch=>{-2=>intercalary_day[0], +1=>intercalary_day[1]}})
827
+ ]
828
+
829
+ super
830
+ end
831
+ end
832
+ end
833
+
834
+ class CalendarNote
835
+ #
836
+ # ヒンドゥー系の暦注
837
+ #
838
+ class HinduNote < self
839
+
840
+ Notes = [When::BasicTypes::M17n, [
841
+ "locale:[=en:, ja=ja:, hi=hi:, alias]",
842
+ "names:[Hindu]",
843
+
844
+ # 年の暦注 ----------------------------
845
+ [When::BasicTypes::M17n,
846
+ "names:[note for year=, 年の暦注=, *alias:year]",
847
+ [When::BasicTypes::M17n,
848
+ "names:[samvatsara, 木星年=]",
849
+ "[Prabhava=, プラバヴァ=, _IAST_=]", # 1
850
+ "[Vibhava=, ヴィバヴァ=, _IAST_=]", # 2
851
+ "[Sukha=, スカ=, _IAST_=]", # 3
852
+ "[Pramoda=, プラモーダ=, _IAST_=]", # 4
853
+ "[Prajāpati=, プラジャーパティ=, _IAST_=]", # 5
854
+ "[Aṅgiras=, アンギラス=, _IAST_=]", # 6
855
+ "[Śrīmukha=, シュリームカ=, _IAST_=]", # 7
856
+ "[Bhāva=, バーヴァ=, _IAST_=]", # 8
857
+ "[Yuvan=, ユヴァン=, _IAST_=]", # 9
858
+ "[Dhātṛ=, ダートリ=, _IAST_=]", # 10
859
+ "[Īśvara=, イーシュヴァラ=, _IAST_=]", # 11
860
+ "[Bahudhānya=, バフダーニャ=, _IAST_=]", # 12
861
+ "[Pramāthin=, プラマーティン=, _IAST_=]", # 13
862
+ "[Vikrama=, ヴィクラマ=, _IAST_=]", # 14
863
+ "[Vṛṣa=, ヴリシャ=, _IAST_=]", # 15
864
+ "[Chitrabhānu=, チトラバーヌ=, _IAST_=]", # 16
865
+ "[Subhānu=, スバーヌ=, _IAST_=]", # 17
866
+ "[Tāraṇa=, ターラナ=, _IAST_=]", # 18
867
+ "[Pārthiva=, パールティヴァ=, _IAST_=]", # 19
868
+ "[Vyaya=, ヴヤヤ=, _IAST_=]", # 20
869
+ "[Sarvajit=, サルヴァジト=, _IAST_=]", # 21
870
+ "[Sarvadhārin=, サルヴァダーリン=, _IAST_=]", # 22
871
+ "[Virodhin=, ヴィローディン=, _IAST_=]", # 23
872
+ "[Vikṛta=, ヴィクリタ=, _IAST_=]", # 24
873
+ "[Khara=, カラ=, _IAST_=]", # 25
874
+ "[Nandana=, ナンダナ=, _IAST_=]", # 26
875
+ "[Vijaya=, ヴィジャヤ=, _IAST_=]", # 27
876
+ "[Jaya=, ジャヤ=, _IAST_=]", # 28
877
+ "[Manmatha=, マンマタ=, _IAST_=]", # 29
878
+ "[Durmukha=, ドゥルムカ=, _IAST_=]", # 30
879
+ "[Hemalamba=, ヘマラムバ=, _IAST_=]", # 31
880
+ "[Vilambin=, ヴィラムビン=, _IAST_=]", # 32
881
+ "[Vikārin=, ヴィカーリン=, _IAST_=]", # 33
882
+ "[Śārvarin=, シャールヴァリン=, _IAST_=]", # 34
883
+ "[Plava=, プラヴァ=, _IAST_=]", # 35
884
+ "[Śubhakṛt=, シュバクリト=, _IAST_=]", # 36
885
+ "[Śobhana=, ショバナ=, _IAST_=]", # 37
886
+ "[Krodhin=, クロディン=, _IAST_=]", # 38
887
+ "[Viśvāvasu=, ヴィシュヴァーヴァス=, _IAST_=]", # 39
888
+ "[Parābhava=, パラーバヴァ=, _IAST_=]", # 40
889
+ "[Plavaṅga=, プラヴァンガ=, _IAST_=]", # 41
890
+ "[Kīlaka=, キーラカ=, _IAST_=]", # 42
891
+ "[Saumya=, サウムヤ=, _IAST_=]", # 43
892
+ "[Sādhāraṇa=, サーダーラナ=, _IAST_=]", # 44
893
+ "[Virodhakṛt=, ヴィローダクリト=, _IAST_=]", # 45
894
+ "[Paridhāvin=, パリダーヴィン=, _IAST_=]", # 46
895
+ "[Pramādin=, プラマーディン=, _IAST_=]", # 47
896
+ "[Ānanda=, アーナンダ=, _IAST_=]", # 48
897
+ "[Rākṣasa=, ラークシャサ=, _IAST_=]", # 49
898
+ "[Anala=, アナラ=, _IAST_=]", # 50
899
+ "[Piṅgala=, ピンガラ=, _IAST_=]", # 51
900
+ "[Kālayukta=, カーラユクタ=, _IAST_=]", # 52
901
+ "[Siddhārthin=, シッダールティン=, _IAST_=]", # 53
902
+ "[Raudra=, ラウドラ=, _IAST_=]", # 54
903
+ "[Durmati=, ドゥルマティ=, _IAST_=]", # 55
904
+ "[Dundubhi=, ドゥンドゥビ=, _IAST_=]", # 56
905
+ "[Rudhirodgārin=, ルディロードガーリン=, _IAST_=]", # 57
906
+ "[Raktākṣin=, ラクタークシン=, _IAST_=]", # 58
907
+ "[Krodhana=, クローダナ=, _IAST_=]", # 59
908
+ "[Kṣaya=, クシャヤ=, _IAST_=]" # 60
909
+ ]
910
+ ],
911
+
912
+ # 月の暦注 ----------------------------
913
+ [When::BasicTypes::M17n,
914
+ "names:note for month=, 月の暦注=, *alias:month]",
915
+ [When::BasicTypes::M17n,
916
+ "names:[month name=en:Month, 月の名前=ja:%%<月_(暦)>, zh:該月的名稱=, *alias:Month=]"
917
+ ]
918
+ ],
919
+
920
+ # 日の暦注 ----------------------------
921
+ [When::BasicTypes::M17n,
922
+ "names:[note for day=, 日の暦注=, *alias:day]",
923
+
924
+ [When::BasicTypes::M17n,
925
+ "names:[tithi=, ティティ=ja:%%<ティティ>, तिथियाँ]",
926
+ "[Amavasya, 新月, _IAST_=]", # 新月
927
+ "[Pratipad=en:Prathama_(day), 1日=, _IAST_=]", # 1
928
+ "[Dwitiya, 2日=, _IAST_=]", # 2
929
+ "[Tritiya, 3日=, _IAST_=]", # 3
930
+ "[Chaturthi, 4日=, _IAST_=]", # 4
931
+ "[Panchami, 5日=, _IAST_=]", # 5
932
+ "[Ṣaṣṭhī=en:Shashti, 6日=, _IAST_=]", # 6
933
+ "[Saptami, 7日=, _IAST_=]", # 7
934
+ "[Ashtami, 8日=, _IAST_=]", # 8
935
+ "[Navami, 9日=, _IAST_=]", # 9
936
+ "[Dashami, 10日=, _IAST_=]", # 10
937
+ "[Ekadashi, 11日=, _IAST_=]", # 11
938
+ "[Dwadashi, 12日=, _IAST_=]", # 12
939
+ "[Thrayodashi, 13日=, _IAST_=]", # 13
940
+ "[Chaturdashi, 14日=, _IAST_=]", # 14
941
+ "[Purnima, 満月, _IAST_=]" # 満月
942
+ ],
943
+
944
+ [When::BasicTypes::M17n,
945
+ "names:[vāra=, ヴァーラ=, _IAST_=, *vara=]",
946
+ "[Ravi=en:S%C5%ABrya, 日曜日, _IAST_=]",
947
+ "[Soma, 月曜日, _IAST_=]",
948
+ "[Maṅgala=en:Mangala, 火曜日, _IAST_=]",
949
+ "[Budha, 水曜日, _IAST_=]",
950
+ "[Guru, 木曜日, _IAST_=]",
951
+ "[Śukra=en:Shukra, 金曜日, _IAST_=]",
952
+ "[Śani=en:Shani, 土曜日, _IAST_=]"
953
+ ],
954
+
955
+ [When::BasicTypes::M17n,
956
+ "names:[nakṣatra=, ナクシャトラ=, _IAST_=, *naksatra=]",
957
+ "[Aśvinī=en:Ashvin%C4%AB, アシュヴィニー=, _IAST_=, 婁宿]", # 1
958
+ "[Bharaṇī=en:Bharan%C4%AB, バラニー=, _IAST_=, 胃宿]", # 2
959
+ "[Kṛttikā=en:Krittik%C4%81, クリッティカー=, _IAST_=, 昴宿]", # 3
960
+ "[Rohiṇī=en:Rohini_(nakshatra), ローヒニ―=, _IAST_=, 畢宿]", # 4
961
+ "[Mṛgaśiras=en:Mrigash%C4%ABrsha, ムリガシラス=, _IAST_=, 觜宿]", # 5
962
+ "[Ārdrā=en:Ardra_(nakshatra), アールドラー=, _IAST_=, 參宿]", # 6
963
+ "[Punarvasu=en:Punarvasu, プナルヴァス=, _IAST_=, 井宿]", # 7
964
+ "[Puṣya=en:Pushya, プシュヤ=, _IAST_=, 鬼宿]", # 8
965
+ "[Aśleṣā=en:%C4%80shlesh%C4%81, アーシュレーシャー=, _IAST_=, 柳宿]", # 9
966
+ "[Maghā=en:Magh%C4%81, マガー=, _IAST_=, 星宿]", # 10
967
+ "[Pū. Phalguṇī=en:P%C5%ABrva_Phalgun%C4%AB, P. パールグニー=, _IAST_=, 張宿]", # 11
968
+ "[U. Phalguṇī=en:Uttara_Phalgun%C4%AB, U. パールグニー=, _IAST_=, 翼宿]", # 12
969
+ "[Hasta=en:Nakshatra#Divisions, ハスタ=, _IAST_=, 軫宿]", # 13
970
+ "[Citrā=en:Nakshatra#Divisions, チトラー=, _IAST_=, 角宿]", # 14
971
+ "[Svāti=en:Sv%C4%81t%C4%AB, スヴァーティー=, _IAST_=, 亢宿]", # 15
972
+ "[Viśākha=en:Vish%C4%81kh%C4%81, ヴィシャーカー=, _IAST_=, 氐宿]", # 16
973
+ "[Anurādhā=en:Anur%C4%81dh%C4%81, アヌラーダー=, _IAST_=, 房宿]", # 17
974
+ "[Jyeṣṭha=en:Jyeshtha, ジェーシュター=, _IAST_=, 心宿]", # 18
975
+ "[Mūla=en:Mula_(astrology), ムーラ=, _IAST_=, 尾宿]", # 19
976
+ "[Pū. āṣāḍha=en:P%C5%ABrva_Ash%C4%81dh%C4%81, P. アーシャーダー=, _IAST_=, 箕宿]", # 20
977
+ "[U. āṣāḍha=en:Uttara_Ash%C4%81dh%C4%81, U. アーシャーダー=, _IAST_=, 斗宿]", # 21
978
+ "[Śravaṇa=en:Shravana, シュラヴァナ=, _IAST_=, 女宿]", # 22
979
+ "[Śraviṣṭhā=en:Dhanishta, ダニシュター=, _IAST_=, 虛宿]", # 23
980
+ "[Śatabhiṣak=en:Shatabhish%C4%81, シャタビシャジュ=, _IAST_=, 危宿]", # 24
981
+ "[Pū. Bhādrapadā=en:P%C5%ABrva_Bh%C4%81drapad%C4%81,P. バードラパダー=, _IAST_=, 室宿]", # 25
982
+ "[U. Bhādrapadā=en:Uttara_Bh%C4%81drapad%C4%81, U. バードラパダー=, _IAST_=, 壁宿]", # 26
983
+ "[Revatī=en:Revati_(nakshatra), レーヴァティー=, _IAST_=, 奎宿]" # 27
984
+ ],
985
+
986
+ [When::BasicTypes::M17n,
987
+ "names:[yoga=, ヨーガ=, _IAST_=]",
988
+ "[Viṣkambha=, ヴィシュカムバ=, _IAST_=]", # 1
989
+ "[Prīti=, プリーティ=, _IAST_=]", # 2
990
+ "[Āyuśmān=, アーユシュマー=, _IAST_=]", # 3
991
+ "[Saubhāgya=, サウバーギャ=, _IAST_=]", # 4
992
+ "[Śobhana=, ショーバナ=, _IAST_=]", # 5
993
+ "[Atigaṇḍa=, アティガンダ=, _IAST_=]", # 6
994
+ "[Sukarma=, スカルマ=, _IAST_=]", # 7
995
+ "[Dhṛti=, ドゥリティ=, _IAST_=]", # 8
996
+ "[Śūla=, シューラ=, _IAST_=]", # 9
997
+ "[Gaṇḍa=, ガンダ=, _IAST_=]", # 10
998
+ "[Vṛddhi=, ヴリッディ=, _IAST_=]", # 11
999
+ "[Dhruva=, ドルヴァ=, _IAST_=]", # 12
1000
+ "[Vyāghāta=, ヴヤーガータ=, _IAST_=]", # 13
1001
+ "[Harṣaṇa=, ハルシャナ=, _IAST_=]", # 14
1002
+ "[Vajra=, ヴァジュラ=, _IAST_=]", # 15
1003
+ "[Siddhi=, シッディ=, _IAST_=]", # 16
1004
+ "[Vyatīpāta=, ヴヤティーパータ=, _IAST_=]", # 17
1005
+ "[Varīyas=, ヴァリーヤス=, _IAST_=]", # 18
1006
+ "[Parigha=, パリガ=, _IAST_=]", # 19
1007
+ "[Śiva=, シヴァ=, _IAST_=]", # 20
1008
+ "[Siddha=, シッダ=, _IAST_=]", # 21
1009
+ "[Sādhya=, サーディヤ=, _IAST_=]", # 22
1010
+ "[Śubha=, シュバ=, _IAST_=]", # 23
1011
+ "[Śukla=, シュクラ=, _IAST_=]", # 24
1012
+ "[Brahman=, ブラフマン=, _IAST_=]", # 25
1013
+ "[Māhendra=, マーヘンドラ=, _IAST_=]", # 26
1014
+ "[Vaidhṛti=, ヴァイドリティ=, _IAST_=]" # 27
1015
+ ],
1016
+
1017
+ [When::BasicTypes::M17n,
1018
+ "names:[Karaṇa=, カラナ=, _IAST_=, *karana]",
1019
+ "[Bava=, バヴァ=, _IAST_=]", # 1
1020
+ "[Bālava=, バーラヴァ=, _IAST_=]", # 2
1021
+ "[Kaulava=, カウラヴァ=, _IAST_=]", # 3
1022
+ "[Taitila=, タイティラ=, _IAST_=]", # 4
1023
+ "[Gara=, ガラ=, _IAST_=]", # 5
1024
+ "[Vaṇija=, ヴァニジュ=, _IAST_=]", # 6
1025
+ "[Viṣṭi=, ヴィシュティ=, _IAST_=]", # 7
1026
+ "[Kiṃtughna=, キンストゥグナ=, _IAST_=]", # A
1027
+ "[Śakuni=, シャクニ=, _IAST_=]", # B
1028
+ "[Catuṣpāda=, チャトシュパダ=, _IAST_=]", # C
1029
+ "[Nāga=, ナーガ=, _IAST_=]" # D
1030
+ ]
1031
+ ]
1032
+ ]]
1033
+
1034
+ NoteConsts = {
1035
+ 'tithi' => {
1036
+ :formula => 15,
1037
+ :range => (-1..2),
1038
+ :index => [ 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,
1039
+ 15,1,2,3,4,5,6,7,8,9,10,11,12,13,14]
1040
+ },
1041
+ 'naksatra' => {
1042
+ :formula => '27M',
1043
+ :range => (-1..2),
1044
+ :index => (0...27).to_a
1045
+ },
1046
+ 'yoga' => {
1047
+ :formula => '27M+27S',
1048
+ :range => (-1..2),
1049
+ :index => (0...27).to_a
1050
+ },
1051
+ 'karana' => {
1052
+ :formula => 30,
1053
+ :range => (-2..3),
1054
+ :index => [7] + (0...7).to_a * 8 + [8,9,10]
1055
+ }
1056
+ }
1057
+
1058
+ #
1059
+ # pancanga 計算に必要となる情報をまとめた内部クラス
1060
+ #
1061
+ class Dates
1062
+
1063
+ # @private
1064
+ attr_reader :o_date, :l_date, :root, :formula, :iri, :rises
1065
+
1066
+ # 初期設定
1067
+ # @private
1068
+ def initialize(date)
1069
+ @o_date = date
1070
+ clock = date.clock
1071
+ frame = date.frame if date.frame.kind_of?(When::CalendarTypes::HinduLuniSolar)
1072
+ @l_date = (frame || When.Calendar('HinduLuniSolar?note=HinduNote')).jul_trans(date.to_i, {:clock=>'+05:30'})
1073
+ @root = When.CalendarNote('HinduNote/Notes')['day']
1074
+ @formula = @l_date.frame.formula[-1]
1075
+ @iri = @formula.iri
1076
+ @rises = [@formula.sunrise(@l_date), @formula.sunrise(@l_date+When.Duration('P1D'))]
1077
+ end
1078
+
1079
+ # その他のメソッドは @l_date に移譲する
1080
+ def method_missing(name, *args, &block)
1081
+ self.class.module_eval %Q{
1082
+ def #{name}(*args, &block)
1083
+ @l_date.send("#{name}", *args, &block)
1084
+ end
1085
+ } unless When::Parts::MethodCash.escape(name)
1086
+ @l_date.send(name, *args, &block)
1087
+ end
1088
+ end
1089
+
1090
+ #
1091
+ # 任意の暦をインド太陰太陽暦日に変換
1092
+ # @private
1093
+ def _to_date_for_note(date)
1094
+ Dates.new(date)
1095
+ end
1096
+
1097
+ #
1098
+ # 木星年
1099
+ #
1100
+ # @param [Dates] dates
1101
+ #
1102
+ # @return [When::BasicTypes::M17n] 木星年の名称
1103
+ #
1104
+ # see {http://en.wikipedia.org/wiki/Samvatsara Samvatsara}
1105
+ #
1106
+ def samvatsara(dates)
1107
+ year_kali = dates.l_date.most_significant_coordinate + dates.l_date.frame.epoch_in_CE + 3101
1108
+ year_mod = year_kali >= jovian ? (year_kali + 12) % 60 :
1109
+ ((year_kali * 211 - 108).div(18000) + year_kali + 26) % 60
1110
+ When.CalendarNote('HinduNote/Notes')['year']['samvatsara'][year_mod]
1111
+ end
1112
+
1113
+ #
1114
+ # 木星年の計算方式に“South”を適用開始する年
1115
+ #
1116
+ # @return [Integer] (カリユガ紀元)
1117
+ #
1118
+ def jovian
1119
+ return @jovian if @jovian.kind_of?(Integer)
1120
+ @jovian = @jovian ? @jovian.to_i : 4009
1121
+ end
1122
+
1123
+ #
1124
+ # ヴァーラ (七曜)
1125
+ #
1126
+ # @param [Dates] dates
1127
+ #
1128
+ # @return [Array<When::TM::TemporalPosition>] 日の出の時刻をイベント時刻とする
1129
+ #
1130
+ def vara(dates)
1131
+ rise = dates.rises[0]
1132
+ rise.events = [dates.root['vara'][(rise.to_i+1) % 7]]
1133
+ ['V:-', rise]
1134
+ end
1135
+
1136
+ #
1137
+ # ヴァーラ以外
1138
+ #
1139
+
1140
+ # 当該日付中でティティが変わる日時
1141
+ # @method tithi(dates)
1142
+ # @param [Dates] dates
1143
+ # @return [Array<When::TM::TemporalPosition>] イベント日時
1144
+
1145
+ # 当該日付中でナクシャトラが変わる日時
1146
+ # @method naksatra(dates)
1147
+ # @param [Dates] dates
1148
+ # @return [Array<When::TM::TemporalPosition>] イベント日時
1149
+
1150
+ # 当該日付中でヨーガが変わる日時
1151
+ # @method yoga(dates)
1152
+ # @param [Dates] dates
1153
+ # @return [Array<When::TM::TemporalPosition>] イベント日時
1154
+
1155
+ # 当該日付中でカラナが変わる日時
1156
+ # @method karana(dates)
1157
+ # @param [Dates] dates
1158
+ # @return [Array<When::TM::TemporalPosition>] イベント日時
1159
+ #
1160
+
1161
+ # @private
1162
+ NoteConsts.keys.each do |key|
1163
+ module_eval %Q{
1164
+ def #{key}(dates)
1165
+ pancanga(dates, '#{key}').map {|event| ['#{key[0..0].upcase}:-', event]}
1166
+ end
1167
+ }
1168
+ end
1169
+
1170
+ #
1171
+ # ヴァーラ以外のイベント日時
1172
+ #
1173
+ # @param [Dates] dates
1174
+ # @param [String] key 'tithi', 'naksatra', 'yoga', 'karana' のいずれか
1175
+ # @return [Array<When::TM::TemporalPosition>] イベント日時
1176
+ #
1177
+ def pancanga(dates, key)
1178
+ pattern = NoteConsts[key]
1179
+ note = dates.root[key]
1180
+ if pattern[:formula].kind_of?(Numeric)
1181
+ factor = pattern[:formula].to_f
1182
+ formula = dates.formula
1183
+ else
1184
+ factor = 1.0
1185
+ formula = When.Resource(dates.iri.sub(/formula=2L/, "formula=#{pattern[:formula]}"))
1186
+ end
1187
+ cn = (formula.time_to_cn(dates.l_date) * factor).floor
1188
+ events = []
1189
+ pattern[:range].each do |i|
1190
+ event = formula._to_seed_type(formula.cn_to_time((cn+i)/factor), dates.l_date)
1191
+ break if +event >= +dates.rises[1]
1192
+ next if +event < +dates.rises[0]
1193
+ event.events = [note[pattern[:index][(cn+i) % pattern[:index].length]]]
1194
+ events << event
1195
+ end
1196
+ events
1197
+ end
1198
+ end
1199
+
1200
+ #
1201
+ # 日の出の九惑星の位置まで計算
1202
+ #
1203
+ class HinduNoteDetailed < HinduNote
1204
+
1205
+ Notes = HinduNote::Notes
1206
+
1207
+ #
1208
+ # ヴァーラ (七曜)と九惑星の位置
1209
+ #
1210
+ # @param [Dates] dates
1211
+ # @return [Array<When::TM::TemporalPosition, Hash{ 惑星シンボル=>惑星の真黄経 }>]
1212
+ # 日の出の時刻をイベント時刻とし、その時刻での九惑星の位置を計算
1213
+ #
1214
+ def vara(dates)
1215
+ rise = dates.rises[0]
1216
+ rise.events = [dates.root['vara'][(rise.to_i+1) % 7]]
1217
+ t = dates.formula.is_dynamical ? +rise : rise.to_f
1218
+ [['V:-', rise], dates.formula.graha.keys.inject({}) {|h,p|
1219
+ h.store(p, dates.formula.graha[p].true_longitude(t))
1220
+ h
1221
+ }]
1222
+ end
1223
+ end
1224
+ end
1225
+ end