when_exe 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/LICENSE.ja.txt +25 -25
  2. data/LICENSE.txt +31 -31
  3. data/bin/locales.rb +2 -1
  4. data/bin/when.rb.config +1 -1
  5. data/lib/when_exe.rb +70 -48
  6. data/lib/when_exe/basictypes.rb +99 -65
  7. data/lib/when_exe/calendartypes.rb +40 -178
  8. data/lib/when_exe/coordinates.rb +156 -62
  9. data/lib/when_exe/core/compatibility.rb +10 -0
  10. data/lib/when_exe/core/extension.rb +40 -0
  11. data/lib/when_exe/ephemeris.rb +112 -50
  12. data/lib/when_exe/icalendar.rb +125 -91
  13. data/lib/when_exe/inspect.rb +100 -48
  14. data/lib/when_exe/locales/ar.rb +48 -48
  15. data/lib/when_exe/locales/bg.rb +1 -1
  16. data/lib/when_exe/locales/bs.rb +4 -2
  17. data/lib/when_exe/locales/ca.rb +1 -1
  18. data/lib/when_exe/locales/en_CA.rb +3 -4
  19. data/lib/when_exe/locales/en_IE.rb +88 -0
  20. data/lib/when_exe/locales/en_US.rb +87 -0
  21. data/lib/when_exe/locales/es_CR.rb +84 -0
  22. data/lib/when_exe/locales/es_EC.rb +85 -0
  23. data/lib/when_exe/locales/es_PA.rb +85 -0
  24. data/lib/when_exe/locales/fr.rb +39 -39
  25. data/lib/when_exe/locales/hu.rb +15 -14
  26. data/lib/when_exe/locales/it.rb +1 -1
  27. data/lib/when_exe/locales/ja.rb +2 -2
  28. data/lib/when_exe/locales/locales.rb +7 -0
  29. data/lib/when_exe/locales/lt.rb +21 -19
  30. data/lib/when_exe/locales/ms.rb +84 -0
  31. data/lib/when_exe/locales/nl.rb +2 -2
  32. data/lib/when_exe/locales/ru.rb +1 -1
  33. data/lib/when_exe/locales/uk.rb +1 -1
  34. data/lib/when_exe/locales/ur.rb +84 -0
  35. data/lib/when_exe/mini_application.rb +44 -43
  36. data/lib/when_exe/parts/enumerator.rb +3 -3
  37. data/lib/when_exe/parts/geometric_complex.rb +6 -1
  38. data/lib/when_exe/parts/locale.rb +49 -18
  39. data/lib/when_exe/parts/method_cash.rb +61 -0
  40. data/lib/when_exe/parts/resource.rb +221 -106
  41. data/lib/when_exe/parts/timezone.rb +70 -33
  42. data/lib/when_exe/region/bahai.rb +2 -2
  43. data/lib/when_exe/region/balinese.rb +40 -43
  44. data/lib/when_exe/region/chinese.rb +93 -33
  45. data/lib/when_exe/region/chinese_calendar.rb +117 -1
  46. data/lib/when_exe/region/chinese_epoch.rb +65 -10
  47. data/lib/when_exe/region/christian.rb +97 -2
  48. data/lib/when_exe/region/ephemeric_notes.rb +353 -0
  49. data/lib/when_exe/region/french.rb +1 -1
  50. data/lib/when_exe/region/geologicalage.rb +171 -171
  51. data/lib/when_exe/region/indian.rb +18 -14
  52. data/lib/when_exe/region/iranian.rb +1 -1
  53. data/lib/when_exe/region/japanese.rb +49 -12
  54. data/lib/when_exe/region/japanese_notes.rb +838 -507
  55. data/lib/when_exe/region/japanese_residues.rb +724 -662
  56. data/lib/when_exe/region/javanese.rb +7 -7
  57. data/lib/when_exe/region/mayan.rb +19 -17
  58. data/lib/when_exe/region/nihon_shoki.rb +3 -3
  59. data/lib/when_exe/region/residue.rb +29 -28
  60. data/lib/when_exe/region/shire.rb +2 -2
  61. data/lib/when_exe/region/tibetan.rb +87 -5
  62. data/lib/when_exe/region/world.rb +1 -1
  63. data/lib/when_exe/timestandard.rb +85 -7
  64. data/lib/when_exe/tmobjects.rb +32 -4
  65. data/lib/when_exe/tmposition.rb +104 -55
  66. data/lib/when_exe/tmreference.rb +157 -60
  67. data/lib/when_exe/version.rb +2 -2
  68. data/test/examples/JapanHolidays.ics +3 -3
  69. data/test/examples/JapanHolidaysRFC6350.ics +499 -0
  70. data/test/examples/Residue.m17n +3 -2
  71. data/test/examples/Spatial.m17n +3 -3
  72. data/test/examples/USA-DST.ics +27 -27
  73. data/test/examples/today.rb +1 -1
  74. data/test/test.rb +4 -2
  75. data/test/test/basictypes.rb +40 -15
  76. data/test/test/coordinates.rb +9 -4
  77. data/test/test/icalendar.rb +24 -14
  78. data/test/test/inspect.rb +5 -3
  79. data/test/test/parts.rb +11 -2
  80. data/test/test/region/chinese.rb +4 -4
  81. data/test/test/region/civil.rb +124 -0
  82. data/test/test/region/geologicalage.rb +5 -2
  83. data/test/test/region/indian.rb +2 -0
  84. data/test/test/region/japanese.rb +156 -1
  85. data/test/test/region/jewish.rb +3 -3
  86. data/test/test/region/m17n.rb +9 -9
  87. data/test/test/region/mayan.rb +122 -5
  88. data/test/test/region/residue.rb +1 -1
  89. data/test/test/tmobjects.rb +27 -64
  90. data/test/test/tmposition.rb +48 -1
  91. data/test/test/tmreference.rb +66 -4
  92. data/when_exe.gemspec +1 -1
  93. metadata +15 -6
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  =begin
3
- Copyright (C) 2011-2013 Takashi SUGA
3
+ Copyright (C) 2011-2014 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,6 +15,36 @@ module When::Parts
15
15
  #
16
16
  class Timezone
17
17
 
18
+ #
19
+ # When::V::Timezone と Qhwn::Parts::Timezone の抽象基底
20
+ #
21
+ module Base
22
+ # 標準時間帯の時計
23
+ # @return [When::TM::Clock]
24
+ attr_reader :standard
25
+
26
+ # 夏時間帯の時計
27
+ # @return [When::TM::Clock]
28
+ attr_reader :daylight
29
+
30
+ # 夏時間帯と標準時間帯の時間差
31
+ # @return [When::TM:IntervalLength]
32
+ attr_reader :difference
33
+
34
+ # When::TM::TemporalPosition の時間帯を変更して複製する
35
+ #
36
+ # @param [When::TM::CalDate, When::TM::DateAndTime, When::TM::JulianDate] date
37
+ # @param [Hash] options see {When::TM::TemporalPosition._instance}
38
+ #
39
+ # @return [When::TM::DateAndTime, When::TM::JulianDate]
40
+ #
41
+ def ^(date, options={})
42
+ options = date._attr.merge({:clock=>self}).merge(options)
43
+ return When::TM::JulianDate.dynamical_time(date.dynamical_time, options) unless date.frame.kind_of?(When::TM::Calendar)
44
+ date.frame.jul_trans(When::TM::JulianDate.dynamical_time(date.dynamical_time), options)
45
+ end
46
+ end
47
+
18
48
  class << self
19
49
  include Resource::Pool
20
50
 
@@ -64,22 +94,12 @@ module When::Parts
64
94
  end
65
95
  end
66
96
 
97
+ include Base
98
+
67
99
  # ラップしている TZInfo::Timezone インスタンス
68
100
  # @return [TZInfo::Timezone]
69
101
  attr_reader :timezone
70
102
 
71
- # 標準時間帯の時計
72
- # @return [When::TM::Clock]
73
- attr_reader :standard
74
-
75
- # 夏時間帯の時計
76
- # @return [When::TM::Clock]
77
- attr_reader :daylight
78
-
79
- # 夏時間帯と標準時間帯の時間差
80
- # @return [When::TM:IntervalLength]
81
- attr_reader :difference
82
-
83
103
  # ユニーク識別名
84
104
  # @return [String]
85
105
  def label
@@ -98,6 +118,14 @@ module When::Parts
98
118
  self.class.tz_info[label].latitude
99
119
  end
100
120
 
121
+ # 時間帯を代表する都市の空間位置
122
+ # @return [When::Coordinates::Spatial]
123
+ def location
124
+ return @location if @location
125
+ tzinfo = self.class.tz_info[label]
126
+ @location = When.Resource("_l:long=#{tzinfo.longitude.to_f}&lat=#{tzinfo.latitude.to_f}&label=#{label}")
127
+ end
128
+
101
129
  # 時分秒のインデクス
102
130
  # @return [Array<When::Coordinates::Index>]
103
131
  attr_reader :indices
@@ -131,8 +159,8 @@ module When::Parts
131
159
  }
132
160
  end
133
161
  end
134
- std, dst = _offsets(Time.now.to_i)
135
- @standard = When::TM::Clock.new({:zone=>std, :tz_prop=>self})
162
+ dst, std = _offsets(Time.now.to_i)
163
+ @standard = When::TM::Clock.new({:zone=>std, :tz_prop=>self})
136
164
  if std == dst
137
165
  @daylight = @standard
138
166
  @difference = 0
@@ -144,16 +172,20 @@ module When::Parts
144
172
  end
145
173
 
146
174
  # @private
147
- def _daylight(zdate=nil)
148
- if block_given?
149
- zdate = yield(@standard.dup.tap{|clock| clock.tz_prop = nil})
150
- now = zdate.to_time.to_i
151
- clocks = _offsets(now).map {|clock| When::TM::Clock.new({:zone=>clock, :tz_prop=>self})}
152
- flags = clocks.map {|z| @timezone.period_for_utc(yield(z.dup.tap{|clock| clock.tz_prop = nil}).to_time.to_i).dst? }
153
- (flags[0] || flags[1]) ? clocks[1] : clocks[0]
154
- else
155
- When::TM::Clock.new({:zone=>@timezone.period_for_utc(zdate.to_time.to_i).utc_total_offset, :tz_prop=>self})
175
+ def _daylight(time)
176
+ frame, cal_date, clk_time = time
177
+ clocks = {}
178
+ if clk_time
179
+ time = frame.to_universal_time(cal_date, clk_time, @standard)
180
+ offsets = _offsets((time/When::TM::Duration::SECOND).floor)
181
+ offsets.each do |offset|
182
+ clocks[offset] ||= When::TM::Clock.new({:zone=>offset, :tz_prop=>self})
183
+ return clocks[offsets[0]] if @timezone.period_for_utc(
184
+ (frame.to_universal_time(cal_date, clk_time, clocks[offset])/When::TM::Duration::SECOND).floor).dst?
185
+ end
156
186
  end
187
+ offset = @timezone.period_for_utc((time/When::TM::Duration::SECOND).floor).utc_total_offset
188
+ clocks[offset] || When::TM::Clock.new({:zone=>offset, :tz_prop=>self})
157
189
  end
158
190
 
159
191
  # @private
@@ -164,17 +196,17 @@ module When::Parts
164
196
  private
165
197
 
166
198
  def _offsets(time)
167
- now = @timezone.period_for_utc(time)
168
- past = @timezone.period_for_utc(now.utc_start-1) if now.utc_start
169
- future = @timezone.period_for_utc(now.utc_end) if now.utc_end
170
- std = now.utc_offset
171
- dst = now.utc_total_offset
199
+ now = @timezone.period_for_utc(time)
200
+ past = @timezone.period_for_utc(now.utc_start-1) if now.utc_start
201
+ future = @timezone.period_for_utc(now.utc_end) if now.utc_end
202
+ std = now.utc_offset
203
+ dst = now.utc_total_offset
172
204
  [past, future].each do |period|
173
205
  next unless period
174
- std = period.utc_offset if std > period.utc_offset
175
- dst = period.utc_total_offset if dst < period.utc_total_offset
206
+ std = period.utc_offset if std > period.utc_offset
207
+ dst = period.utc_total_offset if dst < period.utc_total_offset
176
208
  end
177
- [std, dst]
209
+ [dst, std]
178
210
  end
179
211
 
180
212
  # その他のメソッド
@@ -182,7 +214,12 @@ module When::Parts
182
214
  # 処理を first (type: When::TM::(Temporal)Position) に委譲する
183
215
  #
184
216
  def method_missing(name, *args, &block)
185
- timezone.send(name.to_sym, *args, &block)
217
+ self.class.module_eval %Q{
218
+ def #{name}(*args, &block)
219
+ timezone.send("#{name}", *args, &block)
220
+ end
221
+ } unless When::Parts::MethodCash.escape(name)
222
+ timezone.send(name, *args, &block)
186
223
  end
187
224
  end
188
225
  end
@@ -100,8 +100,8 @@ module When
100
100
  def ephemeris_equinox(date)
101
101
  equinox_time = @engine.cn_to_time(+date[0])
102
102
  equinox_date = (equinox_time + 0.5 + @engine.long/360.0).floor
103
- sun_set_time = @engine.sun_set(equinox_date)
104
- (sun_set_time <= equinox_time) ? equinox_date+1 : equinox_date
103
+ sunset_time = @engine.sunset(equinox_date)
104
+ (sunset_time <= equinox_time) ? equinox_date+1 : equinox_date
105
105
  end
106
106
 
107
107
  private
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  =begin
3
- Copyright (C) 2011-2013 Takashi SUGA
3
+ Copyright (C) 2011-2014 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
@@ -71,24 +71,21 @@ module When
71
71
  # ウク周期
72
72
  #
73
73
  class Wuku < Residue
74
+
75
+ # Urip 7
76
+ Urip7 = [ 5, 4, 3, 7, 8, 6, 9]
77
+
78
+ # Urip 5
79
+ Urip5 = [ 9, 7, 4, 8, 5]
80
+
74
81
  # 2日週
75
- Dwiwara = [ 0, 1, 1, 1, 1, 1, 0,
76
- 1, 0, 0, 0, 1, 0, 1,
77
- 0, 1, 0, 1, 0, 1, 0,
78
- 0, 0, 1, 0, 1, 1, 1,
79
- 1, 1, 0, 0, 0, 0, 0]
82
+ Dwiwara = (0...35).to_a.map {|d| (Urip7[d % 7] + Urip5[d % 5]) % 2}
83
+
80
84
  # 10日週
81
- Dasawara = [ 0, 1, 2, 3, 4, 3, 5,
82
- 6, 7, 8, 5, 3, 9, 2,
83
- 9, 4, 9, 1, 5, 1, 8,
84
- 7, 8, 1, 7, 2, 4, 4,
85
- 4, 6, 7, 0, 7, 0, 0]
85
+ Dasawara = (0...35).to_a.map {|d| (Urip7[d % 7] + Urip5[d % 5]) % 10}
86
+
86
87
  # Watek
87
- Watek = [ 0, 1, 2, 3, 4, 3, 5,
88
- 6, 7, 8, 5, 3, 9,10,
89
- 9, 4, 9, 1, 5, 1,11,
90
- 7, 8, 1, 7,10, 4, 4,
91
- 4, 6, 7, 0, 7, 0, 0]
88
+ Watek = (0...35).to_a.map {|d| Urip7[d % 7] + Urip5[d % 5] - 7 }
92
89
 
93
90
  # 2日週
94
91
  # @return [When::BasicTypes::M17n]
@@ -136,15 +133,15 @@ module When
136
133
  #
137
134
  # バリのサカ暦
138
135
  #
139
- Balinese = [self, [
136
+ BalineseLuniSolar = [self, [
140
137
  "namespace:[en=http://en.wikipedia.org/wiki/, ja=http://ja.wikipedia.org/wiki/]",
141
138
  "locale:[=en:, ja=ja:, alias]",
142
139
  "period:[BalineseLuniSolar=, バリ・サカ暦=]",
143
- ["[BSE=, サカ暦=, alias:Balinese_Saka_Era]1886-07<13", "Calendar Epoch", "1886-07<13^BalineseLuniSolar1965",
144
- "1892-07-04^BalineseLuniSolar1971",
145
- "1914-07-08^BalineseLuniSolar1993",
146
- "1921-06<10^BalineseLuniSolar2000",
147
- "1924-07<14^BalineseLuniSolar2003", '+Infinity']
140
+ ["[SE=, サカ暦=, alias:Balinese_Saka_Era]1887-07<13", "Calendar Epoch", "1965-07<13^BalineseLuniSolar1965",
141
+ "1971-07-04^BalineseLuniSolar1971",
142
+ "1993-07-08^BalineseLuniSolar1993",
143
+ "2000-06<10^BalineseLuniSolar2000",
144
+ "2003-07<14^BalineseLuniSolar2003", '+Infinity']
148
145
  ]]
149
146
  end
150
147
 
@@ -204,6 +201,8 @@ module When
204
201
  :trunk=>When.Resource('_m:BalineseTerms::HinduMonth::*'),
205
202
  :shift=>+8})
206
203
 
204
+ @origin_of_MSC = 0
205
+
207
206
  @tabular = CyclicTableBased.new({
208
207
  'indices' => [month_index, Coordinates::Index.new],
209
208
  'rule_table' => @rule_table
@@ -222,8 +221,6 @@ module When
222
221
  @indices = [month_index, Coordinates::Index.new({:branch=>{-2=>intercalary_day[0]}})]
223
222
 
224
223
  @note = When.CalendarNote(@note || 'BalineseNote')
225
-
226
- @timezone ||= 0
227
224
  super
228
225
  end
229
226
  end
@@ -452,16 +449,16 @@ module When
452
449
 
453
450
  [When::BasicTypes::M17n,
454
451
  "names:[Dasawara=, 10日週=]",
455
- "[Sri ]", # 0
452
+ "[Pandita]", # 0
456
453
  "[Pati ]", # 1
457
- "[Raja ]", # 2
458
- "[Manuh ]", # 3
459
- "[Duka ]", # 4
460
- "[Manusa ]", # 5
461
- "[Raksasa]", # 6
462
- "[Suka ]", # 7
454
+ "[Suka ]", # 2
455
+ "[Duka ]", # 3
456
+ "[Sri ]", # 4
457
+ "[Manuh ]", # 5
458
+ "[Manusa ]", # 6
459
+ "[Raja ]", # 7
463
460
  "[Dewa ]", # 8
464
- "[Pandita]" # 9
461
+ "[Raksasa]" # 9
465
462
  ],
466
463
 
467
464
  [When::Coordinates::Residue,
@@ -476,18 +473,18 @@ module When
476
473
 
477
474
  [When::BasicTypes::M17n,
478
475
  "names:[Watek=]",
479
- "[Suku-Gajah= ]", # 0
480
- "[Gajah-Lembu= ]", # 1
481
- "[Watu-Lembu= ]", # 2
482
- "[Wong-Lembu= ]", # 3
483
- "[Buta-Uler= ]", # 4
484
- "[Gajah-Lintah=]", # 5
485
- "[Suku-Uler= ]", # 6
486
- "[Watu-Lintah= ]", # 7
476
+ "[Watu-Lembu= ]", # 7
487
477
  "[Buta-Lintah= ]", # 8
488
- "[Wong-Gajah= ]", # 9
489
- "[Watu-Uler= ]", # 10
490
- "[Buta-Gajah= ]" # 11
478
+ "[Suku-Uler= ]", # 9
479
+ "[Wong-Gajah= ]", # 10
480
+ "[Gajah-Lembu= ]", # 11
481
+ "[Watu-Lintah= ]", # 12
482
+ "[Buta-Uler= ]", # 13
483
+ "[Suku-Gajah= ]", # 14
484
+ "[Wong-Lembu= ]", # 15
485
+ "[Gajah-Lintah=]", # 16
486
+ "[Watu-Uler= ]", # 17
487
+ "[Buta-Gajah= ]" # 18
491
488
  ],
492
489
 
493
490
  [When::Coordinates::Residue,
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  =begin
3
- Copyright (C) 2011-2013 Takashi SUGA
3
+ Copyright (C) 2011-2014 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
@@ -130,8 +130,36 @@ module When
130
130
  attr_reader :anomalistic_month_length
131
131
 
132
132
  # 元期の近点離隔
133
- # @return [Numeric]
134
- attr_reader :anomalistic_month_shift
133
+ # @return [Numeric]
134
+ attr_reader :anomalistic_month_shift
135
+
136
+ # 当該日付のthiti の変化範囲(唐代の定朔の暦法用 cn_to_time(1L) を使用する)
137
+ #
138
+ # @param [When::TM::TemporalPosition] date 日付
139
+ #
140
+ # @return [Range] 当該日付のthiti の変化範囲(朔を含む場合 nil)
141
+ #
142
+ def thiti_range(date)
143
+ date = date.floor
144
+ p0, p1 = [date, date.succ].map {|d|
145
+ t = d.to_f
146
+ c = (30.0 * ((t - CYCLE_0M) * @cycle_number_1m + @cycle_number_0m)).floor
147
+ t0 = t1 = nil
148
+ loop do
149
+ t0 = cn_to_time( c / 30.0)
150
+ t1 = cn_to_time((c+1)/ 30.0)
151
+ if t0 > t
152
+ c -= 1
153
+ elsif t1 <= t
154
+ c += 1
155
+ else
156
+ break
157
+ end
158
+ end
159
+ (c + (t-t0) / (t1-t0)) % 30.0
160
+ }
161
+ p0 >= p1 ? nil : p0...p1
162
+ end
135
163
 
136
164
  private
137
165
 
@@ -157,8 +185,6 @@ module When
157
185
  #
158
186
  def delta_s(t)
159
187
 
160
- tt = t
161
-
162
188
  t0, a, b, c = nil
163
189
  @s.each do |v|
164
190
  t0, a, b, c = v
@@ -189,8 +215,6 @@ module When
189
215
  #
190
216
  def delta_m(t)
191
217
 
192
- tt = t
193
-
194
218
  t *= @denominator
195
219
  a0 = b0 = t0 = 0
196
220
  @m.each do |v|
@@ -210,6 +234,7 @@ module When
210
234
  if @formula == '1L'
211
235
  @anomalistic_month_length = @anomalistic_month_length.to_r
212
236
  @anomalistic_month_shift = (@anomalistic_month_shift||0).to_r
237
+ @s = @s.map {|item| item.dup}
213
238
  (0...@s.size).each do |i|
214
239
  @s[i-1][1,0] = @year_length / @s.size + (@s[i][0]-@s[i-1][0]) / @denominator
215
240
  end
@@ -228,6 +253,14 @@ module When
228
253
  #
229
254
  class ChineseSolar < EphemerisBasedSolar
230
255
 
256
+ #
257
+ # @return [When::CalendarTypes::ChineseLuniSolar] 対で用いる太陰太陽暦の名前
258
+ #
259
+ attr_reader :twin
260
+
261
+ # @private
262
+ attr_reader :doyo
263
+
231
264
  private
232
265
 
233
266
  # オブジェクトの正規化
@@ -241,7 +274,6 @@ module When
241
274
  @formula *= 2 if @formula.length == 1
242
275
  @formula[0] += (@formula[0] =~ /\?/ ? '&' : '?') + 'formula=12S' if @formula[0].kind_of?(String)
243
276
  @formula[1] += (@formula[1] =~ /\?/ ? '&' : '?') + 'formula=1L' if @formula[1].kind_of?(String)
244
- @timezone ||= 0
245
277
  @note ||= When.CalendarNote('ChineseNotes')
246
278
  @indices ||= [
247
279
  When::Coordinates::Index.new({:trunk=>When.Resource('_m:ChineseTerms::Month::*')}),
@@ -256,13 +288,29 @@ module When
256
288
  #
257
289
  class ChineseLuniSolar < EphemerisBasedLuniSolar
258
290
 
291
+ #
292
+ # @return [When::CalendarTypes::ChineseSolar] 対で用いる太陽暦の名前
293
+ #
294
+ attr_reader :twin
295
+
296
+ # 指定の年の天正冬至を含む月以降1年分の閏月のパターン
297
+ #
298
+ # @param [Numeric] y 年
299
+ #
300
+ # @return [Array<Numeric:月番号>, Array<Numeric:中気のない月の月番号>]
301
+ #
302
+ def intercalary_pattern(y)
303
+ m = _base_month(y)
304
+ l = _base_ids(y)
305
+ [l, (0...l.size).to_a.map {|i| _intercalary?(m+i) ? l[i] : nil}.compact]
306
+ end
307
+
259
308
  private
260
309
 
261
310
  # オブジェクトの正規化
262
311
  #
263
312
  # @cycle_offset = 雨水の場合 -1
264
313
  # @formula = 太陽黄経および月の位相の計算に用いるEphemeris
265
- # @timezone[1] = 進朔量
266
314
  #
267
315
  def _normalize(args=[], options={})
268
316
  @label ||= When.Resource('_m:ChineseTerms::ChineseLuniSolar')
@@ -277,7 +325,6 @@ module When
277
325
  @intercalary_span ||= 12
278
326
  @intercalary_span = @intercalary_span.to_i
279
327
  @intercalary_month = (@intercalary_month.to_i - @base_month) % 12 + 1 if @intercalary_month
280
- @timezone ||= 0
281
328
  @note ||= When.CalendarNote('ChineseNotes')
282
329
  @indices ||= [
283
330
  When::Coordinates::Index.new({:branch=>{1=>When.Resource('_m:CalendarTerms::閏')},
@@ -312,10 +359,7 @@ module When
312
359
  # @return [Numeric] 天正冬至月の通月
313
360
  #
314
361
  def _base_month_(y)
315
- (Residue.mod((@formula[0].cn_to_time(12*(y-1) + @base_month - @vernal_month) +
316
- 0.5 + @timezone[0]).floor) {|m|
317
- _new_month(m)
318
- })[0]
362
+ (Residue.mod(solar_sdn(@formula[0].cn_to_time(12*(y-1) + @base_month - @vernal_month))) {|m| _new_month(m)})[0]
319
363
  end
320
364
 
321
365
  # 暦年の翻訳表の取得
@@ -383,7 +427,7 @@ module When
383
427
  end
384
428
  end
385
429
 
386
- Chinese = [When::BasicTypes::M17n, [
430
+ Chinese = [{}, When::BasicTypes::M17n, [
387
431
  "namespace:[en=http://en.wikipedia.org/wiki/, ja=http://ja.wikipedia.org/wiki/]",
388
432
  "locale:[=ja:, en=en:, alias]",
389
433
  "area:[中国,China]",
@@ -397,7 +441,7 @@ module When
397
441
  [ChineseLuniSolar,
398
442
  'name:[顓頊暦]',
399
443
  'formula:MeanLunation?year_length=1461/4&lunation_length=27759/940&day_epoch=1171396&longitude_shift=-1/8',
400
- 'timezone:0,+12',
444
+ 'time_basis:+00,+#{P:12}',
401
445
  'intercalary_month:9'
402
446
  ],
403
447
 
@@ -501,12 +545,13 @@ module When
501
545
  ],
502
546
 
503
547
  [ChineseLuniSolar,
504
- 'name:[儀鳳暦]',
548
+ 'name:[平朔儀鳳暦]',
505
549
  'formula:MeanLunation?year_length=122357/335&lunation_length=39571/1340&day_epoch=-96608689'
506
550
  ],
507
551
 
508
552
  [ChineseLuniSolar,
509
553
  'name:[麟徳暦]',
554
+ 'time_basis:+00,+#{P:00}',
510
555
  {'formula'=>['12S', '1L'].map {|f|
511
556
  Ephemeris::ChineseTrueLunation.new({
512
557
  'formula' => f,
@@ -573,13 +618,15 @@ module When
573
618
  [1340.0, -125], # 27日
574
619
  [ 743.0+1.0/12, -71] # 28日
575
620
  ]
576
- })
577
- }}
621
+ })
622
+ },
623
+ 'doyo' => (Rational( 4,15) + 244) / 1340
624
+ }
578
625
  ],
579
626
 
580
627
  [ChineseLuniSolar,
581
628
  'name:[大衍暦]',
582
- 'timezone:0,+6',
629
+ 'time_basis:+00,+#{P:03}',
583
630
  {'formula'=>['12S', '1L'].map {|f|
584
631
  Ephemeris::ChineseTrueLunation.new({
585
632
  'formula' => f,
@@ -647,13 +694,15 @@ module When
647
694
  [3040.0, +276], # 27日
648
695
  [1686.0, +165] # 28日
649
696
  ]
650
- })
651
- }}
697
+ })
698
+ },
699
+ 'doyo' => (Rational(13,30) + 531) / 3040
700
+ }
652
701
  ],
653
702
 
654
703
  [ChineseLuniSolar,
655
704
  'name:[五紀暦]',
656
- 'timezone:0,+6',
705
+ 'time_basis:+00,+#{P:06}',
657
706
  {'formula'=>['12S', '1L'].map {|f|
658
707
  Ephemeris::ChineseTrueLunation.new({
659
708
  'formula' => f,
@@ -720,13 +769,20 @@ module When
720
769
  [1340.0, -125], # 27日
721
770
  [ 743.0+5.0/37, -75] # 28日
722
771
  ]
723
- })
724
- }}
772
+ })
773
+ },
774
+ 'doyo' => (Rational( 4,15) + 244) / 1340
775
+ }
776
+ ],
777
+
778
+ [ChineseSolar,
779
+ 'name:[正元暦(節月)]',
780
+ 'formula:MeanLunation?year_length=399943/1095&lunation_length=32336/1095&day_epoch=-145149709'
725
781
  ],
726
782
 
727
783
  [ChineseLuniSolar,
728
784
  'name:[宣明暦]',
729
- 'timezone:0,+6',
785
+ 'time_basis:+00,+#{P:06}',
730
786
  {'formula'=>['12S', '1L'].map {|f|
731
787
  Ephemeris::ChineseTrueLunation.new({
732
788
  'formula' => f,
@@ -793,8 +849,10 @@ module When
793
849
  [ 8400.0, +740], # 13日
794
850
  [ 6529.095, +646] # 14日
795
851
  ]
796
- })
797
- }}
852
+ })
853
+ },
854
+ 'doyo' => (Rational( 1, 2) + 1468) / 8400
855
+ }
798
856
  ],
799
857
 
800
858
  [ChineseSolar,
@@ -808,12 +866,12 @@ module When
808
866
  ],
809
867
 
810
868
  [ChineseSolar,
811
- 'name:[前々宝暦暦(節月)]',
869
+ 'name:[貞享補暦A(節月)]',
812
870
  'formula:VariableYearLengthMethod?day_epoch=2336118.903800&year_epoch=1684&year_length=365.241696&year_delta=1'
813
871
  ],
814
872
 
815
873
  [ChineseSolar,
816
- 'name:[前宝暦暦(節月)]',
874
+ 'name:[貞享補暦B(節月)]',
817
875
  'formula:VariableYearLengthMethod?day_epoch=2336118.622300&year_epoch=1684&year_length=365.241696&year_delta=1'
818
876
  ],
819
877
 
@@ -833,9 +891,11 @@ module When
833
891
  ]
834
892
  ].inject([]) {|list, cal|
835
893
  if cal.kind_of?(Array) && cal[0] == ChineseLuniSolar
836
- twin = cal.dup
837
- twin[0..1] = [ChineseSolar, cal[1].sub(/\]/, '(節月)]')]
838
- list << cal << twin
894
+ solar_name = cal[1].sub(/\]/, '(節月)]')
895
+ lunisolar = cal.dup << 'twin:Chinese::' + solar_name.gsub(/(name:\[|\])/,'')
896
+ solar = cal.dup << 'twin:Chinese::' + cal[1].gsub(/(name:\[|\])/,'')
897
+ solar[0..1] = [ChineseSolar, solar_name]
898
+ list << lunisolar << solar
839
899
  else
840
900
  list << cal
841
901
  end