/
indian.rb
1268 lines (1153 loc) · 50.3 KB
/
indian.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
=begin
Copyright (C) 2011-2014 Takashi SUGA
You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
=end
module When
module Parts::Locale
#
# IAST: International Alphabet of Sanskrit Transliteration
#
IAST = {
'hi' => {
"A" => "अ", "a" => "अ",
"Ā" => "आ", "ā" => "आ",
"I" => "इ", "i" => "इ",
"Ī" => "ई", "ī" => "ई",
"U" => "उ", "u" => "उ",
"Ū" => "ऊ", "ū" => "ऊ",
"Ṛ" => "ऋ", "ṛ" => "ऋ",
"Ṝ" => "ॠ", "ṝ" => "ॠ",
"Ḷ" => "ऌ", "ḷ" => "ऌ",
"Ḹ" => "ॡ", "ḹ" => "ॡ",
"E" => "ए", "e" => "ए",
"Ai" => "ऐ", "ai" => "ऐ",
"O" => "ओ", "o" => "ओ",
"Au" => "औ", "au" => "औ",
"Ṃ" => "अं", "ṃ" => "अं",
"Ḥ" => "अः", "ḥ" => "अः",
"'" => "अऽ",
"K" => "क", "k" => "क",
"C" => "च", "c" => "च",
"Ṭ" => "ट", "ṭ" => "ट",
"T" => "त", "t" => "त",
"P" => "प", "p" => "प",
"Kh" => "ख", "kh" => "ख",
"Ch" => "छ", "ch" => "छ",
"Ṭh" => "ठ", "ṭh" => "ठ",
"Th" => "थ", "th" => "थ",
"Ph" => "फ", "ph" => "फ",
"G" => "ग", "g" => "ग",
"J" => "ज", "j" => "ज",
"Ḍ" => "ड", "ḍ" => "ड",
"D" => "द", "d" => "द",
"B" => "ब", "b" => "ब",
"Gh" => "घ", "gh" => "घ",
"Jh" => "झ", "jh" => "झ",
"Ḍh" => "ढ", "ḍh" => "ढ",
"Dh" => "ध", "dh" => "ध",
"Bh" => "भ", "bh" => "भ",
"Ṅ" => "ङ", "ṅ" => "ङ",
"Ñ" => "ञ", "ñ" => "ञ",
"Ṇ" => "ण", "ṇ" => "ण",
"N" => "न", "n" => "न",
"M" => "म", "m" => "म",
"H" => "ह", "h" => "ह",
"Y" => "य", "y" => "य",
"R" => "र", "r" => "र",
"L" => "ल", "l" => "ल",
"V" => "व", "v" => "व",
"Ś" => "श", "ś" => "श",
"Ṣ" => "ष", "ṣ" => "ष",
"S" => "स", "s" => "स"
},
'ja' => {
"Ā" => "A-", "ā" => "a-",
"Ī" => "I-", "ī" => "i-",
"Ū" => "U-", "ū" => "u-",
"E" => "e-", "e" => "e-",
"O" => "O-", "o" => "o-",
"Ṛ" => "R", "ṛ" => "r",
"Ṝ" => "R", "ṝ" => "r",
"Ḷ" => "L", "ḷ" => "l",
"Ḹ" => "L", "ḹ" => "l",
"Ṃ" => "M", "ṃ" => "m",
"Ḥ" => "H", "ḥ" => "h",
"C" => "Ch", "c" => "ch",
"Ṭ" => "T", "ṭ" => "t",
"Kh" => "K", "kh" => "k",
"Ch" => "Ch", "ch" => "ch",
"Ṭh" => "T", "ṭh" => "t",
"Th" => "T", "th" => "t",
"Ph" => "P", "ph" => "p",
"Ḍ" => "D", "ḍ" => "d",
"Gh" => "G", "gh" => "g",
"Jh" => "J", "jh" => "j",
"Ḍh" => "D", "ḍh" => "d",
"Dh" => "D", "dh" => "d",
"Bh" => "B", "bh" => "b",
"Ṅ" => "N", "ṅ" => "n",
"Ñ" => "Ny", "ñ" => "ny",
"Ṇ" => "N", "ṇ" => "n",
"Ś" => "Sh", "ś" => "sh",
"Ṣ" => "Sh", "ṣ" => "sh",
}
}
# @private
IAST_keys = Hash[*(IAST.keys.map {|locale|
[locale, Regexp.new((IAST[locale].keys.sort_by {|key| -key.length} + ['%.*?[A-Za-z]']).join('|'))]
}).flatten]
#
# Convert IAST string to indic scripts
#
# @private
def self.iast(string, locale)
string.gsub(IAST_keys[locale]) {|code|
IAST[locale][code] || code
}
end
end
class BasicTypes::M17n
IndianTerms = [self, [
"namespace:[en=http://en.wikipedia.org/wiki/, ja=http://ja.wikipedia.org/wiki/, hi=http://hi.wikipedia.org/wiki/]",
"locale:[=en:, ja=ja:, hi=hi:, alias]",
"names:[IndianTerms=]",
"[IndianNationalSolar=en:Indian_national_calendar, インド国定暦]",
"[HinduSolar=en:Hindu_calendar, インド太陽暦=ja:%%<ヒンドゥー暦>]",
"[HinduLuniSolar=en:Hindu_calendar, インド太陰太陽暦=ja:%%<ヒンドゥー暦>]",
[self,
"names:[IntercalaryMonth=en:Intercalation, 閏月]",
"[%s Śuklapakṣa=, %s 白分=, _IAST_]",
"[%s Kṛṣṇapakṣa=, %s 黒分=, _IAST_]",
"[adhika %s Śuklapakṣa=, 閏%s 白分=, _IAST_]",
"[adhika %s Kṛṣṇapakṣa=, 閏%s 黒分=, _IAST_]"
],
[self,
"names:[IntercalaryDay=en:Intercalation, 閏日=ja:%%<閏>]",
"[Double %s=, 欠= ]",
"[Intercalary %s=, 重= ]"
],
[self,
"names:[LunarMonth=, 太陰月=ja:%%<月_(暦)>]",
"[Mārgaśīra=en:Margashirsha, マールガシールシャ=, _IAST_]",
"[Pauṣa=en:Pausha, パウシャ=, _IAST_]",
"[Māgha=en:Maagha, マーガ=, _IAST_]",
"[Phālguna=en:Phalguna, パールグナ=, _IAST_]",
"[Caitra=en:Chaitra, チャイトラ=, _IAST_]",
"[Vaiśākha=en:Vaisakha, ヴァイシャーカ=, _IAST_]",
"[Jyaiṣṭha=en:Jyeshta, ジャイシュタ=, _IAST_]",
"[Āṣāḍha=en:Aashaadha, アーシャーダ=, _IAST_]",
"[Śrāvaṇa=en:Shraavana, シュラーヴァナ=, _IAST_]",
"[Bhādrapada=en:Bhadrapada, バードラパダ=, _IAST_]",
"[Āśvina=en:Ashwin, アーシュヴィナ=, _IAST_]",
"[Kārttika=en:Kartika_(month), カールッティカ=, _IAST_]"
],
[self,
"names:[SolarMonth=, 太陽月=ja:%%<月_(暦)>]",
"[Maysha=, 白羊宮, _IAST_]",
"[Vrushabha=, 金牛宮, _IAST_]",
"[Mithuna=, 双児宮, _IAST_]",
"[Karka=, 巨蟹宮, _IAST_]",
"[Simha=, 獅子宮, _IAST_]",
"[Kanya=, 処女宮, _IAST_]",
"[Tula=, 天秤宮, _IAST_]",
"[Vrushchika=, 天蝎宮, _IAST_]",
"[Dhanu=, 人馬宮, _IAST_]",
"[Makar=, 磨羯宮, _IAST_]",
"[Kumbha=, 宝瓶宮, _IAST_]",
"[Meena=, 双魚宮, _IAST_]"
]
]]
end
module Coordinates
# Location of cities in India
IndianCities = [When::BasicTypes::M17n, [
"namespace:[en=http://en.wikipedia.org/wiki/, ja=http://ja.wikipedia.org/wiki/]",
"locale:[=en:, ja=ja:, alias]",
"names:[IndianCities]",
[Spatial, "long:+82.5", "lat:N23.11", "label:[CentralIndia, インド中部]" ],
[Spatial, "long:+82.5", "lat:+29.0", "label:[NorthIndia, インド北部]" ],
[Spatial, "long:+78.0", "lat:+27.2", "label:[Agra, アーグラ]" ],
[Spatial, "long:+72.6", "lat:+23.0", "label:[Ahmedabad, アフマダーバード]" ],
[Spatial, "long:+74.6", "lat:+26.5", "label:[Ajmer, アジメール]" ],
[Spatial, "long:+78.1", "lat:+27.9", "label:[Aligarh, アリーガル]" ],
[Spatial, "long:+74.9", "lat:+31.6", "label:[Amritsar, アムリトサル]" ],
[Spatial, "long:+77.6", "lat:+13.0", "label:[Bangalore, バンガロール]" ],
[Spatial, "long:+85.8", "lat:+20.2", "label:[Bhuvaneswar, ブヴァネーシュヴァル]"],
[Spatial, "long:+80.3", "lat:+13.1", "label:[Chennai, チェンナイ, Madras]" ],
[Spatial, "long:+79.9", "lat: +6.9", "label:[Colombo, コロンボ]" ],
[Spatial, "long:+90.4", "lat:+23.7", "label:[Dacca, ダッカ]" ],
[Spatial, "long:+77.2", "lat:+28.6", "label:[Delhi, デリー]" ],
[Spatial, "long:+78.5", "lat:+17.4", "label:[Hyderabad, ハイデラバード]" ],
[Spatial, "long:+75.8", "lat:+26.9", "label:[Jaipur, ジャイプル]" ],
[Spatial, "long:+85.2", "lat:+27.7", "label:[Kathmandu, カトマンズ]" ],
[Spatial, "long:+76.2", "lat:+10.0", "label:[Kochi, コーチ, Cochin]" ],
[Spatial, "long:+88.4", "lat:+22.6", "label:[Kolkata, コルカタ, Calcutta]" ],
[Spatial, "long:+74.3", "lat:+31.6", "label:[Lahor, ラホール]" ],
[Spatial, "long:+77.7", "lat:+27.5", "label:[Mathura, マトゥラー]" ],
[Spatial, "long:+72.8", "lat:+19.0", "label:[Mumbai, ムンバイ, Bombay]" ],
[Spatial, "long:+76.6", "lat:+12.3", "label:[Mysore, マイソール]" ],
[Spatial, "long:+85.1", "lat:+25.6", "label:[Patna, パトナ]" ],
[Spatial, "long:+73.9", "lat:+18.5", "label:[Pune, プネー]" ],
[Spatial, "long:+74.8", "lat:+34.1", "label:[Srinagar, シュリーナガル]" ],
[Spatial, "long:+77.0", "lat: +8.5", "label:[Thiruvananthapuram, ティルヴァナンタプラム, Trivandrum]"],
[Spatial, "long:+83.0", "lat:+25.3", "label:[Varanasi, ワーラーナシー]" ],
[Spatial, "long:+75.8", "lat:+23.2", "label:[Ujjain, ウッジャイン]" ]
]]
end
module Ephemeris
#
# Hindu Luni-Solar Calendar Formula
#
class Hindu < Formula
# Basic Astronomical Constants for Surya-Siddhanta
Tz = 0.5+75.8/360 # time difference between JulianDayNumber and Ujjain
E = 588_466 - Tz # Yuga Epoch -3101-02-18T00:00:00
P = 180 # Precession cycles in yuga
Ep = 1_903_318 - Tz # Precession Epoch 499-01-01
Ob = 24.0 / 360.0 # Obliquity of the ecliptic
Grahas = {
'SS' => { # Previous / Newest
:Star => 1_582_237_800.0, # 1_582_237_500 / 1_582_237_800
:Sun => 4_320_000.0,
:Moon => 57_753_336.0,
:Mercury => 17_937_000.0,
:Venus => 7_022_388.0,
:Mars => 2_296_824.0,
:Jupiter => 364_220.0,
:Saturn => 146_564.0,
:Candrocca => 488_219.0, # 488_203 / 488_219
:Rahu => -232_226.0
},
'SB' => {
:Star => 1_582_237_828.0,
:Sun => 4_320_000.0,
:Moon => 57_753_336.0,
:Mercury => 17_937_060.0,
:Venus => 7_022_376.0,
:Mars => 2_296_832.0,
:Jupiter => 364_220.0,
:Saturn => 146_568.0,
:Candrocca => 488_203.0, # 488_199 / 488_203
:Rahu => -232_238.0
}
}
#
# 日月五惑星とラーフおよびケートゥ
#
# @abstract
class Graha
include When::Ephemeris
end
#
# 現代的“惑星”
#
class ModernGraha < Graha
# 真黄経
#
# @param [Numeric] t ユリウス日
#
# @return [Numeric]
#
def true_longitude(t)
@target.coords(t, @base).phi
end
# オブジェクトの生成
#
# @param [When::Ephemeris::Datum] target 天体
# @param [When::Coordinates::Spatial] base 観測地
#
def initialize(target, base)
@target = target
@base = base
end
end
#
# 古典的“惑星”
#
# @abstract
class ClassicGraha < Graha
# 平均黄経
#
# @param [Numeric] t ユリウス日
#
# @return [Numeric]
#
def mean_longitude(t)
_mean_rotation(t - E)
end
# 真黄経
#
# @param [Numeric] t ユリウス日
#
# @return [Numeric]
#
def true_longitude(t)
_true_rotation(t - E)
end
# 平均黄経
#
# @param [Numeric] ahar カリユガ暦元からの経過日数
#
# @return [Numeric]
#
def _mean_rotation(ahar)
@rotation * ahar / @formula.civil_days
end
# オブジェクトの生成
#
# @param [When::Ephemeris::Formula] formula 親オブジェクト
# @param [Numeric] rotation ユガあたりの回転数
#
def initialize(formula, rotation)
@formula = formula
@rotation = rotation
end
end
# 架空の“惑星” - ラーフ / 月軌道の遠地点としてのケートゥ
class VirtualGraha < ClassicGraha
# 平均黄経
#
# @param [Numeric] ahar カリユガ暦元からの経過日数
#
# @return [Numeric]
#
def _mean_rotation(ahar)
super + @rotation0
end
alias :_true_rotation :_mean_rotation
# オブジェクトの生成
#
# @param [When::Ephemeris::Formula] formula 親オブジェクト
# @param [Numeric] rotation ユガあたりの回転数
# @param [Numeric] rotation0 カリユガ暦元での回転量
#
def initialize(formula, rotation, rotation0)
@rotation0 = rotation0 / 360.0
super(formula, rotation)
end
end
# 実在の“惑星”
# @abstract
class RealGraha < ClassicGraha
# マンダ補正
#
# @param [Numeric] rot 平均近点角など / CIRCLE
#
# @return [Numeric]
#
def _manda_equation(rot)
asin(@circumm * sinc(rot)) / CIRCLE
end
# オブジェクトの生成
#
# @param [When::Ephemeris::Formula] formula 親オブジェクト
# @param [Numeric] rotation ユガあたりの回転数
# @param [Numeric] circumm マンダ円の半径
# @param [Numeric] apogee 近点黄経 / CIRCLE
#
def initialize(formula, rotation, circumm, apogee)
@circumm = circumm / 360.0
@apogee = apogee / 360.0
super(formula, rotation)
end
end
# 太陽と月 - 逆行しない“惑星”
# @abstract
class ConcentricGraha < RealGraha
# 平均黄経
#
# @param [Numeric] ahar カリユガ暦元からの経過日数
#
# @return [Numeric]
#
def _mean_rotation(ahar)
super + @epoch
end
# オブジェクトの生成
#
# @param [When::Ephemeris::Formula] formula 親オブジェクト
# @param [Numeric] rotation ユガあたりの回転数
# @param [Numeric] circumm マンダ円の半径
# @param [Numeric] apogee 近点黄経 / CIRCLE
# @param [Numeric] epoch カリユガ暦元での黄経 / CIRCLE
#
def initialize(formula, rotation, circumm, apogee, epoch)
@epoch = epoch
super(formula, rotation, circumm, apogee)
end
end
# 太陽
class Sun < ConcentricGraha
# 真黄経
#
# @param [Numeric] ahar カリユガ暦元からの経過日数
#
# @return [Numeric]
#
def _true_rotation(ahar)
mean = _mean_rotation(ahar)
mean - _manda_equation(mean - @apogee)
end
end
# 月
class Moon < ConcentricGraha
# 真黄経
#
# @param [Numeric] ahar カリユガ暦元からの経過日数
#
# @return [Numeric]
#
def _true_rotation(ahar)
mean = _mean_rotation(ahar)
mean - _manda_equation(mean - @formula.graha[:Candrocca]._mean_rotation(ahar))
end
end
# 惑星 - 逆行するもの
# @abstract
class Planet < RealGraha
# シグラ補正
#
# @param [Numeric] anomaly 平均近点角 / CIRCLE
#
# @return [Numeric]
#
def _sighra_equation(anomaly)
atan2(@circums * sinc(anomaly), @circums * cosc(anomaly) + 1) / CIRCLE
end
# 平均シグラ
#
# @param [Numeric] ahar カリユガ暦元からの経過日数
#
# @return [Numeric]
#
def _mean_sighra(ahar)
@sighra * ahar / @formula.civil_days
end
# 真黄経
#
# @param [Numeric] ahar カリユガ暦元からの経過日数
# @param [Numeric] rotation 基準回転量 / CIRCLE
#
# @return [Numeric]
#
def _true_rotation(ahar, rotation)
# first sighra correction
delta = _sighra_equation(_mean_sighra(ahar) - rotation) / 2
# first manda correction
mean = _mean_rotation(ahar) + delta
delta = _manda_equation(mean - @apogee) / 2
# second manda correction
mean -= delta
delta = _manda_equation(mean - @apogee)
# second sighra correction
mean = _mean_rotation(ahar) - delta
delta = _sighra_equation(_mean_sighra(ahar) - mean)
# true rotation
mean + delta
end
# オブジェクトの生成
#
# @param [When::Ephemeris::Formula] formula 親オブジェクト
# @param [Numeric] rotation ユガあたりの回転数
# @param [Numeric] circumm マンダ円の半径
# @param [Numeric] apogee 近点黄経 / CIRCLE
# @param [Numeric] sighra シグラ対象のカリユガあたりの回転数
# @param [Numeric] circums シグラ円の半径
#
def initialize(formula, rotation, circumm, apogee, sighra, circums)
@sighra = sighra
@circums = circums / 360.0
super(formula, rotation, circumm, apogee)
end
end
# 内惑星 - 水金
class InferiorPlanet < Planet
# 真黄経
#
# @param [Numeric] t ユリウス日
#
# @return [Numeric]
#
def true_longitude(t)
ahar = t - E
_true_rotation(ahar, @formula.graha[:Sun]._mean_rotation(ahar))
end
end
# 外惑星 - 火木土
class SuperiorPlanet < Planet
# 真黄経
#
# @param [Numeric] t ユリウス日
#
# @return [Numeric]
#
def true_longitude(t)
ahar = t - E
_true_rotation(ahar, _mean_rotation(ahar))
end
end
#
# ユガの太陽日数
#
# @return [Numeric]
#
attr_reader :civil_days
# 日の出の日時
#
# @param [Numeric] sdn ユリウス日
# @param [When::TM::TemporalPosition] sdn
# @param [nil] height 太陽高度(本クラスでは使用しない)
#
# @return [Integer, When::TM::DateAndTime] 日の出の日時
#
def sunrise(sdn, height=nil)
t = sdn.to_i - @long / 360.0 - 0.25
p = _mean_sun(t) + P * (t - Ep) / @civil_days
_to_seed_type(t - asin(tand(@lat)*tan(asin(sinc(p)*sinc(Ob)))) / CIRCLE, sdn)
end
# 日の入りの日時
#
# @param [Numeric] sdn ユリウス日
# @param [When::TM::TemporalPosition] sdn
# @param [nil] height 太陽高度(本クラスでは使用しない)
#
# @return [Integer, When::TM::DateAndTime] 日の入りの日時
#
def sunset(sdn, height=nil)
t = sdn.to_i - @long / 360.0 + 0.25
p = _mean_sun(t) + P * (t - Ep) / @civil_days
_to_seed_type(t + asin(tand(@lat)*tan(asin(sinc(p)*sinc(Ob)))) / CIRCLE, sdn)
end
# 太陽の南中の日時
#
# @param [Numeric] sdn ユリウス日
# @param [When::TM::TemporalPosition] sdn
#
# @return [Integer, When::TM::DateAndTime] 太陽の南中の日時
#
def sun_noon(sdn)
_to_seed_type(sdn.to_i - @long / 360.0, sdn)
end
private
# オブジェクトの正規化
def _normalize(args=[], options={})
@time_standard ||= 'universal'
@bija ||= 'SB'
super
end
# 9惑星オブジェクトの生成
def _normalize_grahas
grahas = Grahas[@bija]
# ユガあたりの暦定数
@sidereal_days = grahas[:Star] # 恒星日
@solar_years = grahas[:Sun] # 太陽年
@civil_days = @sidereal_days - @solar_years # 太陽日
@sidereal_months = grahas[:Moon] # 恒星月
@synodic_months = @sidereal_months - @solar_years # 朔望月
@adhimasas = @synodic_months - 12 * @solar_years # 閏月
@tithis = 30 * @sidereal_months # 太陰日
@ksayadinas = @tithis - @civil_days # 欠日
# 9惑星
@graha = {}
@graha.update({
:Sun => Sun.new( self, @solar_years, 13+50/60.0, 77+17/60.0, -3101)
}) if @formula =~ /[SL]/i
@graha.update({
:Moon => Moon.new( self, @sidereal_months, 31+50/60.0, 0, -28086),
:Candrocca => VirtualGraha.new( self, grahas[:Candrocca], 90.0)
}) if @formula =~ /[ML]/i
@graha.update({
:Mercury => InferiorPlanet.new(self, @solar_years, 29.0, 220+27/60.0, grahas[:Mercury], 131.5),
:Venus => InferiorPlanet.new(self, @solar_years, 11.5, 79+50/60.0, grahas[:Venus], 261.0),
:Mars => SuperiorPlanet.new(self, grahas[:Mars], 73.5, 130+02/60.0, @solar_years, 233.5),
:Jupiter => SuperiorPlanet.new(self, grahas[:Jupiter], 32.5, 171+18/60.0, @solar_years, 71.0),
:Saturn => SuperiorPlanet.new(self, grahas[:Saturn], 48.5, 236+37/60.0, @solar_years, 39.5),
:Rahu => VirtualGraha.new( self, grahas[:Rahu], 180.0)
}) if @formula == '2L'
end
end
end
class TM::CalendarEra
IndianNationalSolar = [self, [
"namespace:[en=http://en.wikipedia.org/wiki/, ja=http://ja.wikipedia.org/wiki/]",
"locale:[=en:, ja=ja:, alias]",
"area:[IndianNationalSolar=en:Indian_national_calendar, インド国定暦]",
["[SE=, サカ暦=, alias:Saka_Era]1.1.1", "Calendar Epoch", "79-01-01^IndianNationalSolar"]
]]
end
module CalendarTypes
#
# Indian national solar calendar
#
IndianNationalSolar = [CyclicTableBased, {
'label' => When.Resource('_m:IndianTerms::IndianNationalSolar'),
'origin_of_LSC' => 1721140,
'indices' => [
When::Coordinates::Index.new({:unit =>12, :trunk=>When.Resource('_m:IndianTerms::LunarMonth::*'), :shift=>4}),
When::Coordinates::DefaultDayIndex
],
'rule_table' => {
'T' => {'Rule' =>['LC', 'SC', 'SC', 'SC']},
'SC' => {'Rule' =>[365]*4 + [366, 365, 365, 365]*24},
'LC' => {'Rule' =>[366, 365, 365, 365]*25},
365 => {'Length'=>[30] + [31]*5 + [30]*6},
366 => {'Length'=> [31]*6 + [30]*6}
},
}]
#
# Hindu Solar Calendar
#
class HinduSolar < EphemerisBasedSolar
# protected
# 月初の通日
#
# @param [Integer] m 通月
#
# @return [Integer] 月初の通日
#
def _new_month_(m)
new_month_time = @formula[0].cn_to_time(m + @cycle_offset)
new_month_date = (new_month_time + 0.5 + @formula[0].long/360.0).floor
sunrise_time = @formula[0].sunrise(new_month_date)
(sunrise_time <= new_month_time) ? new_month_date : new_month_date-1
end
private
# オブジェクトの正規化
#
# @formula[0] = 位相の計算に用いる太陽の Formula
# @cycle_offset = 位相のオフセット
# @start_month = 暦年の最初の月
#
def _normalize(args=[], options={})
@label ||= When.Resource('_m:IndianTerms::HinduSolar')
@type ||= 'SBS'
raise ArgumentError, "Irregal formula: #{@formula}" unless @type.upcase =~ /^(M|SS|SB)(V|S|VZ|SZ)$/
@location ||= HinduLuniSolar::Location[$1]
@cycle_offset ||= HinduLuniSolar::CycleOffset[$1]
@origin_of_MSC ||= -HinduLuniSolar::YearEpoch[$2]
@epoch_in_CE ||= 0
@start_month ||= 1 # Maysha
@start_month = @start_month.to_i
@cycle_offset = @cycle_offset.to_f + (@start_month - 1)
formula = @formula || HinduLuniSolar::Formula[$1]
if formula.kind_of?(String)
formula += (formula =~ /\?/) ? '&' : '?'
@formula = [When.Resource("_ep:#{formula}location=(#{@location})&formula=12S")]
end
@indices ||= [
Coordinates::Index.new({:trunk=>When.Resource('_m:IndianTerms::SolarMonth::*'),
:shift=>@start_month-1}),
Coordinates::DefaultDayIndex
]
super
end
end
#
# Hindu Luni-Solar Calendar
#
class HinduLuniSolar < EphemerisBasedLuniSolar
# Calendar Type
Formula = {'M'=>'Formula', 'SS'=>'Hindu?bija=SS', 'SB'=>'Hindu?bija=SB'}
Location = {'M'=>'_co:IndianCities::CentralIndia', 'SS'=>'_co:IndianCities::Ujjain', 'SB'=>'_co:IndianCities::Ujjain'}
CycleOffset = {'M'=>+23.25/30, 'SS'=>0.0, 'SB'=>0.0}
HinduStyle = {'A'=>0, 'P'=>1, 'PX'=>2}
YearEpoch = {'V'=>-58,'VZ'=>-57,'S'=>78, 'SZ'=>79}
# White / black month and leap month identification table
#[w]/b [n]/l #0 #1 #2
LEAP_MAP = {[nil, false] => [ 0, 0, 0 ],
[nil, true ] => [-1.5, -1.5, -1.5],
[true, false] => [+0.5, -0.5, -2.5],
[true, true ] => [-1, -2, -1 ]}
# protected
# 月初の通日
#
# @param [Integer] m 通月
#
# @return [Integer] 月初の通日
#
def _new_month_(m)
new_moon_time = @formula[-1].cn_to_time(m)
new_moon_date = (new_moon_time + 0.5 + @formula[-1].long/360.0).floor
sunrise_time = @formula[-1].sunrise(new_moon_date)
(sunrise_time >= new_moon_time) ? new_moon_date : new_moon_date+1
end
# 年初の通月
#
# @param [Integer] y 年
#
# @return [Integer] 年初の通月
#
def _new_year_month_(y)
(Residue.mod(y-1) {|t| _tithi_to_coordinates(t*15)[0]})[0] + 1
end
# 朔望日 -> 年・月・日
#
# tithi : 朔望日(月の位相 / (CIRCLE/30))
#
# @return [Array<Numeric>] ( y, m, d )
# [ y - 年(Integer) ]
# [ m - 月(When::Coordinates::Pair) ]
# [ d - 日(Integer) ]
#
def _tithi_to_coordinates(tithi)
m, d = tithi.divmod(30)
s = [0,1,2].map {|i| (@formula[1].time_to_cn(30*(m+i)) - @cycle_offset).floor + 1 }
f = s[0]==s[1]
if (d >= 15.0)
d -= 15
b = true
n = true unless @hindu_style==0
f = s[1]==s[2] if @hindu_style==1
end
y, m = (n ? s[1] : s[0]).divmod(12)
return [y, Pair._force_pair(m+1, LEAP_MAP[[b,f]][@hindu_style]), d.floor]
end
# 日時要素の翻訳表の取得
#
# @overload _ids_(date)
# @param [Array<Numeric>] date ( 年 )
# @return [Array<When::Coordinates::Pair>] 1年の月の配置の翻訳表
#
# @overload _ids_(date)
# @param [Array<Numeric>] date ( 年 月 )
# @return [Array<When::Coordinates::Pair>] 1月の日の配置の翻訳表
# @note 月は 0 始まりの通番
#
def _ids_(date)
y, m = date
y = +y
mm = _new_year_month(y)
return (_table(_new_month_(mm+m.to_i)) {|i| _new_month(mm+m+i/15.0)}) if m
table = (0...26).to_a.map {|i| _tithi_to_coordinates((mm+i)*15)[1]}
table.pop while table[-1].trunk < 11
return table
end
private
# 日時要素の翻訳表の作成
def _table(b0)
table = [Pair._force_pair(0,0)]
(1..16).each do |i|
b1 = yield(i)
case b1-b0
when 0 ; table[-1] = Pair._force_pair(i-1, -2)
when 1 ; table << Pair._force_pair(i, 0)
when 2 ; table << Pair._force_pair(i, 0) << Pair._force_pair(i, 1)
else ; raise ArgumentError, "Irregal date span: #{b1-b0}"
end
b0 = b1
end
table.pop while table[-1].trunk >= 16
table.shift
return table
end
# オブジェクトの正規化
#
# @formula = 位相の計算に用いる太陽・変換・月の Formula
# @cycle_offset = 位相のオフセット
# @hindu_style = 閏月の表現方法
# @start_month = 暦年の最初の月
#
def _normalize(args=[], options={})
@label ||= When.Resource('_m:IndianTerms::HinduLuniSolar')
@type ||= 'SBSA'
raise ArgumentError, "Irregal formula: #{@formula}" unless @type.upcase =~ /^(M|SS|SB)(V|S|VZ|SZ)(A|P|PX)$/
@location ||= Location[$1]
@cycle_offset ||= CycleOffset[$1]
@origin_of_MSC ||= -YearEpoch[$2]
@hindu_style ||= HinduStyle[$3]
@epoch_in_CE ||= 0
@start_month ||= 5 # Chaitra
@start_month = @start_month.to_i
@cycle_offset = @cycle_offset.to_f + (@start_month - 5)
@hindu_style = @hindu_style.to_i
@origin_of_MSC = @origin_of_MSC.to_i
formula = @formula || Formula[$1]
if formula.kind_of?(String)
formula += (formula =~ /\?/) ? '&' : '?'
@formula = When.Resource(["_ep:#{formula}formula=12S",
"_ep:#{formula}formula=30L->12S",
"_ep:#{formula}location=(#{@location})&formula=2L"])
end
intercalary_month = When.Resource('_m:IndianTerms::IntercalaryMonth::*')
intercalary_day = When.Resource('_m:IndianTerms::IntercalaryDay::*')
@indices ||= [
Coordinates::Index.new({:branch=>{-2.5 => intercalary_month[1], # 黒分
-2 => intercalary_month[3], # 閏黒分
-1.5 => intercalary_month[2], # 閏白分
-1 => intercalary_month[3], # 閏黒分
-0.5 => intercalary_month[1], # 黒分
0 => intercalary_month[0], # 白分
+0.5 => intercalary_month[1]}, # 黒分
:trunk=>When.Resource('_m:IndianTerms::LunarMonth::*'),
:shift=>@start_month-1}),
Coordinates::Index.new({:branch=>{-2=>intercalary_day[0], -1=>intercalary_day[1]}})
]
super
end
end
end
class CalendarNote
#
# ヒンドゥー系の暦注
#
class HinduNote < self
NoteObjects = [When::BasicTypes::M17n, [
"namespace:[en=http://en.wikipedia.org/wiki/, ja=http://ja.wikipedia.org/wiki/, hi=http://hi.wikipedia.org/wiki/]",
"locale:[=en:, ja=ja:, hi=hi:, alias]",
"names:[Hindu]",
# 年の暦注 ----------------------------
[When::BasicTypes::M17n,
"names:[year]",
[When::BasicTypes::M17n,
"names:[samvatsara, 木星年=]",
"[Prabhava=, プラバヴァ=, _IAST_]", # 1
"[Vibhava=, ヴィバヴァ=, _IAST_]", # 2
"[Sukha=, スカ=, _IAST_]", # 3
"[Pramoda=, プラモーダ=, _IAST_]", # 4
"[Prajāpati=, プラジャーパティ=, _IAST_]", # 5
"[Aṅgiras=, アンギラス=, _IAST_]", # 6
"[Śrīmukha=, シュリームカ=, _IAST_]", # 7
"[Bhāva=, バーヴァ=, _IAST_]", # 8
"[Yuvan=, ユヴァン=, _IAST_]", # 9
"[Dhātṛ=, ダートリ=, _IAST_]", # 10
"[Īśvara=, イーシュヴァラ=, _IAST_]", # 11
"[Bahudhānya=, バフダーニャ=, _IAST_]", # 12
"[Pramāthin=, プラマーティン=, _IAST_]", # 13
"[Vikrama=, ヴィクラマ=, _IAST_]", # 14
"[Vṛṣa=, ヴリシャ=, _IAST_]", # 15
"[Chitrabhānu=, チトラバーヌ=, _IAST_]", # 16
"[Subhānu=, スバーヌ=, _IAST_]", # 17
"[Tāraṇa=, ターラナ=, _IAST_]", # 18
"[Pārthiva=, パールティヴァ=, _IAST_]", # 19
"[Vyaya=, ヴヤヤ=, _IAST_]", # 20
"[Sarvajit=, サルヴァジト=, _IAST_]", # 21
"[Sarvadhārin=, サルヴァダーリン=, _IAST_]", # 22
"[Virodhin=, ヴィローディン=, _IAST_]", # 23
"[Vikṛta=, ヴィクリタ=, _IAST_]", # 24
"[Khara=, カラ=, _IAST_]", # 25
"[Nandana=, ナンダナ=, _IAST_]", # 26
"[Vijaya=, ヴィジャヤ=, _IAST_]", # 27
"[Jaya=, ジャヤ=, _IAST_]", # 28
"[Manmatha=, マンマタ=, _IAST_]", # 29
"[Durmukha=, ドゥルムカ=, _IAST_]", # 30
"[Hemalamba=, ヘマラムバ=, _IAST_]", # 31
"[Vilambin=, ヴィラムビン=, _IAST_]", # 32
"[Vikārin=, ヴィカーリン=, _IAST_]", # 33
"[Śārvarin=, シャールヴァリン=, _IAST_]", # 34
"[Plava=, プラヴァ=, _IAST_]", # 35
"[Śubhakṛt=, シュバクリト=, _IAST_]", # 36
"[Śobhana=, ショバナ=, _IAST_]", # 37
"[Krodhin=, クロディン=, _IAST_]", # 38
"[Viśvāvasu=, ヴィシュヴァーヴァス=, _IAST_]", # 39
"[Parābhava=, パラーバヴァ=, _IAST_]", # 40
"[Plavaṅga=, プラヴァンガ=, _IAST_]", # 41
"[Kīlaka=, キーラカ=, _IAST_]", # 42
"[Saumya=, サウムヤ=, _IAST_]", # 43
"[Sādhāraṇa=, サーダーラナ=, _IAST_]", # 44
"[Virodhakṛt=, ヴィローダクリト=, _IAST_]", # 45
"[Paridhāvin=, パリダーヴィン=, _IAST_]", # 46
"[Pramādin=, プラマーディン=, _IAST_]", # 47
"[Ānanda=, アーナンダ=, _IAST_]", # 48
"[Rākṣasa=, ラークシャサ=, _IAST_]", # 49
"[Anala=, アナラ=, _IAST_]", # 50
"[Piṅgala=, ピンガラ=, _IAST_]", # 51
"[Kālayukta=, カーラユクタ=, _IAST_]", # 52
"[Siddhārthin=, シッダールティン=, _IAST_]", # 53
"[Raudra=, ラウドラ=, _IAST_]", # 54
"[Durmati=, ドゥルマティ=, _IAST_]", # 55
"[Dundubhi=, ドゥンドゥビ=, _IAST_]", # 56
"[Rudhirodgārin=, ルディロードガーリン=, _IAST_]", # 57
"[Raktākṣin=, ラクタークシン=, _IAST_]", # 58
"[Krodhana=, クローダナ=, _IAST_]", # 59
"[Kṣaya=, クシャヤ=, _IAST_]" # 60
]
],
# 月の暦注 ----------------------------
[When::BasicTypes::M17n,
"names:[month]",
[When::BasicTypes::M17n,
"names:[Month]"
]
],
# 日の暦注 ----------------------------
[When::BasicTypes::M17n,
"names:[day]",
[When::BasicTypes::M17n,
"names:[tithi=, ティティ=ja:%%<ティティ>]",
"[Amavasya, 新月, _IAST_]", # 新月
"[Pratipad=en:Prathama_(day), 1日=, _IAST_]", # 1
"[Dwitiya, 2日=, _IAST_]", # 2
"[Tritiya, 3日=, _IAST_]", # 3
"[Chaturthi, 4日=, _IAST_]", # 4
"[Panchami, 5日=, _IAST_]", # 5
"[Ṣaṣṭhī=en:Shashti, 6日=, _IAST_]", # 6
"[Saptami, 7日=, _IAST_]", # 7
"[Ashtami, 8日=, _IAST_]", # 8
"[Navami, 9日=, _IAST_]", # 9
"[Dashami, 10日=, _IAST_]", # 10
"[Ekadashi, 11日=, _IAST_]", # 11
"[Dwadashi, 12日=, _IAST_]", # 12
"[Thrayodashi, 13日=, _IAST_]", # 13
"[Chaturdashi, 14日=, _IAST_]", # 14
"[Purnima, 満月, _IAST_]" # 満月
],
[When::BasicTypes::M17n,
"names:[vāra=, ヴァーラ=, _IAST_, *vara=]",
"[Ravi=en:S%C5%ABrya, 日曜日, _IAST_]",
"[Soma, 月曜日, _IAST_]",
"[Maṅgala=en:Mangala, 火曜日, _IAST_]",
"[Budha, 水曜日, _IAST_]",
"[Guru, 木曜日, _IAST_]",
"[Śukra=en:Shukra, 金曜日, _IAST_]",
"[Śani=en:Shani, 土曜日, _IAST_]"
],