when_exe 0.4.0 → 0.4.1
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.
- checksums.yaml +4 -4
- data/README.md +333 -212
- data/bin/make_ttl.rb +37 -0
- data/bin/make_ttl.rb.config +9 -0
- data/lib/when_exe.rb +923 -925
- data/lib/when_exe/calendarnote.rb +9 -5
- data/lib/when_exe/coordinates.rb +2437 -2446
- data/lib/when_exe/inspect.rb +1480 -1408
- data/lib/when_exe/linkeddata.rb +574 -0
- data/lib/when_exe/locales/akt.rb +177 -176
- data/lib/when_exe/locales/locale.rb +751 -751
- data/lib/when_exe/mini_application.rb +307 -307
- data/lib/when_exe/parts/resource.rb +1115 -1103
- data/lib/when_exe/region/chinese/epochs.rb +6 -5
- data/lib/when_exe/region/christian.rb +831 -829
- data/lib/when_exe/region/japanese.rb +93 -93
- data/lib/when_exe/region/japanese/notes.rb +1510 -1495
- data/lib/when_exe/region/japanese/residues.rb +13 -13
- data/lib/when_exe/tmposition.rb +2307 -2273
- data/lib/when_exe/tmreference.rb +1744 -1734
- data/lib/when_exe/version.rb +2 -2
- data/link_to_online_documents +1 -1
- data/test/scripts/3.ext.rb +6 -6
- data/test/scripts/3.rb +6 -6
- data/test/test.rb +76 -75
- data/test/test/icalendar.rb +883 -879
- data/test/test/linkeddata.rb +224 -0
- data/test/test/region/m17n.rb +193 -193
- data/when_exe.gemspec +3 -2
- metadata +13 -6
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
=begin
|
3
|
-
Copyright (C) 2011-
|
3
|
+
Copyright (C) 2011-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
|
@@ -207,6 +207,9 @@ module When
|
|
207
207
|
#
|
208
208
|
CalendarDepend = false
|
209
209
|
|
210
|
+
# @private
|
211
|
+
HashProperty = [:event]
|
212
|
+
|
210
213
|
# デフォルトイベント名
|
211
214
|
#
|
212
215
|
# @return [String]
|
@@ -435,14 +438,15 @@ module When
|
|
435
438
|
|
436
439
|
# return Array of Hash
|
437
440
|
focused_notes.map {|note|
|
441
|
+
nobj = note_objects[note]
|
438
442
|
case notes[note]
|
439
443
|
when nil, false ; {}
|
440
|
-
when Hash ; {:note=>
|
444
|
+
when Hash ; {:note=>nobj.label}.merge(notes[note])
|
441
445
|
else
|
442
|
-
if
|
443
|
-
|
446
|
+
if nobj.respond_to?(:to_note_hash)
|
447
|
+
nobj.to_note_hash(notes[note], dates)
|
444
448
|
else
|
445
|
-
{:note=>
|
449
|
+
{:note=>nobj.kind_of?(String) ? nobj : nobj.label, :value=>notes[note]}
|
446
450
|
end
|
447
451
|
end
|
448
452
|
}
|
data/lib/when_exe/coordinates.rb
CHANGED
@@ -1,2446 +1,2437 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
=begin
|
3
|
-
Copyright (C) 2011-
|
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
|
-
#
|
9
|
-
# 座標の記述に用いる諸オブジェクト
|
10
|
-
#
|
11
|
-
module When::Coordinates
|
12
|
-
# 変換テーブル
|
13
|
-
PRECISION = {'YEAR'=>When::YEAR, 'MONTH' =>When::MONTH, 'WEEK' =>When::WEEK, 'DAY' =>When::DAY,
|
14
|
-
'HOUR'=>When::HOUR, 'MINUTE'=>When::MINUTE, 'SECOND'=>When::SECOND, 'SYSTEM'=>When::SYSTEM}
|
15
|
-
PERIOD = {'P1Y' =>When::YEAR, 'P1M' =>When::MONTH, 'P1W' =>When::WEEK, 'P1D' =>When::DAY,
|
16
|
-
'PT1H'=>When::HOUR, 'PT1M' =>When::MINUTE, 'PT1S' =>When::SECOND,
|
17
|
-
'1Y' =>When::YEAR, '1M' =>When::MONTH, '1W' =>When::WEEK, '1D' =>When::DAY,
|
18
|
-
'1h' =>When::HOUR, '1m' =>When::MINUTE, '1s' =>When::SECOND}
|
19
|
-
VALUE = {'DATE'=>When::DAY, 'TIME' =>When::SYSTEM, 'DATE-TIME'=>When::SYSTEM} # RFC 5545
|
20
|
-
PRECISION_NAME = PRECISION.invert
|
21
|
-
PERIOD_NAME = {When::YEAR=>'P1Y' , When::MONTH=>'P1M', When::WEEK =>'P1W', When::DAY=>'P1D',
|
22
|
-
When::HOUR=>'PT1H', When::MINUTE=>'PT1M', When::SECOND=>'PT1S'}
|
23
|
-
MATCH = {'NS'=>/(N|S|北緯|南緯)/, 'EW'=>/(E|W|東経|西経)/}
|
24
|
-
|
25
|
-
# 60進->10進変換(1/225度単位)
|
26
|
-
#
|
27
|
-
# @param [String] src 60進法で表した方向付きの数値
|
28
|
-
# @param [String] dir 方向 ('NS' または 'EW')
|
29
|
-
#
|
30
|
-
# @return [Numeric] 10進変換した数値 (src が nil なら0.0を、Numeric なら 225*src を返す)
|
31
|
-
#
|
32
|
-
def self.to_deg_225(src, dir)
|
33
|
-
case src
|
34
|
-
when String
|
35
|
-
src = src.gsub(/_+/,'').gsub(/@/, '.')
|
36
|
-
return src.to_r * Spatial::DEGREE if (src =~ /E[-+]/ || src !~ MATCH[dir])
|
37
|
-
sign = ($1 == dir[1..1]) ? -1 : +1
|
38
|
-
value = src.gsub(MATCH[dir], '').strip
|
39
|
-
if ((value + "00000") =~ /\A(\d+)\.(\d{2})(\d{2})(\d+)\z/)
|
40
|
-
deg, min, sec, frac = $~[1..4]
|
41
|
-
sec += "." + frac
|
42
|
-
else
|
43
|
-
deg, min, sec = value.split(/[^\d.]+/)
|
44
|
-
end
|
45
|
-
return sign * (deg.to_i * Spatial::DEGREE +
|
46
|
-
(min||0).to_f * (Spatial::DEGREE/60.0) +
|
47
|
-
(sec||0).to_f * (Spatial::DEGREE/3600.0))
|
48
|
-
when NilClass
|
49
|
-
0.0
|
50
|
-
when Numeric
|
51
|
-
src * Spatial::DEGREE
|
52
|
-
else
|
53
|
-
raise TypeError, "Invalid Location Type"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
# 60進->10進変換(度単位)
|
58
|
-
#
|
59
|
-
# @param [String] src 60進法で表した方向付きの数値
|
60
|
-
# @param [String] dir 方向 ('NS' または 'EW')
|
61
|
-
#
|
62
|
-
# @return [Numeric] 10進変換した数値 (src が nil なら0.0を、Numeric ならそのままsrcを返す)
|
63
|
-
#
|
64
|
-
def self.to_deg(src, dir)
|
65
|
-
to_deg_225(src, dir) / Spatial::DEGREE
|
66
|
-
end
|
67
|
-
|
68
|
-
# 10進->60進変換
|
69
|
-
#
|
70
|
-
# @param [Numeric] src 数値
|
71
|
-
# @param [String] dir 方向 ('NS' または 'EW')
|
72
|
-
# @param [Integer] round 秒の小数点以下最大桁数
|
73
|
-
#
|
74
|
-
# @return [String] 60進変換した数値
|
75
|
-
#
|
76
|
-
def self.to_dms(src, dir, round=6)
|
77
|
-
dir = (src >= 0) ? dir[0..0] : dir[1..1]
|
78
|
-
deg, min = src.abs.divmod(1)
|
79
|
-
min, sec = (60*min).divmod(1)
|
80
|
-
sec = (60*10**round*sec).round
|
81
|
-
fig = round + 2
|
82
|
-
round.times do
|
83
|
-
div, mod = sec.divmod(10)
|
84
|
-
if mod == 0
|
85
|
-
fig -= 1
|
86
|
-
sec = div
|
87
|
-
else
|
88
|
-
break
|
89
|
-
end
|
90
|
-
end
|
91
|
-
(['N','S'].include?(dir) ? "%02d.%02d%0#{fig}d%s" : "%03d.%02d%0#{fig}d%s") % [deg, min, sec, dir]
|
92
|
-
end
|
93
|
-
|
94
|
-
#
|
95
|
-
# 剰余類
|
96
|
-
#
|
97
|
-
class Residue < When::BasicTypes::Object
|
98
|
-
|
99
|
-
LabelProperty = 'label'
|
100
|
-
|
101
|
-
class << self
|
102
|
-
#
|
103
|
-
# 曜日(剰余類)
|
104
|
-
#
|
105
|
-
# @param [Numeric] day 月曜を 0 とする七曜(剰余類)を返します
|
106
|
-
# @param [String] day 最初の3文字から決定した七曜(剰余類)を返します。
|
107
|
-
# 一致する七曜(剰余類)がない場合、名前の一致するその他の剰余類を探して返します。
|
108
|
-
#
|
109
|
-
# @return [When::Coordinates::Residue]
|
110
|
-
#
|
111
|
-
def day_of_week(day)
|
112
|
-
return day if day.kind_of?(self)
|
113
|
-
|
114
|
-
day ||= 0
|
115
|
-
week = When.Resource('_co:Common::Week')
|
116
|
-
dow = week.child
|
117
|
-
case day
|
118
|
-
when Numeric ; return dow[day]
|
119
|
-
when /\AWeek\z/ ; return week
|
120
|
-
when String ; day = When::EncodingConversion.to_internal_encoding(day)
|
121
|
-
else ; return nil
|
122
|
-
end
|
123
|
-
|
124
|
-
day, shift = day.split(':', 2)
|
125
|
-
residue = day.split('&').inject(nil) {|res,d|
|
126
|
-
r = _day_of_week(d.strip, dow)
|
127
|
-
return nil unless r
|
128
|
-
res ? res & r : r
|
129
|
-
}
|
130
|
-
return residue unless shift
|
131
|
-
shift = shift.to_i
|
132
|
-
shift -= 1 if shift > 0
|
133
|
-
residue >> shift
|
134
|
-
end
|
135
|
-
alias :to_residue :day_of_week
|
136
|
-
|
137
|
-
def _day_of_week(day, dow)
|
138
|
-
match = day[/\A...|^.{1,2}\z/]
|
139
|
-
if match
|
140
|
-
dow.size.times do |i|
|
141
|
-
return dow[i] if dow[i].label.=~(/\A#{match}/i)
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
ObjectSpace.each_object(self) do |object|
|
146
|
-
return object if object.registered? && object.label.=~(/\A#{day}\z/)
|
147
|
-
end
|
148
|
-
|
149
|
-
return nil
|
150
|
-
end
|
151
|
-
private :_day_of_week
|
152
|
-
|
153
|
-
# 汎用の mod
|
154
|
-
#
|
155
|
-
# @param [Numeric] nn 被除数
|
156
|
-
# @param [Block] dd 手続き
|
157
|
-
#
|
158
|
-
# nn = rem + dd(quot)
|
159
|
-
#
|
160
|
-
# div = dd(quot+1)-dd(quot)
|
161
|
-
#
|
162
|
-
# となるように rem, div, quot を決めたい手続き
|
163
|
-
#
|
164
|
-
# @return [Array<Numeric>] [ quot, rem, div ]
|
165
|
-
# nn を dd で「割った」商(quot), 余り(rem)および除数(div)を返します。
|
166
|
-
# remは非負、quotは Integer。
|
167
|
-
#
|
168
|
-
def mod(nn, &dd)
|
169
|
-
u = dd.call(0)
|
170
|
-
y = ((nn-u)*256).divmod(dd.call(256)-u)[0] - 1
|
171
|
-
w1, w2 = dd.call(y), dd.call(y+1)
|
172
|
-
until w1 <= nn && nn < w2
|
173
|
-
if w2 <= nn then y, w1, w2 = y+1, w2, dd.call(y+2)
|
174
|
-
else y, w1, w2 = y-1, dd.call(y-1), w1
|
175
|
-
end
|
176
|
-
end
|
177
|
-
return y, nn-w1, w2-w1
|
178
|
-
end
|
179
|
-
|
180
|
-
# 中国剰余
|
181
|
-
#
|
182
|
-
# @param [Array<Numeric>] a [ num, den ] den で割って num 余ることを示す配列
|
183
|
-
# @param [Array<Numeric>] b [ num, den ] den で割って num 余ることを示す配列
|
184
|
-
#
|
185
|
-
# @return [Array<Numeric>] a と b の条件をともに満たす [ num, den ]
|
186
|
-
#
|
187
|
-
def _china(a, b)
|
188
|
-
b, a = a, b if (a[1] <= b[1])
|
189
|
-
g, p, q = _gcd(a[1], b[1])
|
190
|
-
return [((b[0]*a[1]*q-a[0]*b[1]*p)*(a[1]*q-b[1]*p)) % (a[1]*b[1]), a[1]*b[1]] if (g == 1)
|
191
|
-
r = a[0] % g
|
192
|
-
s = b[0] % g
|
193
|
-
return nil unless (r == s)
|
194
|
-
m = _china([(a[0]-r).div(g), a[1].div(g)], [(b[0]-s).div(g), b[1].div(g)])
|
195
|
-
return nil unless (m)
|
196
|
-
return [m[0]*g+r, m[1]*g]
|
197
|
-
end
|
198
|
-
|
199
|
-
private
|
200
|
-
|
201
|
-
# 最大公約数
|
202
|
-
def _gcd(a,b)
|
203
|
-
c, x = a.divmod(b)
|
204
|
-
g = [[a, 1, 0],
|
205
|
-
[b, c, 1]]
|
206
|
-
|
207
|
-
until (x == 0) do
|
208
|
-
k = g[1][0].div(x)
|
209
|
-
g << [x, k * g[1][1] + g[0][1], k * g[1][2] + g[0][2]]
|
210
|
-
g.shift
|
211
|
-
x = g[0][0] % g[1][0]
|
212
|
-
end
|
213
|
-
|
214
|
-
return [g[1][0]] + g[0][1..2]
|
215
|
-
end
|
216
|
-
end
|
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
|
-
return
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
base.
|
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
|
-
return
|
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
|
-
# @param [
|
429
|
-
#
|
430
|
-
#
|
431
|
-
#
|
432
|
-
#
|
433
|
-
#
|
434
|
-
#
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
#
|
448
|
-
#
|
449
|
-
#
|
450
|
-
# @param [
|
451
|
-
# @param [
|
452
|
-
# @param [
|
453
|
-
# @
|
454
|
-
# @
|
455
|
-
#
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
options.
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
end
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
@
|
481
|
-
|
482
|
-
@
|
483
|
-
@
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
@carry
|
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
|
-
@count
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
#
|
606
|
-
#
|
607
|
-
#
|
608
|
-
#
|
609
|
-
#
|
610
|
-
# @param [
|
611
|
-
#
|
612
|
-
#
|
613
|
-
# @param [
|
614
|
-
#
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
first =
|
623
|
-
args[1] =
|
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
|
-
@trunk
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
@branch
|
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
|
-
return (
|
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
|
-
return trunk
|
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
|
-
form +=
|
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
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
#
|
1007
|
-
#
|
1008
|
-
#
|
1009
|
-
#
|
1010
|
-
#
|
1011
|
-
#
|
1012
|
-
# @
|
1013
|
-
#
|
1014
|
-
#
|
1015
|
-
#
|
1016
|
-
#
|
1017
|
-
# 0
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
#
|
1031
|
-
#
|
1032
|
-
#
|
1033
|
-
#
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
#
|
1043
|
-
#
|
1044
|
-
#
|
1045
|
-
#
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
#
|
1055
|
-
#
|
1056
|
-
#
|
1057
|
-
#
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
#
|
1067
|
-
#
|
1068
|
-
#
|
1069
|
-
#
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
#
|
1078
|
-
#
|
1079
|
-
#
|
1080
|
-
#
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
#
|
1090
|
-
#
|
1091
|
-
#
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
#
|
1108
|
-
#
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
#
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1136
|
-
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1141
|
-
#
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1147
|
-
#
|
1148
|
-
#
|
1149
|
-
|
1150
|
-
|
1151
|
-
#
|
1152
|
-
|
1153
|
-
|
1154
|
-
#
|
1155
|
-
#
|
1156
|
-
|
1157
|
-
|
1158
|
-
#
|
1159
|
-
|
1160
|
-
|
1161
|
-
#
|
1162
|
-
#
|
1163
|
-
|
1164
|
-
|
1165
|
-
#
|
1166
|
-
|
1167
|
-
|
1168
|
-
#
|
1169
|
-
#
|
1170
|
-
#
|
1171
|
-
#
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
#
|
1181
|
-
#
|
1182
|
-
#
|
1183
|
-
#
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
#
|
1193
|
-
#
|
1194
|
-
#
|
1195
|
-
#
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
#
|
1205
|
-
#
|
1206
|
-
#
|
1207
|
-
#
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1217
|
-
#
|
1218
|
-
#
|
1219
|
-
#
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1233
|
-
#
|
1234
|
-
#
|
1235
|
-
#
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1258
|
-
#
|
1259
|
-
#
|
1260
|
-
#
|
1261
|
-
#
|
1262
|
-
#
|
1263
|
-
#
|
1264
|
-
#
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
|
1274
|
-
#
|
1275
|
-
#
|
1276
|
-
#
|
1277
|
-
#
|
1278
|
-
#
|
1279
|
-
#
|
1280
|
-
#
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
#
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1296
|
-
|
1297
|
-
|
1298
|
-
|
1299
|
-
|
1300
|
-
#
|
1301
|
-
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1308
|
-
#
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1331
|
-
|
1332
|
-
|
1333
|
-
#
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1337
|
-
|
1338
|
-
#
|
1339
|
-
|
1340
|
-
|
1341
|
-
#
|
1342
|
-
|
1343
|
-
|
1344
|
-
# 赤道座標
|
1345
|
-
|
1346
|
-
|
1347
|
-
#
|
1348
|
-
|
1349
|
-
|
1350
|
-
#
|
1351
|
-
|
1352
|
-
|
1353
|
-
#
|
1354
|
-
|
1355
|
-
|
1356
|
-
#
|
1357
|
-
|
1358
|
-
|
1359
|
-
#
|
1360
|
-
|
1361
|
-
|
1362
|
-
#
|
1363
|
-
|
1364
|
-
|
1365
|
-
#
|
1366
|
-
|
1367
|
-
|
1368
|
-
#
|
1369
|
-
#
|
1370
|
-
|
1371
|
-
|
1372
|
-
#
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
#
|
1379
|
-
#
|
1380
|
-
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1384
|
-
#
|
1385
|
-
#
|
1386
|
-
|
1387
|
-
|
1388
|
-
#
|
1389
|
-
#
|
1390
|
-
|
1391
|
-
|
1392
|
-
#
|
1393
|
-
#
|
1394
|
-
|
1395
|
-
|
1396
|
-
#
|
1397
|
-
#
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
#
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1412
|
-
#
|
1413
|
-
|
1414
|
-
|
1415
|
-
|
1416
|
-
|
1417
|
-
|
1418
|
-
|
1419
|
-
#
|
1420
|
-
#
|
1421
|
-
# @return [
|
1422
|
-
#
|
1423
|
-
|
1424
|
-
|
1425
|
-
|
1426
|
-
|
1427
|
-
|
1428
|
-
#
|
1429
|
-
|
1430
|
-
|
1431
|
-
|
1432
|
-
|
1433
|
-
|
1434
|
-
|
1435
|
-
|
1436
|
-
|
1437
|
-
|
1438
|
-
|
1439
|
-
#
|
1440
|
-
|
1441
|
-
|
1442
|
-
#
|
1443
|
-
|
1444
|
-
|
1445
|
-
|
1446
|
-
|
1447
|
-
|
1448
|
-
|
1449
|
-
|
1450
|
-
|
1451
|
-
|
1452
|
-
#
|
1453
|
-
|
1454
|
-
|
1455
|
-
|
1456
|
-
|
1457
|
-
|
1458
|
-
|
1459
|
-
|
1460
|
-
|
1461
|
-
|
1462
|
-
|
1463
|
-
|
1464
|
-
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1468
|
-
#
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
1474
|
-
|
1475
|
-
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1486
|
-
|
1487
|
-
|
1488
|
-
|
1489
|
-
|
1490
|
-
|
1491
|
-
|
1492
|
-
|
1493
|
-
|
1494
|
-
@
|
1495
|
-
|
1496
|
-
|
1497
|
-
|
1498
|
-
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
1508
|
-
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1512
|
-
|
1513
|
-
#
|
1514
|
-
#
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1518
|
-
|
1519
|
-
|
1520
|
-
|
1521
|
-
|
1522
|
-
#
|
1523
|
-
|
1524
|
-
|
1525
|
-
|
1526
|
-
|
1527
|
-
|
1528
|
-
|
1529
|
-
|
1530
|
-
|
1531
|
-
|
1532
|
-
|
1533
|
-
|
1534
|
-
t
|
1535
|
-
|
1536
|
-
|
1537
|
-
|
1538
|
-
|
1539
|
-
|
1540
|
-
|
1541
|
-
|
1542
|
-
|
1543
|
-
|
1544
|
-
|
1545
|
-
|
1546
|
-
|
1547
|
-
|
1548
|
-
|
1549
|
-
|
1550
|
-
|
1551
|
-
|
1552
|
-
|
1553
|
-
|
1554
|
-
|
1555
|
-
|
1556
|
-
|
1557
|
-
|
1558
|
-
|
1559
|
-
|
1560
|
-
|
1561
|
-
|
1562
|
-
|
1563
|
-
|
1564
|
-
|
1565
|
-
|
1566
|
-
#
|
1567
|
-
#
|
1568
|
-
|
1569
|
-
#
|
1570
|
-
#
|
1571
|
-
|
1572
|
-
#
|
1573
|
-
#
|
1574
|
-
|
1575
|
-
#
|
1576
|
-
#
|
1577
|
-
|
1578
|
-
|
1579
|
-
|
1580
|
-
|
1581
|
-
|
1582
|
-
|
1583
|
-
|
1584
|
-
|
1585
|
-
|
1586
|
-
|
1587
|
-
|
1588
|
-
|
1589
|
-
|
1590
|
-
|
1591
|
-
|
1592
|
-
|
1593
|
-
|
1594
|
-
|
1595
|
-
|
1596
|
-
|
1597
|
-
|
1598
|
-
|
1599
|
-
|
1600
|
-
|
1601
|
-
|
1602
|
-
|
1603
|
-
|
1604
|
-
|
1605
|
-
|
1606
|
-
|
1607
|
-
|
1608
|
-
|
1609
|
-
|
1610
|
-
|
1611
|
-
|
1612
|
-
|
1613
|
-
|
1614
|
-
|
1615
|
-
|
1616
|
-
|
1617
|
-
|
1618
|
-
|
1619
|
-
|
1620
|
-
|
1621
|
-
|
1622
|
-
|
1623
|
-
|
1624
|
-
|
1625
|
-
|
1626
|
-
#
|
1627
|
-
|
1628
|
-
|
1629
|
-
|
1630
|
-
|
1631
|
-
|
1632
|
-
#
|
1633
|
-
|
1634
|
-
|
1635
|
-
#
|
1636
|
-
|
1637
|
-
|
1638
|
-
#
|
1639
|
-
|
1640
|
-
|
1641
|
-
#
|
1642
|
-
|
1643
|
-
|
1644
|
-
#
|
1645
|
-
|
1646
|
-
|
1647
|
-
#
|
1648
|
-
|
1649
|
-
|
1650
|
-
#
|
1651
|
-
#
|
1652
|
-
#
|
1653
|
-
#
|
1654
|
-
|
1655
|
-
|
1656
|
-
|
1657
|
-
#
|
1658
|
-
#
|
1659
|
-
#
|
1660
|
-
#
|
1661
|
-
#
|
1662
|
-
#
|
1663
|
-
#
|
1664
|
-
|
1665
|
-
|
1666
|
-
#
|
1667
|
-
#
|
1668
|
-
|
1669
|
-
|
1670
|
-
#
|
1671
|
-
#
|
1672
|
-
#
|
1673
|
-
#
|
1674
|
-
#
|
1675
|
-
#
|
1676
|
-
#
|
1677
|
-
|
1678
|
-
|
1679
|
-
|
1680
|
-
#
|
1681
|
-
#
|
1682
|
-
#
|
1683
|
-
#
|
1684
|
-
#
|
1685
|
-
#
|
1686
|
-
#
|
1687
|
-
|
1688
|
-
|
1689
|
-
#
|
1690
|
-
#
|
1691
|
-
|
1692
|
-
|
1693
|
-
|
1694
|
-
|
1695
|
-
|
1696
|
-
|
1697
|
-
|
1698
|
-
|
1699
|
-
#
|
1700
|
-
|
1701
|
-
|
1702
|
-
|
1703
|
-
|
1704
|
-
|
1705
|
-
|
1706
|
-
|
1707
|
-
|
1708
|
-
#
|
1709
|
-
#
|
1710
|
-
#
|
1711
|
-
#
|
1712
|
-
#
|
1713
|
-
# @
|
1714
|
-
#
|
1715
|
-
#
|
1716
|
-
#
|
1717
|
-
|
1718
|
-
|
1719
|
-
|
1720
|
-
|
1721
|
-
#
|
1722
|
-
#
|
1723
|
-
#
|
1724
|
-
#
|
1725
|
-
#
|
1726
|
-
|
1727
|
-
|
1728
|
-
|
1729
|
-
|
1730
|
-
|
1731
|
-
|
1732
|
-
|
1733
|
-
|
1734
|
-
# @
|
1735
|
-
#
|
1736
|
-
|
1737
|
-
|
1738
|
-
|
1739
|
-
|
1740
|
-
|
1741
|
-
|
1742
|
-
|
1743
|
-
#
|
1744
|
-
#
|
1745
|
-
#
|
1746
|
-
|
1747
|
-
|
1748
|
-
|
1749
|
-
|
1750
|
-
|
1751
|
-
|
1752
|
-
|
1753
|
-
|
1754
|
-
|
1755
|
-
|
1756
|
-
|
1757
|
-
|
1758
|
-
|
1759
|
-
|
1760
|
-
|
1761
|
-
|
1762
|
-
|
1763
|
-
|
1764
|
-
|
1765
|
-
|
1766
|
-
|
1767
|
-
|
1768
|
-
|
1769
|
-
|
1770
|
-
|
1771
|
-
|
1772
|
-
|
1773
|
-
|
1774
|
-
|
1775
|
-
|
1776
|
-
|
1777
|
-
|
1778
|
-
|
1779
|
-
|
1780
|
-
|
1781
|
-
|
1782
|
-
|
1783
|
-
|
1784
|
-
|
1785
|
-
|
1786
|
-
|
1787
|
-
|
1788
|
-
|
1789
|
-
|
1790
|
-
|
1791
|
-
|
1792
|
-
|
1793
|
-
|
1794
|
-
(@
|
1795
|
-
|
1796
|
-
|
1797
|
-
|
1798
|
-
|
1799
|
-
|
1800
|
-
|
1801
|
-
|
1802
|
-
|
1803
|
-
|
1804
|
-
|
1805
|
-
|
1806
|
-
|
1807
|
-
|
1808
|
-
|
1809
|
-
|
1810
|
-
|
1811
|
-
|
1812
|
-
|
1813
|
-
|
1814
|
-
|
1815
|
-
|
1816
|
-
coord[i]
|
1817
|
-
end
|
1818
|
-
|
1819
|
-
|
1820
|
-
|
1821
|
-
|
1822
|
-
|
1823
|
-
|
1824
|
-
|
1825
|
-
|
1826
|
-
|
1827
|
-
|
1828
|
-
|
1829
|
-
|
1830
|
-
|
1831
|
-
|
1832
|
-
|
1833
|
-
|
1834
|
-
|
1835
|
-
|
1836
|
-
|
1837
|
-
|
1838
|
-
|
1839
|
-
|
1840
|
-
|
1841
|
-
|
1842
|
-
|
1843
|
-
|
1844
|
-
|
1845
|
-
|
1846
|
-
|
1847
|
-
|
1848
|
-
|
1849
|
-
|
1850
|
-
|
1851
|
-
|
1852
|
-
|
1853
|
-
|
1854
|
-
|
1855
|
-
|
1856
|
-
|
1857
|
-
|
1858
|
-
|
1859
|
-
|
1860
|
-
|
1861
|
-
date
|
1862
|
-
|
1863
|
-
|
1864
|
-
|
1865
|
-
|
1866
|
-
|
1867
|
-
|
1868
|
-
|
1869
|
-
|
1870
|
-
|
1871
|
-
|
1872
|
-
|
1873
|
-
|
1874
|
-
|
1875
|
-
|
1876
|
-
|
1877
|
-
|
1878
|
-
|
1879
|
-
|
1880
|
-
|
1881
|
-
|
1882
|
-
|
1883
|
-
|
1884
|
-
|
1885
|
-
|
1886
|
-
|
1887
|
-
|
1888
|
-
|
1889
|
-
|
1890
|
-
|
1891
|
-
|
1892
|
-
|
1893
|
-
|
1894
|
-
|
1895
|
-
|
1896
|
-
|
1897
|
-
|
1898
|
-
|
1899
|
-
|
1900
|
-
|
1901
|
-
|
1902
|
-
|
1903
|
-
|
1904
|
-
|
1905
|
-
|
1906
|
-
|
1907
|
-
|
1908
|
-
|
1909
|
-
|
1910
|
-
|
1911
|
-
|
1912
|
-
|
1913
|
-
|
1914
|
-
|
1915
|
-
|
1916
|
-
|
1917
|
-
|
1918
|
-
|
1919
|
-
|
1920
|
-
|
1921
|
-
|
1922
|
-
|
1923
|
-
|
1924
|
-
#
|
1925
|
-
#
|
1926
|
-
#
|
1927
|
-
#
|
1928
|
-
#
|
1929
|
-
|
1930
|
-
|
1931
|
-
|
1932
|
-
|
1933
|
-
#
|
1934
|
-
#
|
1935
|
-
#
|
1936
|
-
#
|
1937
|
-
|
1938
|
-
#
|
1939
|
-
|
1940
|
-
#
|
1941
|
-
#
|
1942
|
-
#
|
1943
|
-
#
|
1944
|
-
#
|
1945
|
-
#
|
1946
|
-
|
1947
|
-
|
1948
|
-
|
1949
|
-
|
1950
|
-
|
1951
|
-
|
1952
|
-
|
1953
|
-
|
1954
|
-
|
1955
|
-
|
1956
|
-
|
1957
|
-
|
1958
|
-
|
1959
|
-
|
1960
|
-
|
1961
|
-
|
1962
|
-
@
|
1963
|
-
|
1964
|
-
|
1965
|
-
@
|
1966
|
-
|
1967
|
-
|
1968
|
-
|
1969
|
-
|
1970
|
-
@
|
1971
|
-
@index_of_MSC
|
1972
|
-
|
1973
|
-
|
1974
|
-
|
1975
|
-
|
1976
|
-
|
1977
|
-
|
1978
|
-
|
1979
|
-
@
|
1980
|
-
|
1981
|
-
|
1982
|
-
@
|
1983
|
-
end
|
1984
|
-
|
1985
|
-
|
1986
|
-
|
1987
|
-
@
|
1988
|
-
|
1989
|
-
|
1990
|
-
|
1991
|
-
|
1992
|
-
|
1993
|
-
|
1994
|
-
|
1995
|
-
|
1996
|
-
|
1997
|
-
|
1998
|
-
|
1999
|
-
|
2000
|
-
|
2001
|
-
|
2002
|
-
|
2003
|
-
|
2004
|
-
|
2005
|
-
|
2006
|
-
|
2007
|
-
|
2008
|
-
|
2009
|
-
|
2010
|
-
|
2011
|
-
|
2012
|
-
|
2013
|
-
#
|
2014
|
-
|
2015
|
-
|
2016
|
-
|
2017
|
-
|
2018
|
-
|
2019
|
-
|
2020
|
-
|
2021
|
-
|
2022
|
-
|
2023
|
-
|
2024
|
-
|
2025
|
-
|
2026
|
-
|
2027
|
-
|
2028
|
-
|
2029
|
-
|
2030
|
-
|
2031
|
-
|
2032
|
-
|
2033
|
-
|
2034
|
-
|
2035
|
-
|
2036
|
-
|
2037
|
-
|
2038
|
-
|
2039
|
-
|
2040
|
-
|
2041
|
-
|
2042
|
-
|
2043
|
-
|
2044
|
-
|
2045
|
-
|
2046
|
-
|
2047
|
-
|
2048
|
-
|
2049
|
-
|
2050
|
-
|
2051
|
-
|
2052
|
-
|
2053
|
-
|
2054
|
-
|
2055
|
-
|
2056
|
-
|
2057
|
-
|
2058
|
-
|
2059
|
-
|
2060
|
-
|
2061
|
-
|
2062
|
-
|
2063
|
-
|
2064
|
-
|
2065
|
-
|
2066
|
-
|
2067
|
-
|
2068
|
-
#
|
2069
|
-
|
2070
|
-
|
2071
|
-
|
2072
|
-
|
2073
|
-
|
2074
|
-
|
2075
|
-
|
2076
|
-
|
2077
|
-
|
2078
|
-
|
2079
|
-
|
2080
|
-
|
2081
|
-
|
2082
|
-
|
2083
|
-
|
2084
|
-
|
2085
|
-
|
2086
|
-
|
2087
|
-
|
2088
|
-
|
2089
|
-
|
2090
|
-
|
2091
|
-
|
2092
|
-
|
2093
|
-
|
2094
|
-
|
2095
|
-
|
2096
|
-
|
2097
|
-
|
2098
|
-
|
2099
|
-
|
2100
|
-
|
2101
|
-
|
2102
|
-
|
2103
|
-
|
2104
|
-
|
2105
|
-
|
2106
|
-
|
2107
|
-
|
2108
|
-
|
2109
|
-
|
2110
|
-
|
2111
|
-
|
2112
|
-
|
2113
|
-
|
2114
|
-
|
2115
|
-
|
2116
|
-
|
2117
|
-
|
2118
|
-
|
2119
|
-
|
2120
|
-
|
2121
|
-
|
2122
|
-
|
2123
|
-
|
2124
|
-
|
2125
|
-
|
2126
|
-
|
2127
|
-
|
2128
|
-
|
2129
|
-
|
2130
|
-
|
2131
|
-
|
2132
|
-
#
|
2133
|
-
#
|
2134
|
-
#
|
2135
|
-
|
2136
|
-
|
2137
|
-
|
2138
|
-
|
2139
|
-
|
2140
|
-
|
2141
|
-
|
2142
|
-
|
2143
|
-
|
2144
|
-
|
2145
|
-
|
2146
|
-
|
2147
|
-
|
2148
|
-
|
2149
|
-
|
2150
|
-
|
2151
|
-
|
2152
|
-
|
2153
|
-
|
2154
|
-
|
2155
|
-
|
2156
|
-
|
2157
|
-
|
2158
|
-
|
2159
|
-
|
2160
|
-
|
2161
|
-
|
2162
|
-
|
2163
|
-
|
2164
|
-
|
2165
|
-
|
2166
|
-
|
2167
|
-
|
2168
|
-
|
2169
|
-
|
2170
|
-
|
2171
|
-
|
2172
|
-
|
2173
|
-
|
2174
|
-
|
2175
|
-
|
2176
|
-
|
2177
|
-
|
2178
|
-
|
2179
|
-
|
2180
|
-
|
2181
|
-
|
2182
|
-
|
2183
|
-
|
2184
|
-
|
2185
|
-
|
2186
|
-
|
2187
|
-
|
2188
|
-
|
2189
|
-
|
2190
|
-
|
2191
|
-
|
2192
|
-
|
2193
|
-
|
2194
|
-
|
2195
|
-
|
2196
|
-
|
2197
|
-
|
2198
|
-
|
2199
|
-
|
2200
|
-
|
2201
|
-
#
|
2202
|
-
#
|
2203
|
-
#
|
2204
|
-
#
|
2205
|
-
#
|
2206
|
-
|
2207
|
-
|
2208
|
-
|
2209
|
-
|
2210
|
-
|
2211
|
-
|
2212
|
-
|
2213
|
-
|
2214
|
-
|
2215
|
-
|
2216
|
-
|
2217
|
-
|
2218
|
-
|
2219
|
-
|
2220
|
-
|
2221
|
-
|
2222
|
-
|
2223
|
-
|
2224
|
-
|
2225
|
-
|
2226
|
-
|
2227
|
-
|
2228
|
-
|
2229
|
-
|
2230
|
-
|
2231
|
-
|
2232
|
-
|
2233
|
-
|
2234
|
-
|
2235
|
-
|
2236
|
-
|
2237
|
-
|
2238
|
-
|
2239
|
-
|
2240
|
-
|
2241
|
-
|
2242
|
-
|
2243
|
-
|
2244
|
-
|
2245
|
-
|
2246
|
-
|
2247
|
-
|
2248
|
-
|
2249
|
-
|
2250
|
-
|
2251
|
-
|
2252
|
-
|
2253
|
-
|
2254
|
-
|
2255
|
-
|
2256
|
-
|
2257
|
-
|
2258
|
-
|
2259
|
-
|
2260
|
-
|
2261
|
-
#
|
2262
|
-
#
|
2263
|
-
#
|
2264
|
-
|
2265
|
-
|
2266
|
-
|
2267
|
-
|
2268
|
-
|
2269
|
-
|
2270
|
-
#
|
2271
|
-
#
|
2272
|
-
#
|
2273
|
-
#
|
2274
|
-
#
|
2275
|
-
|
2276
|
-
|
2277
|
-
|
2278
|
-
|
2279
|
-
|
2280
|
-
|
2281
|
-
|
2282
|
-
|
2283
|
-
|
2284
|
-
|
2285
|
-
|
2286
|
-
|
2287
|
-
|
2288
|
-
|
2289
|
-
|
2290
|
-
|
2291
|
-
|
2292
|
-
|
2293
|
-
|
2294
|
-
|
2295
|
-
|
2296
|
-
|
2297
|
-
|
2298
|
-
|
2299
|
-
|
2300
|
-
|
2301
|
-
|
2302
|
-
|
2303
|
-
|
2304
|
-
|
2305
|
-
|
2306
|
-
|
2307
|
-
|
2308
|
-
|
2309
|
-
|
2310
|
-
|
2311
|
-
|
2312
|
-
|
2313
|
-
|
2314
|
-
|
2315
|
-
|
2316
|
-
|
2317
|
-
|
2318
|
-
|
2319
|
-
|
2320
|
-
|
2321
|
-
|
2322
|
-
|
2323
|
-
|
2324
|
-
|
2325
|
-
|
2326
|
-
|
2327
|
-
|
2328
|
-
|
2329
|
-
|
2330
|
-
|
2331
|
-
|
2332
|
-
|
2333
|
-
|
2334
|
-
|
2335
|
-
|
2336
|
-
|
2337
|
-
|
2338
|
-
|
2339
|
-
|
2340
|
-
|
2341
|
-
|
2342
|
-
|
2343
|
-
|
2344
|
-
|
2345
|
-
|
2346
|
-
|
2347
|
-
|
2348
|
-
|
2349
|
-
|
2350
|
-
|
2351
|
-
|
2352
|
-
|
2353
|
-
|
2354
|
-
|
2355
|
-
|
2356
|
-
|
2357
|
-
|
2358
|
-
|
2359
|
-
|
2360
|
-
|
2361
|
-
|
2362
|
-
|
2363
|
-
|
2364
|
-
|
2365
|
-
|
2366
|
-
|
2367
|
-
|
2368
|
-
end
|
2369
|
-
|
2370
|
-
|
2371
|
-
|
2372
|
-
|
2373
|
-
|
2374
|
-
|
2375
|
-
|
2376
|
-
|
2377
|
-
|
2378
|
-
|
2379
|
-
|
2380
|
-
|
2381
|
-
|
2382
|
-
|
2383
|
-
|
2384
|
-
|
2385
|
-
|
2386
|
-
|
2387
|
-
|
2388
|
-
|
2389
|
-
|
2390
|
-
|
2391
|
-
|
2392
|
-
|
2393
|
-
|
2394
|
-
|
2395
|
-
|
2396
|
-
|
2397
|
-
time
|
2398
|
-
|
2399
|
-
|
2400
|
-
|
2401
|
-
|
2402
|
-
|
2403
|
-
|
2404
|
-
|
2405
|
-
|
2406
|
-
|
2407
|
-
|
2408
|
-
|
2409
|
-
|
2410
|
-
|
2411
|
-
|
2412
|
-
|
2413
|
-
|
2414
|
-
|
2415
|
-
|
2416
|
-
|
2417
|
-
|
2418
|
-
|
2419
|
-
|
2420
|
-
|
2421
|
-
|
2422
|
-
|
2423
|
-
|
2424
|
-
|
2425
|
-
|
2426
|
-
|
2427
|
-
|
2428
|
-
|
2429
|
-
|
2430
|
-
|
2431
|
-
|
2432
|
-
|
2433
|
-
|
2434
|
-
|
2435
|
-
|
2436
|
-
|
2437
|
-
|
2438
|
-
|
2439
|
-
# 要素の正規化
|
2440
|
-
def _normalize(args=[], options={})
|
2441
|
-
@border = [When::Coordinates::Pair.new(+1,-1),0,0,0]
|
2442
|
-
@event = +1
|
2443
|
-
@height ||= '0'
|
2444
|
-
end
|
2445
|
-
end
|
2446
|
-
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
|
+
#
|
9
|
+
# 座標の記述に用いる諸オブジェクト
|
10
|
+
#
|
11
|
+
module When::Coordinates
|
12
|
+
# 変換テーブル
|
13
|
+
PRECISION = {'YEAR'=>When::YEAR, 'MONTH' =>When::MONTH, 'WEEK' =>When::WEEK, 'DAY' =>When::DAY,
|
14
|
+
'HOUR'=>When::HOUR, 'MINUTE'=>When::MINUTE, 'SECOND'=>When::SECOND, 'SYSTEM'=>When::SYSTEM}
|
15
|
+
PERIOD = {'P1Y' =>When::YEAR, 'P1M' =>When::MONTH, 'P1W' =>When::WEEK, 'P1D' =>When::DAY,
|
16
|
+
'PT1H'=>When::HOUR, 'PT1M' =>When::MINUTE, 'PT1S' =>When::SECOND,
|
17
|
+
'1Y' =>When::YEAR, '1M' =>When::MONTH, '1W' =>When::WEEK, '1D' =>When::DAY,
|
18
|
+
'1h' =>When::HOUR, '1m' =>When::MINUTE, '1s' =>When::SECOND}
|
19
|
+
VALUE = {'DATE'=>When::DAY, 'TIME' =>When::SYSTEM, 'DATE-TIME'=>When::SYSTEM} # RFC 5545
|
20
|
+
PRECISION_NAME = PRECISION.invert
|
21
|
+
PERIOD_NAME = {When::YEAR=>'P1Y' , When::MONTH=>'P1M', When::WEEK =>'P1W', When::DAY=>'P1D',
|
22
|
+
When::HOUR=>'PT1H', When::MINUTE=>'PT1M', When::SECOND=>'PT1S'}
|
23
|
+
MATCH = {'NS'=>/(N|S|北緯|南緯)/, 'EW'=>/(E|W|東経|西経)/}
|
24
|
+
|
25
|
+
# 60進->10進変換(1/225度単位)
|
26
|
+
#
|
27
|
+
# @param [String] src 60進法で表した方向付きの数値
|
28
|
+
# @param [String] dir 方向 ('NS' または 'EW')
|
29
|
+
#
|
30
|
+
# @return [Numeric] 10進変換した数値 (src が nil なら0.0を、Numeric なら 225*src を返す)
|
31
|
+
#
|
32
|
+
def self.to_deg_225(src, dir)
|
33
|
+
case src
|
34
|
+
when String
|
35
|
+
src = src.gsub(/_+/,'').gsub(/@/, '.')
|
36
|
+
return src.to_r * Spatial::DEGREE if (src =~ /E[-+]/ || src !~ MATCH[dir])
|
37
|
+
sign = ($1 == dir[1..1]) ? -1 : +1
|
38
|
+
value = src.gsub(MATCH[dir], '').strip
|
39
|
+
if ((value + "00000") =~ /\A(\d+)\.(\d{2})(\d{2})(\d+)\z/)
|
40
|
+
deg, min, sec, frac = $~[1..4]
|
41
|
+
sec += "." + frac
|
42
|
+
else
|
43
|
+
deg, min, sec = value.split(/[^\d.]+/)
|
44
|
+
end
|
45
|
+
return sign * (deg.to_i * Spatial::DEGREE +
|
46
|
+
(min||0).to_f * (Spatial::DEGREE/60.0) +
|
47
|
+
(sec||0).to_f * (Spatial::DEGREE/3600.0))
|
48
|
+
when NilClass
|
49
|
+
0.0
|
50
|
+
when Numeric
|
51
|
+
src * Spatial::DEGREE
|
52
|
+
else
|
53
|
+
raise TypeError, "Invalid Location Type"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# 60進->10進変換(度単位)
|
58
|
+
#
|
59
|
+
# @param [String] src 60進法で表した方向付きの数値
|
60
|
+
# @param [String] dir 方向 ('NS' または 'EW')
|
61
|
+
#
|
62
|
+
# @return [Numeric] 10進変換した数値 (src が nil なら0.0を、Numeric ならそのままsrcを返す)
|
63
|
+
#
|
64
|
+
def self.to_deg(src, dir)
|
65
|
+
to_deg_225(src, dir) / Spatial::DEGREE
|
66
|
+
end
|
67
|
+
|
68
|
+
# 10進->60進変換
|
69
|
+
#
|
70
|
+
# @param [Numeric] src 数値
|
71
|
+
# @param [String] dir 方向 ('NS' または 'EW')
|
72
|
+
# @param [Integer] round 秒の小数点以下最大桁数
|
73
|
+
#
|
74
|
+
# @return [String] 60進変換した数値
|
75
|
+
#
|
76
|
+
def self.to_dms(src, dir, round=6)
|
77
|
+
dir = (src >= 0) ? dir[0..0] : dir[1..1]
|
78
|
+
deg, min = src.abs.divmod(1)
|
79
|
+
min, sec = (60*min).divmod(1)
|
80
|
+
sec = (60*10**round*sec).round
|
81
|
+
fig = round + 2
|
82
|
+
round.times do
|
83
|
+
div, mod = sec.divmod(10)
|
84
|
+
if mod == 0
|
85
|
+
fig -= 1
|
86
|
+
sec = div
|
87
|
+
else
|
88
|
+
break
|
89
|
+
end
|
90
|
+
end
|
91
|
+
(['N','S'].include?(dir) ? "%02d.%02d%0#{fig}d%s" : "%03d.%02d%0#{fig}d%s") % [deg, min, sec, dir]
|
92
|
+
end
|
93
|
+
|
94
|
+
#
|
95
|
+
# 剰余類
|
96
|
+
#
|
97
|
+
class Residue < When::BasicTypes::Object
|
98
|
+
|
99
|
+
LabelProperty = 'label'
|
100
|
+
|
101
|
+
class << self
|
102
|
+
#
|
103
|
+
# 曜日(剰余類)
|
104
|
+
#
|
105
|
+
# @param [Numeric] day 月曜を 0 とする七曜(剰余類)を返します
|
106
|
+
# @param [String] day 最初の3文字から決定した七曜(剰余類)を返します。
|
107
|
+
# 一致する七曜(剰余類)がない場合、名前の一致するその他の剰余類を探して返します。
|
108
|
+
#
|
109
|
+
# @return [When::Coordinates::Residue]
|
110
|
+
#
|
111
|
+
def day_of_week(day)
|
112
|
+
return day if day.kind_of?(self)
|
113
|
+
|
114
|
+
day ||= 0
|
115
|
+
week = When.Resource('_co:Common::Week')
|
116
|
+
dow = week.child
|
117
|
+
case day
|
118
|
+
when Numeric ; return dow[day]
|
119
|
+
when /\AWeek\z/ ; return week
|
120
|
+
when String ; day = When::EncodingConversion.to_internal_encoding(day)
|
121
|
+
else ; return nil
|
122
|
+
end
|
123
|
+
|
124
|
+
day, shift = day.split(':', 2)
|
125
|
+
residue = day.split('&').inject(nil) {|res,d|
|
126
|
+
r = _day_of_week(d.strip, dow)
|
127
|
+
return nil unless r
|
128
|
+
res ? res & r : r
|
129
|
+
}
|
130
|
+
return residue unless shift
|
131
|
+
shift = shift.to_i
|
132
|
+
shift -= 1 if shift > 0
|
133
|
+
residue >> shift
|
134
|
+
end
|
135
|
+
alias :to_residue :day_of_week
|
136
|
+
|
137
|
+
def _day_of_week(day, dow)
|
138
|
+
match = day[/\A...|^.{1,2}\z/]
|
139
|
+
if match
|
140
|
+
dow.size.times do |i|
|
141
|
+
return dow[i] if dow[i].label.=~(/\A#{match}/i)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
ObjectSpace.each_object(self) do |object|
|
146
|
+
return object if object.registered? && object.label.=~(/\A#{day}\z/)
|
147
|
+
end
|
148
|
+
|
149
|
+
return nil
|
150
|
+
end
|
151
|
+
private :_day_of_week
|
152
|
+
|
153
|
+
# 汎用の mod
|
154
|
+
#
|
155
|
+
# @param [Numeric] nn 被除数
|
156
|
+
# @param [Block] dd 手続き
|
157
|
+
#
|
158
|
+
# nn = rem + dd(quot)
|
159
|
+
#
|
160
|
+
# div = dd(quot+1)-dd(quot)
|
161
|
+
#
|
162
|
+
# となるように rem, div, quot を決めたい手続き
|
163
|
+
#
|
164
|
+
# @return [Array<Numeric>] [ quot, rem, div ]
|
165
|
+
# nn を dd で「割った」商(quot), 余り(rem)および除数(div)を返します。
|
166
|
+
# remは非負、quotは Integer。
|
167
|
+
#
|
168
|
+
def mod(nn, &dd)
|
169
|
+
u = dd.call(0)
|
170
|
+
y = ((nn-u)*256).divmod(dd.call(256)-u)[0] - 1
|
171
|
+
w1, w2 = dd.call(y), dd.call(y+1)
|
172
|
+
until w1 <= nn && nn < w2
|
173
|
+
if w2 <= nn then y, w1, w2 = y+1, w2, dd.call(y+2)
|
174
|
+
else y, w1, w2 = y-1, dd.call(y-1), w1
|
175
|
+
end
|
176
|
+
end
|
177
|
+
return y, nn-w1, w2-w1
|
178
|
+
end
|
179
|
+
|
180
|
+
# 中国剰余
|
181
|
+
#
|
182
|
+
# @param [Array<Numeric>] a [ num, den ] den で割って num 余ることを示す配列
|
183
|
+
# @param [Array<Numeric>] b [ num, den ] den で割って num 余ることを示す配列
|
184
|
+
#
|
185
|
+
# @return [Array<Numeric>] a と b の条件をともに満たす [ num, den ]
|
186
|
+
#
|
187
|
+
def _china(a, b)
|
188
|
+
b, a = a, b if (a[1] <= b[1])
|
189
|
+
g, p, q = _gcd(a[1], b[1])
|
190
|
+
return [((b[0]*a[1]*q-a[0]*b[1]*p)*(a[1]*q-b[1]*p)) % (a[1]*b[1]), a[1]*b[1]] if (g == 1)
|
191
|
+
r = a[0] % g
|
192
|
+
s = b[0] % g
|
193
|
+
return nil unless (r == s)
|
194
|
+
m = _china([(a[0]-r).div(g), a[1].div(g)], [(b[0]-s).div(g), b[1].div(g)])
|
195
|
+
return nil unless (m)
|
196
|
+
return [m[0]*g+r, m[1]*g]
|
197
|
+
end
|
198
|
+
|
199
|
+
private
|
200
|
+
|
201
|
+
# 最大公約数
|
202
|
+
def _gcd(a,b)
|
203
|
+
c, x = a.divmod(b)
|
204
|
+
g = [[a, 1, 0],
|
205
|
+
[b, c, 1]]
|
206
|
+
|
207
|
+
until (x == 0) do
|
208
|
+
k = g[1][0].div(x)
|
209
|
+
g << [x, k * g[1][1] + g[0][1], k * g[1][2] + g[0][2]]
|
210
|
+
g.shift
|
211
|
+
x = g[0][0] % g[1][0]
|
212
|
+
end
|
213
|
+
|
214
|
+
return [g[1][0]] + g[0][1..2]
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
# @private
|
219
|
+
HashProperty = [:label, :remainder, :divisor]
|
220
|
+
|
221
|
+
# 剰余
|
222
|
+
#
|
223
|
+
# @return [Numeric]
|
224
|
+
#
|
225
|
+
attr_accessor :remainder
|
226
|
+
protected :remainder=
|
227
|
+
|
228
|
+
# 法
|
229
|
+
#
|
230
|
+
# @return [Integer] (>0)
|
231
|
+
#
|
232
|
+
attr_reader :divisor
|
233
|
+
|
234
|
+
# 繰り上がり
|
235
|
+
#
|
236
|
+
# @return [Integer]
|
237
|
+
#
|
238
|
+
attr_accessor :carry
|
239
|
+
protected :carry=
|
240
|
+
|
241
|
+
# 単位
|
242
|
+
#
|
243
|
+
# @return [Hash] { String=>Numeric }
|
244
|
+
#
|
245
|
+
# Example : { 'day'=>11, 'year'=4 }
|
246
|
+
#
|
247
|
+
# 通日に適用するときは、11 ずらして計算 - 甲子日 = ユリウス日 11 + 60n
|
248
|
+
#
|
249
|
+
# 通年に適用するときは、 4 ずらして計算 - 甲子年 = 西暦 4 + 60n
|
250
|
+
#
|
251
|
+
attr_reader :units
|
252
|
+
|
253
|
+
# units の指定
|
254
|
+
#
|
255
|
+
# @param [String] arg あらかじめ units に指定した単位を用いる
|
256
|
+
#
|
257
|
+
# @return [When::Coordinates::Residue]
|
258
|
+
#
|
259
|
+
def to(arg)
|
260
|
+
return nil unless @units[arg]
|
261
|
+
self.class.new(@remainder, @divisor, @carry, {arg=>@units[arg]})
|
262
|
+
end
|
263
|
+
alias :/ :to
|
264
|
+
|
265
|
+
# オブジェクトの単位
|
266
|
+
#
|
267
|
+
# @return [String] 現在使用中の単位を返す
|
268
|
+
#
|
269
|
+
def event
|
270
|
+
keys = @units.keys
|
271
|
+
return (keys.size == 1) ? keys[0] : 'day'
|
272
|
+
end
|
273
|
+
|
274
|
+
# remainder の指定
|
275
|
+
#
|
276
|
+
# @param [Numeric] remainder 指定値を@remainderとする
|
277
|
+
# @param [String] remainder When::Parts::Resource の has-a 関係によりString に対応する子供オブジェクトを取得
|
278
|
+
#
|
279
|
+
# @return [When::Coordinates::Residue]
|
280
|
+
#
|
281
|
+
def [](remainder)
|
282
|
+
return super if !remainder.kind_of?(Numeric) || (child && child.length == @divisor)
|
283
|
+
return self if remainder == 0 && !child
|
284
|
+
remainder *= 1
|
285
|
+
return self.class.new(@remainder+remainder, @divisor, @carry, @label, @format, @units) unless (child && child.length > 0)
|
286
|
+
carry, remainder = (@remainder+remainder).divmod(@divisor)
|
287
|
+
base = child.reverse.each do |residue|
|
288
|
+
break residue if residue.remainder <= remainder
|
289
|
+
end
|
290
|
+
raise ArgumentError, "remainder out of range: #{remainder}" unless base.kind_of?(self.class)
|
291
|
+
base = base.dup
|
292
|
+
base.remainder = remainder
|
293
|
+
base.carry += carry
|
294
|
+
return base
|
295
|
+
end
|
296
|
+
|
297
|
+
# 典型的なイベントの発生間隔
|
298
|
+
#
|
299
|
+
# @param [String] event
|
300
|
+
#
|
301
|
+
# @return [When::TM::PeriodDuration]
|
302
|
+
#
|
303
|
+
def duration(event=self.event)
|
304
|
+
When::TM::PeriodDuration.new(@divisor, When::Coordinates::PRECISION[event.upcase])
|
305
|
+
end
|
306
|
+
|
307
|
+
# 派生オブジェクトと元オブジェクトの remainder の差
|
308
|
+
# (派生オブジェクトとは、元オブジェクトに[]演算を施して @remainder を変えたオブジェクト)
|
309
|
+
#
|
310
|
+
# @return [Integer]
|
311
|
+
#
|
312
|
+
# 派生オブジェクトでない場合 : 自身の remainder
|
313
|
+
#
|
314
|
+
# 派生オブジェクトである場合 : 派生オブジェクトと元オブジェクトの remainder の差
|
315
|
+
#
|
316
|
+
def difference
|
317
|
+
@difference ||= (registered? || iri !~ /:/) ? @remainder : @remainder - When.Resource(iri).remainder
|
318
|
+
end
|
319
|
+
|
320
|
+
# remainderの加算
|
321
|
+
#
|
322
|
+
# other : Numeric
|
323
|
+
#
|
324
|
+
# @return [When::Coordinates::Residue]
|
325
|
+
#
|
326
|
+
def +(other)
|
327
|
+
carry, remainder = (@remainder + other).divmod(@divisor)
|
328
|
+
return self.class.new(remainder, @divisor, @carry+carry, @units)
|
329
|
+
end
|
330
|
+
|
331
|
+
# remainderの減算
|
332
|
+
#
|
333
|
+
# @param [Numeric] other
|
334
|
+
#
|
335
|
+
# @return [When::Coordinates::Residue]
|
336
|
+
#
|
337
|
+
def -(other)
|
338
|
+
carry, remainder = (@remainder - other).divmod(@divisor)
|
339
|
+
return self.class.new(remainder, @divisor, @carry+carry, @units)
|
340
|
+
end
|
341
|
+
|
342
|
+
# carryの加算
|
343
|
+
#
|
344
|
+
# @param [Numeric] other
|
345
|
+
#
|
346
|
+
# @return [When::Coordinates::Residue]
|
347
|
+
#
|
348
|
+
def >>(other)
|
349
|
+
return self.class.new(@remainder, @divisor, @carry+other, @units)
|
350
|
+
end
|
351
|
+
|
352
|
+
# carryの減算
|
353
|
+
#
|
354
|
+
# @param [Numeric] other
|
355
|
+
#
|
356
|
+
# @return [When::Coordinates::Residue]
|
357
|
+
#
|
358
|
+
def <<(other)
|
359
|
+
return self.class.new(@remainder, @divisor, @carry-other, @units)
|
360
|
+
end
|
361
|
+
|
362
|
+
# 剰余類の共通集合
|
363
|
+
#
|
364
|
+
# @param [When::Coordinates::Residue] other
|
365
|
+
#
|
366
|
+
# @return [When::Coordinates::Residue]
|
367
|
+
#
|
368
|
+
def &(other)
|
369
|
+
case other
|
370
|
+
when Residue
|
371
|
+
if self.units == other.units
|
372
|
+
m = self.class._china([@remainder, @divisor], [other.remainder, other.divisor])
|
373
|
+
u = units.dup
|
374
|
+
else
|
375
|
+
keys = units.keys & other.units.keys
|
376
|
+
keys = ['day'] if keys == []
|
377
|
+
return nil unless (keys.size==1)
|
378
|
+
self_base = self.units[keys[0]] || 0
|
379
|
+
other_base = other.units[keys[0]] || 0
|
380
|
+
m = self.class._china([@remainder, @divisor],
|
381
|
+
[(other.remainder+other_base-self_base) % other.divisor, other.divisor])
|
382
|
+
u = {keys[0]=>self_base}
|
383
|
+
end
|
384
|
+
return nil unless (m)
|
385
|
+
return self.class.new(m[0], m[1], @carry, u)
|
386
|
+
when Pair
|
387
|
+
return Pair.new(self & other.trunk, other.branch)
|
388
|
+
when Numeric
|
389
|
+
keys = @units.keys
|
390
|
+
d = (keys.size == 1) ? @units[keys[0]] : (@units['day']||0)
|
391
|
+
c, m = (other-d).divmod(@divisor)
|
392
|
+
c += 1 if (m > @remainder)
|
393
|
+
return (c + @carry) * @divisor + @remainder + d
|
394
|
+
else
|
395
|
+
position = When::TM::Position.any_other(other)
|
396
|
+
raise TypeError, "Can't convert #{other.class} to When::TM::TemporalPosition" unless position
|
397
|
+
return position & self
|
398
|
+
end
|
399
|
+
end
|
400
|
+
|
401
|
+
# 剰余
|
402
|
+
#
|
403
|
+
# @param [When::TM::TemporalPosition, Numeric, When::Coordinates::Pair] other
|
404
|
+
#
|
405
|
+
# @return ['other' と同じクラス]
|
406
|
+
#
|
407
|
+
def %(other)
|
408
|
+
case other
|
409
|
+
when Pair
|
410
|
+
return Pair.new(self % other.trunk, other.branch)
|
411
|
+
when Numeric
|
412
|
+
keys = @units.keys
|
413
|
+
d = (keys.size == 1) ? @units[keys[0]] : (@units['day']||0)
|
414
|
+
return (other-d) % @divisor
|
415
|
+
else
|
416
|
+
position = When::TM::Position.any_other(other)
|
417
|
+
raise TypeError, "Can't convert #{other.class} to When::TM::TemporalPosition" unless position
|
418
|
+
return self[position % self]
|
419
|
+
end
|
420
|
+
end
|
421
|
+
|
422
|
+
# Enumerator の生成
|
423
|
+
#
|
424
|
+
# @overload initialize()
|
425
|
+
#
|
426
|
+
# @overload initialize(range, count_limit=nil)
|
427
|
+
# @param [Range, When::Parts::GeometricComplex] range 始点-range.first, 終点-range.last
|
428
|
+
# @param [Integer] count_limit 繰り返し回数(デフォルトは指定なし)
|
429
|
+
#
|
430
|
+
# @overload initialize(first, direction, count_limit)
|
431
|
+
# @param [When::TM::TemporalPosition] first 始点
|
432
|
+
# @param [Symbol] direction :forward - 昇順, :reverse - 降順
|
433
|
+
# @param [Integer] count_limit 繰り返し回数(デフォルトは指定なし)
|
434
|
+
#
|
435
|
+
# @return [When::Coordinates::Residue::BestRationalApproximations] 引数なしの場合
|
436
|
+
# @return [When::Coordinates::Residue::Enumerator] 引数ありの場合
|
437
|
+
#
|
438
|
+
def _enumerator(*args)
|
439
|
+
length = args.length
|
440
|
+
length -= 1 if args[-1].kind_of?(Hash)
|
441
|
+
args.unshift(self)
|
442
|
+
(length==0) ? BestRationalApproximations.new(self, *args) : Enumerator.new(*args)
|
443
|
+
end
|
444
|
+
alias :to_enum :_enumerator
|
445
|
+
alias :enum_for :_enumerator
|
446
|
+
|
447
|
+
# オブジェクトの生成
|
448
|
+
#
|
449
|
+
# @overload initialize(remainder, divisor, carry=0, label=nil, format=nil, units={})
|
450
|
+
# @param [Numeric] remainder 剰余
|
451
|
+
# @param [Integer] divisor 法
|
452
|
+
# @param [Integer] carry 繰り上がり
|
453
|
+
# @param [String, When::BasicTypes::M17n] label 名前
|
454
|
+
# @param [String, When::BasicTypes::M17n] format 名前の書式
|
455
|
+
# @param [Hash] units 単位(下記の通り)
|
456
|
+
# @option units [Numeric] 'day' 通日に対して使用する場合のオフセット
|
457
|
+
# @option units [Numeric] 'year' 通年に対して使用する場合のオフセット
|
458
|
+
#
|
459
|
+
def initialize(*args)
|
460
|
+
# units の取得
|
461
|
+
options =_get_options(args).dup
|
462
|
+
units = {}
|
463
|
+
list = []
|
464
|
+
options.each_pair do |key, value|
|
465
|
+
if (PRECISION[key.upcase])
|
466
|
+
list << key
|
467
|
+
units[key.downcase] = _to_num(value)
|
468
|
+
end
|
469
|
+
end
|
470
|
+
list.each do |key|
|
471
|
+
options.delete(key)
|
472
|
+
end
|
473
|
+
options['units'] ||= {}
|
474
|
+
options['units'].update(units)
|
475
|
+
_set_variables(options)
|
476
|
+
@units ||= {}
|
477
|
+
|
478
|
+
# その他の変数
|
479
|
+
remainder, divisor, carry, label, format = args
|
480
|
+
@label = label || @label
|
481
|
+
@label = m17n(@label, nil, nil, options) if (@label)
|
482
|
+
@format = format || @format
|
483
|
+
@format = m17n(@format, nil, nil, options) if (@format)
|
484
|
+
_sequence
|
485
|
+
@remainder = _to_num(remainder || @remainder)
|
486
|
+
@divisor = _to_num(divisor || @divisor )
|
487
|
+
@carry = _to_num(carry || @carry )
|
488
|
+
raise RangeError, "Divisor shoud be Positive Numeric" if (@divisor <= 0)
|
489
|
+
carry, @remainder = @remainder.divmod(@divisor)
|
490
|
+
@carry += carry
|
491
|
+
end
|
492
|
+
|
493
|
+
private
|
494
|
+
|
495
|
+
alias :_method_missing :method_missing
|
496
|
+
|
497
|
+
# その他のメソッド
|
498
|
+
#
|
499
|
+
# When::Coordinate::Residue で定義されていないメソッドは
|
500
|
+
# 指定の桁での剰余算とみなす
|
501
|
+
#
|
502
|
+
def method_missing(name, *args, &block)
|
503
|
+
return _method_missing(name, *args, &block) if When::Parts::MethodCash::Escape.key?(name) ||
|
504
|
+
!@units.key?(name.to_s.downcase)
|
505
|
+
instance_eval %Q{
|
506
|
+
def #{name}(*args, &block)
|
507
|
+
self[args[0] % self.to("#{name.to_s.downcase}")]
|
508
|
+
end
|
509
|
+
} unless When::Parts::MethodCash.escape(name)
|
510
|
+
self[args[0] % self.to(name.to_s.downcase)]
|
511
|
+
end
|
512
|
+
|
513
|
+
# 数値化
|
514
|
+
def _to_num(s)
|
515
|
+
case s
|
516
|
+
when Numeric ; return s
|
517
|
+
when nil ; return 0
|
518
|
+
when /\.|E/ ; return s.to_f
|
519
|
+
else ; return s.to_i
|
520
|
+
end
|
521
|
+
end
|
522
|
+
|
523
|
+
#
|
524
|
+
# 最良近似分数の系列を生成する Enumerator
|
525
|
+
#
|
526
|
+
class BestRationalApproximations < When::Parts::Enumerator
|
527
|
+
|
528
|
+
# Enumerator の巻き戻し
|
529
|
+
#
|
530
|
+
# @return [void]
|
531
|
+
#
|
532
|
+
def _rewind
|
533
|
+
@z = @x/@y
|
534
|
+
@k = @z.floor
|
535
|
+
@p = [1,@k]
|
536
|
+
@q = [0, 1]
|
537
|
+
super
|
538
|
+
end
|
539
|
+
|
540
|
+
# 最良近似分数を生成する
|
541
|
+
#
|
542
|
+
# @return [Array<Numeric>] ( remainder, divisor, error )
|
543
|
+
# [ remainder (Integer) 分子 ]
|
544
|
+
# [ divisor (Integer) 分母 ]
|
545
|
+
# [ error (Float) 誤差 ]
|
546
|
+
#
|
547
|
+
def succ
|
548
|
+
value = @current
|
549
|
+
if (@count_limit.kind_of?(Numeric) && @count >= @count_limit) ||
|
550
|
+
(@error.kind_of?(Numeric) && @e && @error >= @e.abs)
|
551
|
+
@current = nil
|
552
|
+
else
|
553
|
+
if @z==@k
|
554
|
+
@e = 0
|
555
|
+
@current = [@p[1], @q[1], 0]
|
556
|
+
else
|
557
|
+
@z = 1.0/(@z-@k)
|
558
|
+
@k = @z.floor
|
559
|
+
@e = @p[1].to_f/@q[1]-@x.to_f/@y
|
560
|
+
@current = [@p[1], @q[1], @e]
|
561
|
+
@p = [@p[1], @p[1]*@k + @p[0]]
|
562
|
+
@q = [@q[1], @q[1]*@k + @q[0]]
|
563
|
+
end
|
564
|
+
@count += 1
|
565
|
+
end
|
566
|
+
return value
|
567
|
+
end
|
568
|
+
|
569
|
+
# オブジェクトの生成
|
570
|
+
#
|
571
|
+
# @overload initialize(parent, options={})
|
572
|
+
# @param [When::Coordinates::Residue] parent 生成元の剰余類オブジェクト
|
573
|
+
# @param [Hash] options 下記の通り
|
574
|
+
# @option options [Numeric] :error 収束とみなす誤差(デフォルト 1E-5)
|
575
|
+
# @option options [Integer] :count_limit 最大繰り返し回数
|
576
|
+
#
|
577
|
+
def initialize(*args)
|
578
|
+
@y = args[0].divisor
|
579
|
+
@x = args[0].remainder + @y * args[0].carry
|
580
|
+
super
|
581
|
+
@error = @options[:error] || 1e-15
|
582
|
+
@count_limit = @options[:count_limit]
|
583
|
+
end
|
584
|
+
end
|
585
|
+
|
586
|
+
#
|
587
|
+
# 指定の剰余となる通日or通年を生成する Enumerator
|
588
|
+
#
|
589
|
+
class Enumerator < When::Parts::Enumerator
|
590
|
+
|
591
|
+
#
|
592
|
+
# 次の通日or通年を得る
|
593
|
+
#
|
594
|
+
# @return [When::TM::TemporalPosition]
|
595
|
+
#
|
596
|
+
def succ
|
597
|
+
value = @current
|
598
|
+
@current = (@count_limit.kind_of?(Numeric) && @count >= @count_limit) ? nil :
|
599
|
+
(@current==:first) ? @first :
|
600
|
+
(@direction==:forward) ? @first & @parent >> @count : @first & @parent << @count
|
601
|
+
@count += 1
|
602
|
+
return value
|
603
|
+
end
|
604
|
+
|
605
|
+
# オブジェクトの生成
|
606
|
+
#
|
607
|
+
# @overload initialize(parent, range, count_limit=nil)
|
608
|
+
# @param [When::Coordinates::Residue] parent 生成元の剰余類オブジェクト
|
609
|
+
# @param [Range, When::Parts::GeometricComplex] range 始点-range.first, 終点-range.last
|
610
|
+
# @param [Integer] count_limit 繰り返し回数(デフォルトは指定なし)
|
611
|
+
#
|
612
|
+
# @overload initialize(parent, first, direction, count_limit)
|
613
|
+
# @param [When::Coordinates::Residue] parent 生成元の剰余類オブジェクト
|
614
|
+
# @param [When::TM::TemporalPosition] first 始点
|
615
|
+
# @param [Symbol] direction :forward - 昇順, :reverse - 降順
|
616
|
+
# @param [Integer] count_limit 繰り返し回数(デフォルトは指定なし)
|
617
|
+
#
|
618
|
+
def initialize(*args)
|
619
|
+
case args[1]
|
620
|
+
when When::TimeValue
|
621
|
+
first = args[1] & args[0]
|
622
|
+
first = args[1] & (args[0] << 1) if args[2] == :reverse && first > args[1]
|
623
|
+
args[1] = first
|
624
|
+
when Range
|
625
|
+
first = args[1].first & args[0]
|
626
|
+
args[1] = (args[1].exclude_end?) ? (first...args[1].last) : (first..args[1].last)
|
627
|
+
else
|
628
|
+
raise TypeError, "Second Argument should be 'When::TM::(Temporal)Position'"
|
629
|
+
end
|
630
|
+
@period = When::TM::PeriodDuration.new(args[0].divisor,
|
631
|
+
When::Coordinates::PRECISION[args[0].units] || When::DAY)
|
632
|
+
super(*args)
|
633
|
+
end
|
634
|
+
end
|
635
|
+
end
|
636
|
+
|
637
|
+
# 暦座標
|
638
|
+
#
|
639
|
+
# 暦座標の特性を定義する
|
640
|
+
#
|
641
|
+
class Index < When::BasicTypes::Object
|
642
|
+
|
643
|
+
# 日時要素の要素数
|
644
|
+
#
|
645
|
+
# @return [Integer]
|
646
|
+
#
|
647
|
+
# 「時」なら 24, 「分」なら 60
|
648
|
+
#
|
649
|
+
# 日数や太陰太陽暦の月数のように不定の場合は nil
|
650
|
+
#
|
651
|
+
attr_reader :unit
|
652
|
+
|
653
|
+
# 日時要素の下限
|
654
|
+
#
|
655
|
+
# @return [Integer]
|
656
|
+
#
|
657
|
+
# 年月日は 1, 時分秒は 0
|
658
|
+
#
|
659
|
+
attr_reader :base
|
660
|
+
|
661
|
+
# 日時要素名(幹)
|
662
|
+
#
|
663
|
+
# @return [When::BasicTypes::M17n]
|
664
|
+
#
|
665
|
+
# 月の名称の配列などに用いる
|
666
|
+
#
|
667
|
+
attr_reader :trunk
|
668
|
+
|
669
|
+
# 座標値のシフト
|
670
|
+
#
|
671
|
+
# @return [Integer](デフォルト 0)
|
672
|
+
#
|
673
|
+
# 月 - 名称を trunk 配列の何番目(0オリジン)からとるかを指定
|
674
|
+
#
|
675
|
+
# 日 - 剰余類のシフトを指定
|
676
|
+
#
|
677
|
+
attr_reader :shift
|
678
|
+
|
679
|
+
# 日時要素名(枝)
|
680
|
+
#
|
681
|
+
# @return [Hash] { Numeric=>When::BasicTypes::M17n }
|
682
|
+
#
|
683
|
+
# When::Coordinates::Pair の branch の値からprefix
|
684
|
+
#
|
685
|
+
# (「閏」などの文字列)を引くための Hash
|
686
|
+
#
|
687
|
+
attr_reader :branch
|
688
|
+
|
689
|
+
# 日時要素名(幹枝)
|
690
|
+
#
|
691
|
+
# @return [Hash] { When::Coordinates::Pair=>When::BasicTypes::M17n }
|
692
|
+
#
|
693
|
+
# When::Coordinates::Pair から 日時要素名を引くための Hash
|
694
|
+
#
|
695
|
+
# 初期化時に @trunk, @branch から自動的に生成する
|
696
|
+
#
|
697
|
+
attr_reader :trunk_branch
|
698
|
+
|
699
|
+
# インデクス(幹枝)
|
700
|
+
#
|
701
|
+
# @return [Hash] { String=>When::Coordinates::Pair }
|
702
|
+
#
|
703
|
+
# 日時要素名から When::Coordinates::Pair を引くための Hash
|
704
|
+
#
|
705
|
+
# 初期化時に @trunk, @branch から自動的に生成する
|
706
|
+
#
|
707
|
+
attr_reader :index
|
708
|
+
|
709
|
+
# @private
|
710
|
+
def self.precision(specification)
|
711
|
+
return specification.to_i if (specification.kind_of?(Numeric))
|
712
|
+
return (PRECISION[specification] || VALUE[specification] || When::SYSTEM)
|
713
|
+
end
|
714
|
+
|
715
|
+
private
|
716
|
+
|
717
|
+
def _normalize(args=[], options={})
|
718
|
+
@label = m17n(@label, nil, nil, @options) if @label
|
719
|
+
@unit = @unit.to_i if @unit
|
720
|
+
@base = (@base || 1).to_i
|
721
|
+
@trunk = When::BasicTypes::M17n.labels(args[0]) unless args.empty?
|
722
|
+
@shift = (@shift || 0).to_i
|
723
|
+
@keys = []
|
724
|
+
if @trunk
|
725
|
+
if @trunk.kind_of?(Array)
|
726
|
+
m17n = {}
|
727
|
+
@trunk.length.times do |i|
|
728
|
+
m17n[(i-@shift) % @trunk.length + @base] = @trunk[i]
|
729
|
+
end
|
730
|
+
@trunk = m17n
|
731
|
+
end
|
732
|
+
raise TypeError, "Trunk must be Hash" unless @trunk.kind_of?(Hash)
|
733
|
+
@trunk.values.each do |v|
|
734
|
+
@keys |= v.keys if v.kind_of?(When::Locale)
|
735
|
+
end
|
736
|
+
end
|
737
|
+
if @branch
|
738
|
+
if @branch.kind_of?(Array)
|
739
|
+
m17n = {}
|
740
|
+
@branch.length.times do |i|
|
741
|
+
m17n[i] = @branch[i]
|
742
|
+
end
|
743
|
+
@branch = m17n
|
744
|
+
end
|
745
|
+
raise TypeError, "Branch must be Hash" unless @branch.kind_of?(Hash)
|
746
|
+
@branch.each_pair do |key, value|
|
747
|
+
value = When::BasicTypes::M17n.label(value)
|
748
|
+
@keys |= value.keys if value.kind_of?(When::Locale)
|
749
|
+
@branch[key] = value
|
750
|
+
end
|
751
|
+
end
|
752
|
+
@trunk_branch = {}
|
753
|
+
@index = {}
|
754
|
+
if @trunk
|
755
|
+
if @branch
|
756
|
+
@trunk.keys.each do |t|
|
757
|
+
@branch.keys.each do |b|
|
758
|
+
@trunk_branch[Pair._en_pair(t,b)] = @trunk[t].prefix(@branch[b])
|
759
|
+
end
|
760
|
+
end
|
761
|
+
else
|
762
|
+
@trunk_branch = @trunk
|
763
|
+
end
|
764
|
+
@trunk_branch.each_pair do |k,v|
|
765
|
+
v.values.each do |s|
|
766
|
+
@index[s] = k
|
767
|
+
end
|
768
|
+
end
|
769
|
+
end
|
770
|
+
end
|
771
|
+
end
|
772
|
+
|
773
|
+
# 暦座標値
|
774
|
+
#
|
775
|
+
# 暦座標の値を表現する
|
776
|
+
#
|
777
|
+
class Pair < Numeric
|
778
|
+
DL0 = {'-'=> 0, '.'=> 0, ':'=> 0, ','=> 0, ' '=> 0, '@'=>-2 }
|
779
|
+
DL1 = {'!'=>-2.5, '%'=>-2, '&'=>-1.5, '*'=>-1, '+'=>-0.5,
|
780
|
+
'<'=> 0.5, '='=> 1, '>'=> 1.5, '?'=> 2 }
|
781
|
+
DL2 = DL1.invert
|
782
|
+
|
783
|
+
class << self
|
784
|
+
#
|
785
|
+
# source を Numeric に変換する
|
786
|
+
#
|
787
|
+
# @param [Object] source
|
788
|
+
# @param [Numeric] default source が nil の場合の代替値
|
789
|
+
#
|
790
|
+
# @return [Numeric]
|
791
|
+
#
|
792
|
+
def _en_number(source, default=0)
|
793
|
+
return default unless(source)
|
794
|
+
integer = source.to_i
|
795
|
+
float = source.to_f
|
796
|
+
return (integer==float) ? integer : float
|
797
|
+
end
|
798
|
+
|
799
|
+
#
|
800
|
+
# (source, branch) を When::Coordinates::Pair に変換する
|
801
|
+
#
|
802
|
+
# @param [Object] source
|
803
|
+
# @param [Numeric] branch
|
804
|
+
#
|
805
|
+
# @return [When::Coordinates::Pair]
|
806
|
+
#
|
807
|
+
def _force_pair(source, branch=nil)
|
808
|
+
case source
|
809
|
+
when self
|
810
|
+
return source
|
811
|
+
when Numeric
|
812
|
+
return new(_en_number(source), branch)
|
813
|
+
when String
|
814
|
+
tail = source[-1..-1]
|
815
|
+
branch = DL0[tail] || DL1[tail]
|
816
|
+
source = (branch) ? source[0..-2] : source.dup
|
817
|
+
trunk = (source =~ /\.|E/i) ? source.to_f : source.to_i
|
818
|
+
return new(trunk, branch)
|
819
|
+
else
|
820
|
+
raise TypeError, "Irregal type for #{self} :#{source}"
|
821
|
+
end
|
822
|
+
end
|
823
|
+
|
824
|
+
#
|
825
|
+
# branch が有効なら (source, branch) を When::Coordinates::Pair に変換する。
|
826
|
+
#
|
827
|
+
# @param [Object] trunk
|
828
|
+
# @param [Numeric, String] branch
|
829
|
+
#
|
830
|
+
# @return [trunk自体] branch が無効
|
831
|
+
# @return [When::Coordinates::Pair] branch が有効(非0)
|
832
|
+
#
|
833
|
+
def _en_pair(trunk, branch=nil)
|
834
|
+
return trunk if (trunk.kind_of?(self))
|
835
|
+
branch = DL0[branch] || DL1[branch] || branch
|
836
|
+
trunk = _en_number(trunk) if (trunk)
|
837
|
+
return trunk unless (branch && branch != 0)
|
838
|
+
return new(trunk, branch)
|
839
|
+
end
|
840
|
+
|
841
|
+
#
|
842
|
+
# When::Coordinates::Pair の trunk と branch の和をとって Numeric 化する
|
843
|
+
#
|
844
|
+
# @param [When::Coordinates::Pair] source trunk と branch の和を返す
|
845
|
+
# @param [Array] source 各要素を _de_pair した Arrayを返す
|
846
|
+
# @param [その他 Numeric] source をそのまま返す
|
847
|
+
#
|
848
|
+
# @return [Numeric, Array<Numeric>]
|
849
|
+
#
|
850
|
+
def _de_pair(source)
|
851
|
+
case source
|
852
|
+
when Array
|
853
|
+
return (source.map!{|v| _de_pair(v)})
|
854
|
+
when self
|
855
|
+
return source.sum
|
856
|
+
when Numeric
|
857
|
+
return source
|
858
|
+
else
|
859
|
+
raise TypeError, "Irregal type for #{self}"
|
860
|
+
end
|
861
|
+
end
|
862
|
+
|
863
|
+
#
|
864
|
+
# 文字列を When::Coordinates::Pair のArray 化する
|
865
|
+
#
|
866
|
+
# @param [String] source
|
867
|
+
#
|
868
|
+
# @return [Array<When::Coordinates::Pair>]
|
869
|
+
#
|
870
|
+
def _en_pair_array(source)
|
871
|
+
source = $1 if source=~/\A\s*\[?(.+?)\]?\s*\z/
|
872
|
+
source.split(/,/).map {|v|
|
873
|
+
v =~ /\A\s*(.+?)([^\d\s])?\s*\z/
|
874
|
+
_en_pair($1, $2)
|
875
|
+
}
|
876
|
+
end
|
877
|
+
|
878
|
+
#
|
879
|
+
# 日付を When::Coordinates::Pair のArray 化する
|
880
|
+
#
|
881
|
+
# @param [String] source
|
882
|
+
#
|
883
|
+
# @return [Array<When::Coordinates::Pair>]
|
884
|
+
#
|
885
|
+
def _en_pair_date_time(source)
|
886
|
+
source = $1 if source =~ /\A\s*\[(.+)\]\s*\z/
|
887
|
+
trunk, branch, *rest = source.strip.split(/([^\d])/)
|
888
|
+
if trunk == ''
|
889
|
+
sign = branch
|
890
|
+
trunk, branch, *rest = rest
|
891
|
+
trunk = sign + trunk if trunk
|
892
|
+
end
|
893
|
+
pairs = []
|
894
|
+
while (trunk)
|
895
|
+
pairs << _en_pair(trunk, branch)
|
896
|
+
trunk, branch, *rest = rest
|
897
|
+
end
|
898
|
+
return pairs
|
899
|
+
end
|
900
|
+
|
901
|
+
#
|
902
|
+
# branch文字を意識して、書式文字列により When::Coordinates::Pair の Array を文字列化
|
903
|
+
#
|
904
|
+
# @overload _format(format, list)
|
905
|
+
# @param [String] format 書式文字列
|
906
|
+
# @param [Array] list 書式に従って文字列化されるオブジェクトの Array
|
907
|
+
#
|
908
|
+
# @return [String]
|
909
|
+
#
|
910
|
+
# @note %0s は文字列引数の表示を抑制するための指定となる。C言語のprintfと異なるので注意。
|
911
|
+
#
|
912
|
+
def _format(m17ns)
|
913
|
+
index = 1
|
914
|
+
m17ns[0].scan(/(%(?:(\d)\$)?[-+0# ]?[*\d.$]*[cspdiuboxXfgeEG])([-.:])?|(%%|.)/).inject('') { |form, m17n|
|
915
|
+
t,i,s,c = m17n
|
916
|
+
case t
|
917
|
+
when '%0s'
|
918
|
+
m17n[index..index] = nil
|
919
|
+
when nil
|
920
|
+
form += c
|
921
|
+
else
|
922
|
+
suffix = DL2[m17ns[i ? i.to_i : index]*0] || s if s
|
923
|
+
form += t + ({nil=>'', '%'=>'%%'}[suffix] || suffix)
|
924
|
+
index += t.length - t.gsub(/\*/,'').length + 1
|
925
|
+
end
|
926
|
+
form
|
927
|
+
} % m17ns[1..-1].map { |v| v.kind_of?(self) ? v.trunk : v }
|
928
|
+
end
|
929
|
+
end
|
930
|
+
|
931
|
+
#
|
932
|
+
# 暦要素の幹
|
933
|
+
#
|
934
|
+
# @return [Numeric] 年番号,月番号,日番号など暦要素の幹となる部分
|
935
|
+
#
|
936
|
+
attr_accessor :trunk
|
937
|
+
|
938
|
+
#
|
939
|
+
# 暦要素の枝
|
940
|
+
#
|
941
|
+
# @return [Numeric] 暦要素のうち(閏であるかなど)幹で表現しきれない枝の部分
|
942
|
+
#
|
943
|
+
attr_accessor :branch
|
944
|
+
|
945
|
+
#
|
946
|
+
# 暦要素の幹と枝の和
|
947
|
+
#
|
948
|
+
# @return [Numeric]
|
949
|
+
#
|
950
|
+
# @note
|
951
|
+
# 個別の実装において、本変数が When::TM::Calendar や When::TM::Clock が扱うべき
|
952
|
+
# 座標値を表すように配慮されている。
|
953
|
+
#
|
954
|
+
# 例: 会計年度など年の変わり目が暦年と異なる場合、trunk+=1, branch-=1 として、
|
955
|
+
# trunk が会計年度, sum が暦年を表現するようにできる。この場合、trunk は表記上の
|
956
|
+
# 年、branch は会計年度と暦年にずれがあるという情報を表現していることになる。
|
957
|
+
#
|
958
|
+
attr_reader :sum
|
959
|
+
|
960
|
+
#
|
961
|
+
# trunk の更新
|
962
|
+
#
|
963
|
+
# @param [Numeric] trunk 新しい trunk
|
964
|
+
#
|
965
|
+
# @return [When::Coordinates::Pair] 更新結果
|
966
|
+
#
|
967
|
+
def trunk=(trunk)
|
968
|
+
@trunk = trunk
|
969
|
+
_normalize
|
970
|
+
self
|
971
|
+
end
|
972
|
+
|
973
|
+
#
|
974
|
+
# branch の更新
|
975
|
+
#
|
976
|
+
# @param [Numeric] branch 新しい branch
|
977
|
+
#
|
978
|
+
# @return [When::Coordinates::Pair] 更新結果
|
979
|
+
#
|
980
|
+
def branch=(branch)
|
981
|
+
@branch = branch
|
982
|
+
_normalize
|
983
|
+
self
|
984
|
+
end
|
985
|
+
|
986
|
+
# 属性 @sum を取得する
|
987
|
+
#
|
988
|
+
# @return [Numeric]
|
989
|
+
#
|
990
|
+
# @note
|
991
|
+
# When::Coordinates::Pair 以外の Numeric では、単項演算 + は恒等変換になる。
|
992
|
+
# このため、When::TM::Calendar や When::TM::Clock の実装は、暦要素が When::Coordinates::Pair か
|
993
|
+
# 否かを判断することなく、暦要素に単項演算 + を施すことによって、必要な暦要素を取得できる。
|
994
|
+
def +@
|
995
|
+
return @sum
|
996
|
+
end
|
997
|
+
|
998
|
+
# trunk の符号を反転する
|
999
|
+
#
|
1000
|
+
# @return [When::Coordinates::Pair] Pair.new(-@trunk, @branch)
|
1001
|
+
#
|
1002
|
+
def -@
|
1003
|
+
return self.class.new(-@trunk, @branch)
|
1004
|
+
end
|
1005
|
+
|
1006
|
+
# @trunk, @branch を取得する
|
1007
|
+
#
|
1008
|
+
# @param [Integer] other (1, 0, -1)
|
1009
|
+
#
|
1010
|
+
# @return [Numeric]
|
1011
|
+
# [ other == 1 - @trunk ]
|
1012
|
+
# [ other == 0 - @branch ]
|
1013
|
+
# [ other == -1 - -@trunk ]
|
1014
|
+
#
|
1015
|
+
# @note
|
1016
|
+
# When::Coordinates::Pair 以外の Numeric では、1 による乗算は恒等変換になる。
|
1017
|
+
# また、0 による乗算は恒に 0になる。
|
1018
|
+
# このため、When::TM::Calendar や When::TM::Clock の実装は、暦要素が When::Coordinates::Pair か
|
1019
|
+
# 否かを判断することなく、暦要素に 1 による乗算を施すことによって、trunk に相当する値を、
|
1020
|
+
# 0 による乗算を施すことによって、branch に相当する値を取得できる。
|
1021
|
+
def *(other)
|
1022
|
+
case other
|
1023
|
+
when 1 ; @trunk
|
1024
|
+
when 0 ; @branch
|
1025
|
+
when -1 ; -@trunk
|
1026
|
+
else ; raise ArgumentError, "Irregal designation : #{other}"
|
1027
|
+
end
|
1028
|
+
end
|
1029
|
+
|
1030
|
+
# 加算
|
1031
|
+
#
|
1032
|
+
# @param [Numeric] other
|
1033
|
+
#
|
1034
|
+
# @return [When::Coordinates::Pair]
|
1035
|
+
# other が When::Coordinates::Pair でない場合、trunk に対する加算となる
|
1036
|
+
#
|
1037
|
+
def +(other)
|
1038
|
+
return self.class.new(@trunk + other, @branch) unless other.kind_of?(self.class)
|
1039
|
+
return self.class.new(@trunk + other.trunk, @branch + other.branch)
|
1040
|
+
end
|
1041
|
+
|
1042
|
+
# 減算
|
1043
|
+
#
|
1044
|
+
# @param [Numeric] other
|
1045
|
+
#
|
1046
|
+
# @return [When::Coordinates::Pair]
|
1047
|
+
# other が When::Coordinates::Pair でない場合、trunk に対する減算となる
|
1048
|
+
#
|
1049
|
+
def -(other)
|
1050
|
+
return self.class.new(@trunk - other, @branch) unless other.kind_of?(self.class)
|
1051
|
+
return self.class.new(@trunk - other.trunk, @branch - other.branch)
|
1052
|
+
end
|
1053
|
+
|
1054
|
+
# 商と剰余
|
1055
|
+
#
|
1056
|
+
# @param [Numeric] other
|
1057
|
+
#
|
1058
|
+
# @return [When::Coordinates::Pair]
|
1059
|
+
# trunk に対する divmod となる
|
1060
|
+
#
|
1061
|
+
def divmod(other)
|
1062
|
+
div, mod = @trunk.divmod(other)
|
1063
|
+
return div, self.class.new(mod, @branch)
|
1064
|
+
end
|
1065
|
+
|
1066
|
+
# 剰余
|
1067
|
+
#
|
1068
|
+
# @param [Numeric] other
|
1069
|
+
#
|
1070
|
+
# @return [When::Coordinates::Pair]
|
1071
|
+
# trunk に対する % となる
|
1072
|
+
#
|
1073
|
+
def %(other)
|
1074
|
+
self.class.new(@trunk % other, @branch)
|
1075
|
+
end
|
1076
|
+
|
1077
|
+
# 比較
|
1078
|
+
#
|
1079
|
+
# @param [Numeric] other
|
1080
|
+
#
|
1081
|
+
# @return [Integer] (負,0,正)
|
1082
|
+
# trunk の比較が優先される
|
1083
|
+
#
|
1084
|
+
def <=>(other)
|
1085
|
+
other = self.class._force_pair(other)
|
1086
|
+
(@trunk <=> other.trunk).nonzero? || (@branch <=> other.branch)
|
1087
|
+
end
|
1088
|
+
|
1089
|
+
# 文字列化
|
1090
|
+
#
|
1091
|
+
# @param [String] zero @branch == 0 を表現する文字列
|
1092
|
+
#
|
1093
|
+
# @return [String]
|
1094
|
+
#
|
1095
|
+
def to_s(zero='')
|
1096
|
+
return @trunk.to_s + (@branch==0 ? zero : DL2[@branch])
|
1097
|
+
end
|
1098
|
+
|
1099
|
+
# 強制型変換
|
1100
|
+
# @private
|
1101
|
+
def coerce(other)
|
1102
|
+
[self.class._force_pair(other), self]
|
1103
|
+
end
|
1104
|
+
|
1105
|
+
private
|
1106
|
+
|
1107
|
+
# オブジェクトの生成
|
1108
|
+
#
|
1109
|
+
# @param [Numeric] trunk 幹
|
1110
|
+
# @param [Numeric] branch 枝
|
1111
|
+
#
|
1112
|
+
def initialize(trunk, branch=nil)
|
1113
|
+
@trunk = trunk || 0
|
1114
|
+
@branch = branch || 0
|
1115
|
+
_normalize
|
1116
|
+
end
|
1117
|
+
|
1118
|
+
def _normalize
|
1119
|
+
@trunk = @trunk.to_i if (@trunk.kind_of?(Float) && @trunk.to_i == @trunk.to_f)
|
1120
|
+
@sum = @trunk
|
1121
|
+
if (@branch.kind_of?(Numeric))
|
1122
|
+
@branch = @branch.to_i if (@branch.to_i == @branch.to_f)
|
1123
|
+
@sum += @branch if (@trunk)
|
1124
|
+
end
|
1125
|
+
end
|
1126
|
+
|
1127
|
+
# その他のメソッド
|
1128
|
+
# When::Coordinates:Pair で定義されていないメソッドは
|
1129
|
+
# 処理を @sum (type:Numeric) に委譲する
|
1130
|
+
#
|
1131
|
+
def method_missing(name, *args, &block)
|
1132
|
+
self.class.module_eval %Q{
|
1133
|
+
def #{name}(*args, &block)
|
1134
|
+
@sum.send("#{name}", *args, &block)
|
1135
|
+
end
|
1136
|
+
} unless When::Parts::MethodCash.escape(name)
|
1137
|
+
@sum.send(name, *args, &block)
|
1138
|
+
end
|
1139
|
+
end
|
1140
|
+
|
1141
|
+
# 暦座標値
|
1142
|
+
#
|
1143
|
+
# 閏秒のある暦座標の値を表現する
|
1144
|
+
#
|
1145
|
+
class LeapSeconds < Pair
|
1146
|
+
|
1147
|
+
#
|
1148
|
+
# 閏秒の単位 / When::TM::Duration::SYSTEM
|
1149
|
+
#
|
1150
|
+
# @return [Numeric]
|
1151
|
+
#
|
1152
|
+
attr_reader :second
|
1153
|
+
|
1154
|
+
#
|
1155
|
+
# trunk の整数部
|
1156
|
+
#
|
1157
|
+
# @return [Integer]
|
1158
|
+
#
|
1159
|
+
attr_reader :int
|
1160
|
+
|
1161
|
+
#
|
1162
|
+
# trunk の小数部
|
1163
|
+
#
|
1164
|
+
# @return [Float]
|
1165
|
+
#
|
1166
|
+
attr_reader :frac
|
1167
|
+
|
1168
|
+
# 加算
|
1169
|
+
#
|
1170
|
+
# @param [Numeric] other
|
1171
|
+
#
|
1172
|
+
# @return [When::Coordinates::LeapSeconds]
|
1173
|
+
# other が When::Coordinates::LeapSeconds でない場合、trunk に対する加算となる
|
1174
|
+
#
|
1175
|
+
def +(other)
|
1176
|
+
return self.class.new(@trunk + +other, @branch, @second) unless other.kind_of?(self.class)
|
1177
|
+
return self.class.new(@trunk + other.trunk, @branch + other.branch, @second)
|
1178
|
+
end
|
1179
|
+
|
1180
|
+
# 減算
|
1181
|
+
#
|
1182
|
+
# @param [Numeric] other
|
1183
|
+
#
|
1184
|
+
# @return [When::Coordinates::LeapSeconds]
|
1185
|
+
# other が When::Coordinates::LeapSeconds でない場合、trunk に対する減算となる
|
1186
|
+
#
|
1187
|
+
def -(other)
|
1188
|
+
return self.class.new(@trunk - +other, @branch, @second) unless other.kind_of?(self.class)
|
1189
|
+
return self.class.new(@trunk - other.trunk, @branch - other.branch, @second)
|
1190
|
+
end
|
1191
|
+
|
1192
|
+
# 商と剰余
|
1193
|
+
#
|
1194
|
+
# @param [Numeric] other
|
1195
|
+
#
|
1196
|
+
# @return [When::Coordinates::LeapSeconds]
|
1197
|
+
# trunk に対する divmod となる
|
1198
|
+
#
|
1199
|
+
def divmod(other)
|
1200
|
+
div, mod = @trunk.divmod(other)
|
1201
|
+
return div, self.class.new(mod, @branch, @second)
|
1202
|
+
end
|
1203
|
+
|
1204
|
+
# 比較
|
1205
|
+
#
|
1206
|
+
# @param [Numeric] other
|
1207
|
+
#
|
1208
|
+
# @return [Integer] (負,0,正)
|
1209
|
+
# trunk の整数部, branch, trunk の小数部の順に比較する
|
1210
|
+
#
|
1211
|
+
def <=>(other)
|
1212
|
+
other = self.class.new(+other, 0, @second) unless other.kind_of?(self.class)
|
1213
|
+
raise ArgumentError, "length of unit 'second' mismatch" unless @second == other.second
|
1214
|
+
(@int <=> other.int).nonzero? || (@branch <=> other.branch).nonzero? || (@frac <=> other.frac)
|
1215
|
+
end
|
1216
|
+
|
1217
|
+
# 文字列化
|
1218
|
+
#
|
1219
|
+
# @param [String] zero @branch==0 を表現する文字列
|
1220
|
+
#
|
1221
|
+
# @return [String]
|
1222
|
+
#
|
1223
|
+
def to_s(zero='')
|
1224
|
+
return @trunk.to_s + (@branch==0 ? zero : DL2[(@branch/@second).floor])
|
1225
|
+
end
|
1226
|
+
|
1227
|
+
# 強制型変換
|
1228
|
+
# @private
|
1229
|
+
def coerce(other)
|
1230
|
+
[self.class.new(other, 0, @second), self]
|
1231
|
+
end
|
1232
|
+
|
1233
|
+
# オブジェクトの生成
|
1234
|
+
#
|
1235
|
+
# @param [Numeric] trunk 幹
|
1236
|
+
# @param [Numeric] branch 枝
|
1237
|
+
# @param [Numeric] second 閏秒の単位
|
1238
|
+
#
|
1239
|
+
def initialize(trunk, branch, second)
|
1240
|
+
@second = second
|
1241
|
+
@int, @frac = trunk.divmod(second)
|
1242
|
+
super(trunk, branch)
|
1243
|
+
end
|
1244
|
+
end
|
1245
|
+
|
1246
|
+
#
|
1247
|
+
# 空間位置
|
1248
|
+
#
|
1249
|
+
class Spatial < When::BasicTypes::Object
|
1250
|
+
|
1251
|
+
LabelProperty = 'label'
|
1252
|
+
|
1253
|
+
include When::Ephemeris
|
1254
|
+
|
1255
|
+
require 'when_exe/ephemeris/eclipse'
|
1256
|
+
|
1257
|
+
class << self
|
1258
|
+
# When::Coordinates::Spatial のグローバルな設定を行う
|
1259
|
+
#
|
1260
|
+
# @param [When::Coordinates::Spatial, String] location デフォルトの空間位置を使用する場合、指定する
|
1261
|
+
#
|
1262
|
+
# @return [void]
|
1263
|
+
#
|
1264
|
+
# @note
|
1265
|
+
# 本メソッドでマルチスレッド対応の管理変数の初期化を行っている。
|
1266
|
+
# このため、本メソッド自体はスレッドセーフでない。
|
1267
|
+
#
|
1268
|
+
def _setup_(location=nil)
|
1269
|
+
@_lock_ = Mutex.new if When.multi_thread
|
1270
|
+
@_pool = {}
|
1271
|
+
@default_location = location
|
1272
|
+
end
|
1273
|
+
|
1274
|
+
# デフォルトの空間位置
|
1275
|
+
#
|
1276
|
+
# @param [When::Coordinates::Spatial, String] local デフォルトの空間位置
|
1277
|
+
#
|
1278
|
+
# @return [When::Coordinates::Spatial, String]
|
1279
|
+
#
|
1280
|
+
# @note
|
1281
|
+
# @default_locationは、原則、ライブラリ立ち上げ時に _setup_ で初期化する。
|
1282
|
+
# 以降、@default_locationに代入を行っても、すでに生成した When::TM::TemporalPosition 等には反映されない。
|
1283
|
+
#
|
1284
|
+
def default_location=(local)
|
1285
|
+
if @_pool
|
1286
|
+
@default_location = local
|
1287
|
+
else
|
1288
|
+
_setup_(local)
|
1289
|
+
end
|
1290
|
+
end
|
1291
|
+
|
1292
|
+
# 設定情報を取得する
|
1293
|
+
#
|
1294
|
+
# @return [Hash] 設定情報
|
1295
|
+
#
|
1296
|
+
def _setup_info
|
1297
|
+
{:location => @default_location}
|
1298
|
+
end
|
1299
|
+
|
1300
|
+
# デフォルトの空間位置を読みだす
|
1301
|
+
#
|
1302
|
+
# @return [When::Coordinates::Spatial]
|
1303
|
+
#
|
1304
|
+
def default_location
|
1305
|
+
_default_location[1]
|
1306
|
+
end
|
1307
|
+
|
1308
|
+
# デフォルトの空間位置が When::TM::Clock のローカルタイムから生成されたか?
|
1309
|
+
#
|
1310
|
+
# @return [true, false]
|
1311
|
+
#
|
1312
|
+
def is_default_location_derived?
|
1313
|
+
location = _default_location
|
1314
|
+
location[0] && location[1]
|
1315
|
+
end
|
1316
|
+
|
1317
|
+
private
|
1318
|
+
|
1319
|
+
# 共通処理
|
1320
|
+
def _default_location
|
1321
|
+
case @default_location
|
1322
|
+
when nil ;
|
1323
|
+
when Array ; return @default_location unless @default_location[0]
|
1324
|
+
when String ; return (@default_location = [false, When.Resource(@default_location)])
|
1325
|
+
else ; return (@default_location = [false, @default_location])
|
1326
|
+
end
|
1327
|
+
timezone = When::TM::Clock.local_time
|
1328
|
+
location = timezone.location if timezone.kind_of?(When::Parts::Timezone)
|
1329
|
+
return [true, location]
|
1330
|
+
end
|
1331
|
+
end
|
1332
|
+
|
1333
|
+
# @private
|
1334
|
+
HashProperty = [:label, :longitude, :latitude, [:altitude, 0.0], [:datum, When::Ephemeris::Earth], :ref]
|
1335
|
+
|
1336
|
+
# Degree / Internal Location Unit(16")
|
1337
|
+
#
|
1338
|
+
# (3600 を 2 の因数で割りつくした値を単位とする)
|
1339
|
+
DEGREE = 225
|
1340
|
+
|
1341
|
+
# 黄道座標 (ecliptic coordinate system)
|
1342
|
+
ECLIPTIC = 0
|
1343
|
+
|
1344
|
+
# 赤道座標 (equatorial coordinate system)
|
1345
|
+
EQUATORIAL = 1
|
1346
|
+
|
1347
|
+
# 赤道座標[時角] (equatorial coordinate system with hour angle)
|
1348
|
+
EQUATORIAL_HA = 2
|
1349
|
+
|
1350
|
+
# 地平座標 (horizontal coordinate system)
|
1351
|
+
HORIZONTAL = 3
|
1352
|
+
|
1353
|
+
# 惑星中心の高度
|
1354
|
+
CENTER = :center
|
1355
|
+
|
1356
|
+
# 北緯を正とする緯度 / 16秒
|
1357
|
+
#
|
1358
|
+
# @return [Numeric]
|
1359
|
+
#
|
1360
|
+
attr_reader :lat
|
1361
|
+
|
1362
|
+
# 東経を正とする経度 / 16秒
|
1363
|
+
#
|
1364
|
+
# @return [Numeric]
|
1365
|
+
#
|
1366
|
+
attr_reader :long
|
1367
|
+
|
1368
|
+
# 高度 / m
|
1369
|
+
#
|
1370
|
+
# @return [Numeric]
|
1371
|
+
# @return [:Center] 天体の中心の場合
|
1372
|
+
#
|
1373
|
+
attr_reader :alt
|
1374
|
+
alias :altitude :alt
|
1375
|
+
|
1376
|
+
# 座標系
|
1377
|
+
#
|
1378
|
+
# @return [When::Ephemeris::Datum]
|
1379
|
+
#
|
1380
|
+
attr_reader :datum
|
1381
|
+
|
1382
|
+
# 参照
|
1383
|
+
#
|
1384
|
+
# @return [String] URI
|
1385
|
+
#
|
1386
|
+
attr_reader :ref
|
1387
|
+
|
1388
|
+
# 時間帯(オプショナル)
|
1389
|
+
#
|
1390
|
+
# @return [TZInfo::CountryTimezone]
|
1391
|
+
#
|
1392
|
+
# TZInfoライブラリから経緯度を取得して使用する
|
1393
|
+
#
|
1394
|
+
attr_reader :tz
|
1395
|
+
|
1396
|
+
# 緯度文字列
|
1397
|
+
#
|
1398
|
+
# @param [Integer] round 秒の小数点以下最大桁数
|
1399
|
+
#
|
1400
|
+
# @return [String] 緯度文字列(DD.MMSSsss[NS])
|
1401
|
+
#
|
1402
|
+
def lat_s
|
1403
|
+
When::Coordinates.to_dms(lat / When::Coordinates::Spatial::DEGREE, 'NS', round=6)
|
1404
|
+
end
|
1405
|
+
alias :latitude :lat_s
|
1406
|
+
|
1407
|
+
# 経度文字列
|
1408
|
+
#
|
1409
|
+
# @param [Integer] round 秒の小数点以下最大桁数
|
1410
|
+
#
|
1411
|
+
# @return [String] 経度文字列(DDD.MMSSsss[EW])
|
1412
|
+
#
|
1413
|
+
def long_s
|
1414
|
+
When::Coordinates.to_dms(long / When::Coordinates::Spatial::DEGREE, 'EW', round=6)
|
1415
|
+
end
|
1416
|
+
alias :longitude :long_s
|
1417
|
+
|
1418
|
+
# 高度 / m
|
1419
|
+
#
|
1420
|
+
# @return [Numeric]
|
1421
|
+
# @return [:Center] 天体の中心の場合
|
1422
|
+
#
|
1423
|
+
attr_reader :alt
|
1424
|
+
|
1425
|
+
# 観測地の地心距離 / kmを返します。
|
1426
|
+
#
|
1427
|
+
# @return [Numeric]
|
1428
|
+
#
|
1429
|
+
def obserber_distance
|
1430
|
+
l = PI / (90 * DEGREE) * @lat
|
1431
|
+
@datum.surface_radius * (@datum.shape[0]+@datum.shape[1]*cos(l)+@datum.shape[2]*cos(2*l))
|
1432
|
+
end
|
1433
|
+
|
1434
|
+
# 観測地での‘大地’の視半径
|
1435
|
+
#
|
1436
|
+
# @return [Numeric]
|
1437
|
+
#
|
1438
|
+
def horizon
|
1439
|
+
# 地面以下なら 90度とみなす
|
1440
|
+
return 0.25 if @alt == :Center || @alt <= 0
|
1441
|
+
|
1442
|
+
# 観測地の地心距離 / m
|
1443
|
+
r = obserber_distance * 1000.0
|
1444
|
+
|
1445
|
+
# 大気効果
|
1446
|
+
air_effect = @datum.air[1] * @alt / (@datum.air[2] * @alt + r)
|
1447
|
+
|
1448
|
+
# ‘大地’の視半径
|
1449
|
+
asin((1.0+air_effect) * r / (r+@alt)) / CIRCLE
|
1450
|
+
end
|
1451
|
+
|
1452
|
+
# 観測地の地方恒星時 / 時を返します。
|
1453
|
+
#
|
1454
|
+
# @param [Numeric] t ユリウス日(Terrestrial Time)
|
1455
|
+
# @param [When::TM::TemporalPosition] t
|
1456
|
+
#
|
1457
|
+
# @return [Numeric]
|
1458
|
+
#
|
1459
|
+
def local_sidereal_time(t)
|
1460
|
+
t = +t
|
1461
|
+
c = julian_century_from_2000(t)
|
1462
|
+
result = @datum.sid[0] + c * (@datum.sid[1] + c * @datum.sid[2]) + @long / (15.0 * DEGREE)
|
1463
|
+
result += (cosc(obl(c)) * delta_p(c) +
|
1464
|
+
(t-When::TimeStandard.delta_t_observed(t)/86400+0.5) % 1) * 24 if @datum.kind_of?(Earth)
|
1465
|
+
result
|
1466
|
+
end
|
1467
|
+
|
1468
|
+
# 観測地の日心三次元座標(黄道座標)
|
1469
|
+
#
|
1470
|
+
# @param [Numeric] t ユリウス日(Terrestrial Time)
|
1471
|
+
# @param [When::TM::TemporalPosition] t
|
1472
|
+
#
|
1473
|
+
# @return [Numeric]
|
1474
|
+
#
|
1475
|
+
def _coords(t)
|
1476
|
+
t = +t
|
1477
|
+
@datum._coords(t) + _coords_diff(t)
|
1478
|
+
end
|
1479
|
+
|
1480
|
+
private
|
1481
|
+
|
1482
|
+
# 要素の正規化
|
1483
|
+
def _normalize(args=[], options={})
|
1484
|
+
|
1485
|
+
# 時間帯による指定
|
1486
|
+
@tz = When::Parts::Timezone.tz_info[@tz] if @tz.kind_of?(String)
|
1487
|
+
if @tz
|
1488
|
+
@label ||= When.m17n(@tz.identifier)
|
1489
|
+
@long ||= @tz.longitude
|
1490
|
+
@lat ||= @tz.latitude
|
1491
|
+
end
|
1492
|
+
|
1493
|
+
# データの整形
|
1494
|
+
@label = When::BasicTypes::M17n.new(@label) if @label.kind_of?(Hash)
|
1495
|
+
@long = When::Coordinates.to_deg_225(@long, 'EW') if @long
|
1496
|
+
@lat = When::Coordinates.to_deg_225(@lat, 'NS') if @lat
|
1497
|
+
@datum = When.Resource(@datum || 'Earth', '_ep:')
|
1498
|
+
@long ||= 0.0
|
1499
|
+
@lat ||= 0.0
|
1500
|
+
@alt =
|
1501
|
+
case @alt
|
1502
|
+
when String ; @alt.gsub(/@/, '.').to_f
|
1503
|
+
when Numeric ; @alt.to_f
|
1504
|
+
when Symbol ; @alt
|
1505
|
+
else ; 0.0
|
1506
|
+
end
|
1507
|
+
|
1508
|
+
# 日月食用作業変数
|
1509
|
+
@mean = When.Resource(@mean || '_ep:Formula?formula=1L')
|
1510
|
+
@ecls = {}
|
1511
|
+
end
|
1512
|
+
|
1513
|
+
# 観測地の惑星中心を原点とする三次元座標
|
1514
|
+
#
|
1515
|
+
# @param [Numeric] t ユリウス日(Terrestrial Time)
|
1516
|
+
# @param [When::TM::TemporalPosition] t
|
1517
|
+
# @param [Integer] system : 座標系
|
1518
|
+
# [ ECLIPTIC = 黄道座標 ]
|
1519
|
+
# [ EQUATORIAL = 赤道座標 ]
|
1520
|
+
# [ EQUATORIAL_HA = 赤道座標[時角] ]
|
1521
|
+
# [ HORIZONTAL = 地平座標 ]
|
1522
|
+
#
|
1523
|
+
def _coords_diff(t, system=ECLIPTIC)
|
1524
|
+
return Coords.polar(0,0,0) if alt == :Center
|
1525
|
+
t = +t
|
1526
|
+
lat = @lat.to_f / DEGREE
|
1527
|
+
coords = Coords.polar(
|
1528
|
+
local_sidereal_time(t) / 24.0,
|
1529
|
+
(lat + @datum.shape[3] * sind(2*lat)) / 360.0,
|
1530
|
+
(obserber_distance + @alt/1000.0) / AU)
|
1531
|
+
case system
|
1532
|
+
when ECLIPTIC ; coords.r_to_y(t, @datum)
|
1533
|
+
when EQUATORIAL ; coords
|
1534
|
+
when EQUATORIAL_HA ; coords.r_to_rh(t, self)
|
1535
|
+
when HORIZONTAL ; coords.r_to_h(t, self)
|
1536
|
+
end
|
1537
|
+
end
|
1538
|
+
|
1539
|
+
# その他のメソッド
|
1540
|
+
# When::Coordinates::Spatial で定義されていないメソッドは
|
1541
|
+
# 処理を @datum (type: When::Ephemeris::Datum) に委譲する
|
1542
|
+
#
|
1543
|
+
def method_missing(name, *args, &block)
|
1544
|
+
self.class.module_eval %Q{
|
1545
|
+
def #{name}(*args, &block)
|
1546
|
+
@datum.send("#{name}", *args, &block)
|
1547
|
+
end
|
1548
|
+
} unless When::Parts::MethodCash.escape(name)
|
1549
|
+
@datum.send(name, *args, &block)
|
1550
|
+
end
|
1551
|
+
|
1552
|
+
# @private
|
1553
|
+
module Normalize
|
1554
|
+
|
1555
|
+
private
|
1556
|
+
|
1557
|
+
# 位置情報
|
1558
|
+
#
|
1559
|
+
# @return [When::Coordinates::Spatial]
|
1560
|
+
#
|
1561
|
+
#attr_reader :location
|
1562
|
+
|
1563
|
+
# 日時要素の境界オブジェクト
|
1564
|
+
#
|
1565
|
+
# @return [When::Coordinates::Border]
|
1566
|
+
#
|
1567
|
+
#attr_reader :border
|
1568
|
+
|
1569
|
+
# 境界計算用の計算オブジェクト
|
1570
|
+
#
|
1571
|
+
# @return [When::Ephemeris::Formula]
|
1572
|
+
#
|
1573
|
+
#attr_reader :formula
|
1574
|
+
|
1575
|
+
#
|
1576
|
+
# Temporal Module の Spatial Parts の初期化
|
1577
|
+
#
|
1578
|
+
def _normalize_spatial
|
1579
|
+
|
1580
|
+
# Location
|
1581
|
+
if (@location||@long||@lat||@alt).kind_of?(String)
|
1582
|
+
@location ||= "_l:long=#{@long||0}&lat=#{@lat||0}&alt=#{@alt||0}"
|
1583
|
+
@location = When.Resource(@location)
|
1584
|
+
end
|
1585
|
+
@location ||= @tz_prop.location if @tz_prop
|
1586
|
+
|
1587
|
+
# Border
|
1588
|
+
@border = When.Border(@border) if @border.kind_of?(String)
|
1589
|
+
|
1590
|
+
# Formula
|
1591
|
+
instance_eval('class << self; attr_reader :formula; end') if @location && @border
|
1592
|
+
if respond_to?(:formula)
|
1593
|
+
extend When::Ephemeris::Formula::ForwardedFormula
|
1594
|
+
unless @formula
|
1595
|
+
options = {:formula => kind_of?(When::CalendarTypes::SolarYearTableBased) ? '1S' : '1L'}
|
1596
|
+
options[:location] = @location if @location
|
1597
|
+
@formula = When::Ephemeris::Formula.new(options)
|
1598
|
+
end
|
1599
|
+
@formula = When.Resource(Array(@formula), '_ep:')
|
1600
|
+
end
|
1601
|
+
end
|
1602
|
+
end
|
1603
|
+
end
|
1604
|
+
|
1605
|
+
#
|
1606
|
+
# 暦座標を扱う処理をまとめたモジュール
|
1607
|
+
#
|
1608
|
+
# When::TM::Calendar と When::TM::Clock に共通する処理だが、ISO 19108 で両者の
|
1609
|
+
# 直接の superclass である、When::TM::ReferenceSystem は、これらの処理を持たない
|
1610
|
+
# こととなっているため、When::TM::Calendar と When::TM::Clock の共通部分を
|
1611
|
+
# モジュールとしてまとめた。
|
1612
|
+
#
|
1613
|
+
module Temporal
|
1614
|
+
|
1615
|
+
include When::Parts::MethodCash
|
1616
|
+
|
1617
|
+
# @private
|
1618
|
+
HashProperty =
|
1619
|
+
[[:origin_of_MSC, 0], [:origin_of_LSC, 0], [:index_of_MSC, 0], [:epoch_in_CE, 0],
|
1620
|
+
:unit, :base, :pair, :note,
|
1621
|
+
:location, :time_basis, :border, :formula, :domain]
|
1622
|
+
|
1623
|
+
# 年/日の原点(origin of most significant coordinate)
|
1624
|
+
#
|
1625
|
+
# @return [Integer]
|
1626
|
+
#
|
1627
|
+
attr_reader :origin_of_MSC
|
1628
|
+
|
1629
|
+
# 日/秒の原点(origin of least significant coordinate)
|
1630
|
+
#
|
1631
|
+
# @return [Integer]
|
1632
|
+
#
|
1633
|
+
attr_reader :origin_of_LSC
|
1634
|
+
|
1635
|
+
# インデクスオブジェクト
|
1636
|
+
#
|
1637
|
+
# @return [Array<When::Coordinates::Index>]
|
1638
|
+
#
|
1639
|
+
attr_reader :indices
|
1640
|
+
|
1641
|
+
# 年/日のインデクス(index of most significant coordinate)
|
1642
|
+
#
|
1643
|
+
# @return [Integer]
|
1644
|
+
#
|
1645
|
+
attr_reader :index_of_MSC
|
1646
|
+
|
1647
|
+
# 日時要素の要素数
|
1648
|
+
#
|
1649
|
+
# @return [Array<Integer, nil>]
|
1650
|
+
#
|
1651
|
+
# Ex. [nil, 12], [nil, 24, 60, 60]
|
1652
|
+
#
|
1653
|
+
# 初期化時に indices から自動生成する
|
1654
|
+
#
|
1655
|
+
attr_reader :unit
|
1656
|
+
|
1657
|
+
# 日時要素の下限
|
1658
|
+
#
|
1659
|
+
# @return [Array<Integer, nil>]
|
1660
|
+
#
|
1661
|
+
# Ex. [nil, 1, 1], [nil, 0, 0, 0]
|
1662
|
+
#
|
1663
|
+
# 初期化時に indices から自動生成する
|
1664
|
+
#
|
1665
|
+
# @note 日付/日時の外部表現の「下限」を指定する。内部表現の下限は常に 0 である。
|
1666
|
+
# サブクラスが定義するメソッド _coordinates_to_number, _number_to_coordinates は内部表現を使用する。
|
1667
|
+
#
|
1668
|
+
attr_reader :base
|
1669
|
+
|
1670
|
+
# 日時要素がPairであるべきか
|
1671
|
+
#
|
1672
|
+
# @return [Array<Boolean>]
|
1673
|
+
#
|
1674
|
+
# Ex. [false] * 3, [false] * 4
|
1675
|
+
#
|
1676
|
+
# 初期化時に indices から自動生成する
|
1677
|
+
#
|
1678
|
+
attr_reader :pair
|
1679
|
+
|
1680
|
+
# 代表暦注
|
1681
|
+
#
|
1682
|
+
# @return [When::CalendarNote]
|
1683
|
+
# @return [Array<Array<klass, Array<klass, method, block>>>] 最外側のArray要素は年・月・日に対応
|
1684
|
+
#
|
1685
|
+
# klass [String, When::CalendarNote, When::Coordinates::Residue]
|
1686
|
+
#
|
1687
|
+
# method [String, Symbol] (デフォルト 'day', 'month' or 'year' (対応する桁による))
|
1688
|
+
#
|
1689
|
+
# block [Block] (デフォルト なし)
|
1690
|
+
#
|
1691
|
+
def note
|
1692
|
+
case @note
|
1693
|
+
when String ; @note = When.CalendarNote(@note)
|
1694
|
+
when Array ; @note = When::CalendarNote.new(*@note)
|
1695
|
+
end
|
1696
|
+
@note
|
1697
|
+
end
|
1698
|
+
|
1699
|
+
#
|
1700
|
+
# 日時要素の正規化
|
1701
|
+
#
|
1702
|
+
# @param [Array<Numeric>] source 正規化しようとしている日時要素の Array
|
1703
|
+
# @param [Array<Numeric>] other 日時要素ごとに加減算を行う場合、加減算量の Array を指定する
|
1704
|
+
# @param [Block] block
|
1705
|
+
# @note
|
1706
|
+
# 日付要素と時刻要素に関連がある場合、block を指定して、両者の
|
1707
|
+
# 情報をやり取りする( yield で通日を渡し、通日を返してもらう)。
|
1708
|
+
#
|
1709
|
+
# 例1: 夏時間制を採用している場合、日付によって時刻の正規化の仕方が影響を受ける
|
1710
|
+
#
|
1711
|
+
# 例2: 日の境界が日没の場合、当該時刻が日没の前か後かで日付が変わる
|
1712
|
+
#
|
1713
|
+
# @return [Array<Numeric>] 正規化された日時要素の Array
|
1714
|
+
#
|
1715
|
+
# 日時要素は、それぞれの When::TM::Calendar や When::TM::Clock の実装に応じて有効な値となっている。
|
1716
|
+
#
|
1717
|
+
def _validate(source, other=nil, &block)
|
1718
|
+
return _encode(_decode(source, other, &block))
|
1719
|
+
end
|
1720
|
+
|
1721
|
+
# 期間指定用 Array の桁数合わせ
|
1722
|
+
#
|
1723
|
+
# @param [Array<Numeric>] period
|
1724
|
+
#
|
1725
|
+
# @return [Array<Numeric>] 桁数合わせをした Array
|
1726
|
+
#
|
1727
|
+
def _arrange_length(period)
|
1728
|
+
return period unless period.kind_of?(Array)
|
1729
|
+
diff = @indices.length - period.length + 1
|
1730
|
+
return period if (diff == 0)
|
1731
|
+
return (diff > 0) ? Array.new(diff, 0) + period : period[(-diff)..-1]
|
1732
|
+
end
|
1733
|
+
|
1734
|
+
# @private
|
1735
|
+
#
|
1736
|
+
# 対応する ::Date の start 属性
|
1737
|
+
def _default_start
|
1738
|
+
::Date::GREGORIAN
|
1739
|
+
end
|
1740
|
+
|
1741
|
+
# protected
|
1742
|
+
|
1743
|
+
#
|
1744
|
+
# 日時要素の encode
|
1745
|
+
#
|
1746
|
+
# @param [Array<Numeric>] source 日時要素の内部表現に対応する Array
|
1747
|
+
#
|
1748
|
+
# @return [Array<Numeric>] 日時要素の外部表現に対応する Array
|
1749
|
+
#
|
1750
|
+
def _encode(source, border=@border)
|
1751
|
+
# source は非破壊
|
1752
|
+
date = source.dup
|
1753
|
+
|
1754
|
+
# 外部表現に戻す
|
1755
|
+
date[0] = +date[0]
|
1756
|
+
(@base.length-1).downto(@unit.length-1) do |i|
|
1757
|
+
date[i] = _from_index(date[0..i]) || date[i] + (@base[i]||0)
|
1758
|
+
end
|
1759
|
+
date[0] = source[0]
|
1760
|
+
|
1761
|
+
# 結果を反映
|
1762
|
+
date = border._adjust_epoch(date, self) if border
|
1763
|
+
_encode_upper_structure(date)
|
1764
|
+
end
|
1765
|
+
|
1766
|
+
private
|
1767
|
+
|
1768
|
+
#
|
1769
|
+
# 日時要素の decode
|
1770
|
+
#
|
1771
|
+
# @param [Array<Numeric>] source 日時要素の外部表現に対応する Array
|
1772
|
+
#
|
1773
|
+
# @return [Array<Numeric>] 日時要素の内部表現に対応する Array
|
1774
|
+
#
|
1775
|
+
def _decode(source, other=nil)
|
1776
|
+
|
1777
|
+
# other の正規化
|
1778
|
+
period = other ? other.dup : Array.new(@indices.length+1,0)
|
1779
|
+
|
1780
|
+
# 上の位の集約
|
1781
|
+
date = _decode_upper_structure(source.dup)
|
1782
|
+
if (@index_of_MSC > 0) && other
|
1783
|
+
u = 1
|
1784
|
+
s = period[@index_of_MSC]
|
1785
|
+
(@index_of_MSC-1).downto(0) do |i|
|
1786
|
+
u *= @indices[i].unit
|
1787
|
+
s += u * period[i]
|
1788
|
+
end
|
1789
|
+
period = [s] + period[(@index_of_MSC+1)..-1]
|
1790
|
+
end
|
1791
|
+
|
1792
|
+
# 下の位の既定値
|
1793
|
+
unless date[1] || !@border
|
1794
|
+
date[0...@base.length] = @border.border([@border._date_adjust(date[0])], self)
|
1795
|
+
end
|
1796
|
+
|
1797
|
+
# 要素数固定部分の正規化(上 -> 下) - ISO8601 の 小数要素(ex. "T23:20.8")の処理
|
1798
|
+
coordinates = [date]
|
1799
|
+
coordinates << period if other
|
1800
|
+
coordinates.each do |coord|
|
1801
|
+
carry = 0
|
1802
|
+
@unit.length.times do |i|
|
1803
|
+
if carry == 0
|
1804
|
+
break unless coord[i]
|
1805
|
+
else
|
1806
|
+
coord[i] ||= 0
|
1807
|
+
coord[i] += carry * unit[i]
|
1808
|
+
end
|
1809
|
+
if coord[i].kind_of?(Integer)
|
1810
|
+
carry = 0
|
1811
|
+
else
|
1812
|
+
if i < @unit.length-1
|
1813
|
+
carry = (coord[i].kind_of?(Pair) ? coord[i].trunk : coord[i]) % 1
|
1814
|
+
coord[i] -= carry
|
1815
|
+
end
|
1816
|
+
coord[i] = coord[i].to_i if coord[i].kind_of?(Float) && coord[i] == coord[i].to_i
|
1817
|
+
end
|
1818
|
+
end
|
1819
|
+
end
|
1820
|
+
|
1821
|
+
# 要素数固定部分の正規化(下 -> 上)
|
1822
|
+
carry = 0
|
1823
|
+
(@unit.length-1).downto(1) do |i|
|
1824
|
+
if date[i]
|
1825
|
+
digit = date[i] + ((other || date[i]>=0) ? period[i]-@base[i] : @unit[i])
|
1826
|
+
else
|
1827
|
+
digit = period[i]
|
1828
|
+
end
|
1829
|
+
carry, date[i] = (digit + carry).divmod(@unit[i])
|
1830
|
+
end
|
1831
|
+
year = date[0] + period[0] + carry
|
1832
|
+
|
1833
|
+
# 要素数可変部分の正規化
|
1834
|
+
limit = @base.length-1
|
1835
|
+
count = nil
|
1836
|
+
date[0] = +year
|
1837
|
+
if @base.length > @unit.length
|
1838
|
+
@unit.length.upto(limit) do |i|
|
1839
|
+
len = _length(date[0...i])
|
1840
|
+
if date[i]
|
1841
|
+
plus = date[i]>=0
|
1842
|
+
digit = !plus ? +date[i] : _to_index(date[0..i]) || +date[i] - @base[i]
|
1843
|
+
digit += (plus || other) ? period[i] : len
|
1844
|
+
else
|
1845
|
+
digit = period[i]
|
1846
|
+
end
|
1847
|
+
|
1848
|
+
if i==limit then
|
1849
|
+
# 最下位
|
1850
|
+
if (0...len) === digit
|
1851
|
+
# 要素が範囲内
|
1852
|
+
date[i] = digit
|
1853
|
+
elsif other && period[i] == 0
|
1854
|
+
# 要素が範囲外で、加算自体はあるが“日”の加算なし
|
1855
|
+
date[i] = len-1
|
1856
|
+
else
|
1857
|
+
# 要素が範囲外で、加算自体がないか“日”の加算あり
|
1858
|
+
date[i] = 0
|
1859
|
+
count = _coordinates_to_number(*date)+digit
|
1860
|
+
count = yield(count) if block_given?
|
1861
|
+
date = _number_to_coordinates(count)
|
1862
|
+
end
|
1863
|
+
|
1864
|
+
else
|
1865
|
+
# 最下位以外
|
1866
|
+
# 要素が大きすぎる場合
|
1867
|
+
while digit >= len do
|
1868
|
+
digit -= len
|
1869
|
+
carry = 1
|
1870
|
+
(i-1).downto(1) do |k|
|
1871
|
+
if date[k] >= _length(date[0...k])-1
|
1872
|
+
date[k] = 0
|
1873
|
+
carry = 1
|
1874
|
+
else
|
1875
|
+
date[k] += 1
|
1876
|
+
carry = 0
|
1877
|
+
break
|
1878
|
+
end
|
1879
|
+
end
|
1880
|
+
date[0] += carry
|
1881
|
+
len = _length(date[0...i])
|
1882
|
+
end
|
1883
|
+
|
1884
|
+
# 要素が小さすぎる場合
|
1885
|
+
while digit < 0 do
|
1886
|
+
date[i-1] -= 1
|
1887
|
+
digit += _length(date[0...i])
|
1888
|
+
(i-1).downto(1) do |k|
|
1889
|
+
break if (date[k] >= 0)
|
1890
|
+
date[k-1] -= 1
|
1891
|
+
date[k] = _length(date[0...k]) - 1
|
1892
|
+
end
|
1893
|
+
end
|
1894
|
+
|
1895
|
+
# 要素が範囲内
|
1896
|
+
date[i] = digit
|
1897
|
+
end
|
1898
|
+
end
|
1899
|
+
end
|
1900
|
+
date[0] = year + (date[0] - +year)
|
1901
|
+
|
1902
|
+
# 時刻部分による補正が入る場合
|
1903
|
+
if block_given? && !count
|
1904
|
+
count = _coordinates_to_number(*date)
|
1905
|
+
modified = yield(count)
|
1906
|
+
date = _number_to_coordinates(modified) unless count == modified
|
1907
|
+
end
|
1908
|
+
|
1909
|
+
# 結果を返す
|
1910
|
+
return date
|
1911
|
+
end
|
1912
|
+
|
1913
|
+
#
|
1914
|
+
# 日時要素の下限を取得する
|
1915
|
+
#
|
1916
|
+
# @param [Array<Numeric>] date 日時要素
|
1917
|
+
#
|
1918
|
+
# @return [Integer] 日時要素の下限
|
1919
|
+
#
|
1920
|
+
def _base(date)
|
1921
|
+
return @base[date.length]
|
1922
|
+
end
|
1923
|
+
|
1924
|
+
#
|
1925
|
+
# 日時要素の番号から要素を取得する配列を返す
|
1926
|
+
#
|
1927
|
+
#def _ids(date)
|
1928
|
+
# return nil
|
1929
|
+
#end
|
1930
|
+
|
1931
|
+
#
|
1932
|
+
# 日時要素の要素数を取得する(直下の要素)
|
1933
|
+
#
|
1934
|
+
#def _length(date)
|
1935
|
+
# return @unit[date.length]
|
1936
|
+
#end
|
1937
|
+
|
1938
|
+
#
|
1939
|
+
# 日時要素の要素数を取得する(全要素)
|
1940
|
+
#
|
1941
|
+
# @param [Array<Numeric>] date 日時要素(内部表現)
|
1942
|
+
#
|
1943
|
+
# @return [Integer] 日時要素の要素数
|
1944
|
+
# @note 一般に date が 1要素ならその要素の年の日数、2要素ならその要素の年月の日数になる。
|
1945
|
+
#
|
1946
|
+
def _sum_(date)
|
1947
|
+
return @unit[date.length..-1].inject(1) {|p, u| p * u }
|
1948
|
+
end
|
1949
|
+
|
1950
|
+
def _normalize_temporal
|
1951
|
+
|
1952
|
+
# method cash
|
1953
|
+
@_m_cash_lock_ = Mutex.new if When.multi_thread
|
1954
|
+
|
1955
|
+
# label
|
1956
|
+
@label = When::BasicTypes::M17n.label(@label)
|
1957
|
+
|
1958
|
+
# Origin and Upper Digits
|
1959
|
+
@origin_of_MSC ||= - @border.behavior * 1 if @border
|
1960
|
+
@origin_of_MSC = Pair._en_number(@origin_of_MSC)
|
1961
|
+
@origin_of_LSC = Pair._en_number(@origin_of_LSC)
|
1962
|
+
@index_of_MSC = Pair._en_number(@index_of_MSC)
|
1963
|
+
if @index_of_MSC != 0
|
1964
|
+
extend OriginAndUpperDigits
|
1965
|
+
elsif @origin_of_MSC != 0
|
1966
|
+
extend OriginOnly
|
1967
|
+
end
|
1968
|
+
|
1969
|
+
# unit
|
1970
|
+
@unit = [nil]
|
1971
|
+
(@index_of_MSC...@indices.length).each do |i|
|
1972
|
+
break unless @indices[i].unit
|
1973
|
+
@unit << @indices[i].unit
|
1974
|
+
end
|
1975
|
+
|
1976
|
+
# base & pair
|
1977
|
+
@base = [nil]
|
1978
|
+
@pair = [false]
|
1979
|
+
(@index_of_MSC...@indices.length).each do |i|
|
1980
|
+
raise ArgumentError, "Base not defined" unless @indices[i].base
|
1981
|
+
@base << @indices[i].base
|
1982
|
+
@pair << (@indices[i].branch != nil)
|
1983
|
+
end
|
1984
|
+
extend IndexConversion unless @pair.uniq == [false]
|
1985
|
+
|
1986
|
+
# note
|
1987
|
+
@note ||= 'Default'
|
1988
|
+
|
1989
|
+
# keys
|
1990
|
+
@keys = @indices.inject(label.instance_of?(When::Locale) ? label.keys : []) {|key, index| key |= index.keys}
|
1991
|
+
end
|
1992
|
+
|
1993
|
+
def _default_index_of_MSC
|
1994
|
+
unless @index_of_MSC
|
1995
|
+
[:_coordinates_to_number, :_coordinates_to_number_].each do |to_n|
|
1996
|
+
if respond_to?(to_n)
|
1997
|
+
@index_of_MSC = @indices.length - method(to_n).arity + 1
|
1998
|
+
break
|
1999
|
+
end
|
2000
|
+
end
|
2001
|
+
end
|
2002
|
+
end
|
2003
|
+
|
2004
|
+
# 何もしない
|
2005
|
+
def _return_nil(source); nil end
|
2006
|
+
alias :_from_index :_return_nil
|
2007
|
+
alias :_to_index :_return_nil
|
2008
|
+
|
2009
|
+
def _do_nothing(source); source end
|
2010
|
+
alias :_encode_upper_structure :_do_nothing
|
2011
|
+
alias :_decode_upper_structure :_do_nothing
|
2012
|
+
|
2013
|
+
# @private
|
2014
|
+
module IndexConversion
|
2015
|
+
#
|
2016
|
+
# indexのPair化
|
2017
|
+
#
|
2018
|
+
# @param [Array<Numeric>] date 最下位が index になっている日時要素
|
2019
|
+
#
|
2020
|
+
# @return [When::Coordinates::Pair] 最下位の index に対応する When::Coordinates::Pair
|
2021
|
+
#
|
2022
|
+
def _from_index(date)
|
2023
|
+
return nil unless @pair[date.size-1]
|
2024
|
+
ids = _ids(date[0..-2])
|
2025
|
+
m = ids[date[-1]] if (ids)
|
2026
|
+
return Pair._force_pair(m) if (ids && m)
|
2027
|
+
return Pair.new(+date[-1]+@base[date.length-1], 0)
|
2028
|
+
rescue ArgumentError
|
2029
|
+
nil
|
2030
|
+
end
|
2031
|
+
|
2032
|
+
#
|
2033
|
+
# Pairのindex化
|
2034
|
+
#
|
2035
|
+
# @param [Array<Numeric>] date 最下位が When::Coordinates::Pair になっている日時要素
|
2036
|
+
#
|
2037
|
+
# @return [When::Coordinates::Pair] 最下位の When::Coordinates::Pair に対応する index
|
2038
|
+
#
|
2039
|
+
def _to_index(date)
|
2040
|
+
return nil unless @pair[date.size-1]
|
2041
|
+
ids = _ids(date[0..-2])
|
2042
|
+
i = ids.index(date[-1]) if ids
|
2043
|
+
return i if i
|
2044
|
+
return nil unless ids && date[-1].kind_of?(Pair)
|
2045
|
+
digit = Pair.new(date[-1].trunk, date[-1].branch)
|
2046
|
+
while digit.branch > 0
|
2047
|
+
digit.branch -= 1
|
2048
|
+
i = ids.index(digit)
|
2049
|
+
return i + date[-1].branch - digit.branch if i
|
2050
|
+
end
|
2051
|
+
return nil
|
2052
|
+
rescue ArgumentError
|
2053
|
+
nil
|
2054
|
+
end
|
2055
|
+
end
|
2056
|
+
|
2057
|
+
alias :_method_missing :method_missing
|
2058
|
+
|
2059
|
+
# その他のメソッド
|
2060
|
+
# When::Coordinates::Temporal で定義されていないメソッドは
|
2061
|
+
# 処理を下記に移譲する(番号は優先順位)
|
2062
|
+
# When::CalendarNote
|
2063
|
+
# (1) @note
|
2064
|
+
# (2) SolarTerms
|
2065
|
+
# (3) LunarPhases
|
2066
|
+
# When::Ephemeris::Formula
|
2067
|
+
# (4)@formula[0]
|
2068
|
+
#
|
2069
|
+
def method_missing(name, *args, &block)
|
2070
|
+
unless When::Parts::MethodCash::Escape.key?(name)
|
2071
|
+
if note.respond_to?(name)
|
2072
|
+
if note.class::CalendarDepend
|
2073
|
+
instance_eval %Q{
|
2074
|
+
def #{name}(*args, &block)
|
2075
|
+
@note.send("#{name}", *(args + [self]), &block)
|
2076
|
+
end
|
2077
|
+
} unless When::Parts::MethodCash.escape(name)
|
2078
|
+
return @note.send(name, *(args + [self]), &block)
|
2079
|
+
else
|
2080
|
+
instance_eval %Q{
|
2081
|
+
def #{name}(*args, &block)
|
2082
|
+
@note.send("#{name}", *args, &block)
|
2083
|
+
end
|
2084
|
+
} unless When::Parts::MethodCash.escape(name)
|
2085
|
+
return @note.send(name, *args, &block)
|
2086
|
+
end
|
2087
|
+
end
|
2088
|
+
['SolarTerms', 'LunarPhases'].each do |note|
|
2089
|
+
if When.CalendarNote(note).respond_to?(name)
|
2090
|
+
instance_eval %Q{
|
2091
|
+
def #{name}(*args, &block)
|
2092
|
+
When.CalendarNote("#{note}").send("#{name}", *args, &block)
|
2093
|
+
end
|
2094
|
+
} unless When::Parts::MethodCash.escape(name)
|
2095
|
+
return When.CalendarNote(note).send(name, *args, &block)
|
2096
|
+
end
|
2097
|
+
end
|
2098
|
+
if When::Ephemeris::Formula.method_defined?(name)
|
2099
|
+
unless respond_to?(:forwarded_formula, true)
|
2100
|
+
extend When::Ephemeris::Formula::ForwardedFormula
|
2101
|
+
@formula ||= When::Ephemeris::Formula.new({:location=>@location})
|
2102
|
+
@formula = When.Resource(Array(@formula), '_ep:')
|
2103
|
+
end
|
2104
|
+
instance_eval %Q{
|
2105
|
+
def #{name}(*args, &block)
|
2106
|
+
forward = forwarded_formula("#{name}", args[0])
|
2107
|
+
return forward.send("#{name}", *args, &block) if forward
|
2108
|
+
_method_missing("#{name}", *args, &block)
|
2109
|
+
end
|
2110
|
+
} unless When::Parts::MethodCash.escape(name)
|
2111
|
+
forward = forwarded_formula(name, args[0])
|
2112
|
+
return forward.send(name, *args, &block) if forward
|
2113
|
+
end
|
2114
|
+
end
|
2115
|
+
_method_missing(name, *args, &block)
|
2116
|
+
end
|
2117
|
+
|
2118
|
+
# @private
|
2119
|
+
module OriginOnly
|
2120
|
+
# 上の位の付加
|
2121
|
+
#
|
2122
|
+
# @param [Array<Numeric>] source 日時要素の内部表現に対応する Array
|
2123
|
+
#
|
2124
|
+
# @return [Array<Numeric>] 日時要素の外部表現に対応する Array
|
2125
|
+
#
|
2126
|
+
def _encode_upper_structure(source)
|
2127
|
+
date = source.dup
|
2128
|
+
date[0] += @origin_of_MSC
|
2129
|
+
return date
|
2130
|
+
end
|
2131
|
+
|
2132
|
+
# 上の位の除去
|
2133
|
+
#
|
2134
|
+
# @param [Array<Numeric>] source 日時要素の外部表現に対応する Array
|
2135
|
+
#
|
2136
|
+
# @return [Array<Numeric>] 日時要素の内部表現に対応する Array
|
2137
|
+
#
|
2138
|
+
def _decode_upper_structure(source)
|
2139
|
+
date = source.dup
|
2140
|
+
date[0] -= @origin_of_MSC
|
2141
|
+
return date
|
2142
|
+
end
|
2143
|
+
end
|
2144
|
+
|
2145
|
+
# @private
|
2146
|
+
module OriginAndUpperDigits
|
2147
|
+
# 上の位の付加
|
2148
|
+
#
|
2149
|
+
# @param [Array<Numeric>] source 日時要素の内部表現に対応する Array
|
2150
|
+
#
|
2151
|
+
# @return [Array<Numeric>] 日時要素の外部表現に対応する Array
|
2152
|
+
#
|
2153
|
+
def _encode_upper_structure(source)
|
2154
|
+
date = source.dup
|
2155
|
+
date[0] += @origin_of_MSC
|
2156
|
+
@index_of_MSC.downto(1) do |i|
|
2157
|
+
carry, date[0] = (+date[0]).divmod(@indices[i-1].unit)
|
2158
|
+
date[0] += @indices[i-1].base
|
2159
|
+
date.unshift(carry)
|
2160
|
+
end
|
2161
|
+
return date
|
2162
|
+
end
|
2163
|
+
|
2164
|
+
# 上の位の除去
|
2165
|
+
#
|
2166
|
+
# @param [Array<Numeric>] source 日時要素の外部表現に対応する Array
|
2167
|
+
#
|
2168
|
+
# @return [Array<Numeric>] 日時要素の内部表現に対応する Array
|
2169
|
+
#
|
2170
|
+
def _decode_upper_structure(source)
|
2171
|
+
date = source.dup
|
2172
|
+
u = 1
|
2173
|
+
s = 0
|
2174
|
+
@index_of_MSC.downto(1) do |i|
|
2175
|
+
s += u * (+date[i] - @indices[i-1].base) if (date[i])
|
2176
|
+
u *= @indices[i-1].unit
|
2177
|
+
end
|
2178
|
+
date[@index_of_MSC] = s + u * (+date[0]) - @origin_of_MSC
|
2179
|
+
return date[@index_of_MSC..-1]
|
2180
|
+
end
|
2181
|
+
end
|
2182
|
+
end
|
2183
|
+
|
2184
|
+
#
|
2185
|
+
# 日時要素の境界 - Border
|
2186
|
+
#
|
2187
|
+
class Border < When::BasicTypes::Object
|
2188
|
+
#
|
2189
|
+
# 境界の振舞
|
2190
|
+
#
|
2191
|
+
# @return [Numeric]
|
2192
|
+
#
|
2193
|
+
# Pair(-1,+1) - 暦年/暦日が進む(境界が前年/日にあり、境界後が当年/日の扱いになる)
|
2194
|
+
#
|
2195
|
+
# Pair( 0, 0) - 暦年/暦日が戻る(境界が当年/日にあり、境界前が前年/日の扱いになる)
|
2196
|
+
#
|
2197
|
+
def behavior
|
2198
|
+
@border[0]
|
2199
|
+
end
|
2200
|
+
|
2201
|
+
# 境界の取得
|
2202
|
+
#
|
2203
|
+
# @param [Array<Numeric>] date 境界を計算する年/日
|
2204
|
+
# @param [When::TM::ReferenceSystem] frame 使用する暦法/時法
|
2205
|
+
#
|
2206
|
+
# @return [Array<Numeric>] その年/日の境界
|
2207
|
+
#
|
2208
|
+
def border(date=[], frame=nil)
|
2209
|
+
last = date.length-1
|
2210
|
+
return @border if last<0
|
2211
|
+
b_date = date[0..last] + @border[(last+1)..-1]
|
2212
|
+
branch = @border[last] * 0
|
2213
|
+
b_date[last] = When::Coordinates::Pair.new(date[last] * 1, branch)
|
2214
|
+
return b_date
|
2215
|
+
end
|
2216
|
+
|
2217
|
+
# 境界の正規化
|
2218
|
+
#
|
2219
|
+
# @param [Array<Numeric>] date 境界を計算する年/日
|
2220
|
+
# @param [When::TM::ReferenceSystem] frame 使用する暦法/時法
|
2221
|
+
#
|
2222
|
+
# @return [Array<Numeric>] その年/日の境界
|
2223
|
+
#
|
2224
|
+
def _adjust_epoch(date, frame=nil)
|
2225
|
+
s_date = date.dup
|
2226
|
+
e_date = border([+date[0]], frame)
|
2227
|
+
branch = behavior * 0
|
2228
|
+
branch += 1 if (s_date[1..-1] <=> e_date[1..-1]) < 0
|
2229
|
+
s_date[0] = When::Coordinates::Pair.new(+s_date[0]-branch, branch)
|
2230
|
+
return s_date
|
2231
|
+
end
|
2232
|
+
|
2233
|
+
# 日付の補正
|
2234
|
+
# @private
|
2235
|
+
def _date_adjust(source)
|
2236
|
+
source
|
2237
|
+
end
|
2238
|
+
|
2239
|
+
private
|
2240
|
+
|
2241
|
+
# 要素の正規化
|
2242
|
+
def _normalize(args=[], options={})
|
2243
|
+
@border = When::Coordinates::Pair._en_pair_date_time(@border) if @border.kind_of?(String)
|
2244
|
+
end
|
2245
|
+
end
|
2246
|
+
|
2247
|
+
#
|
2248
|
+
# 日時要素の境界 - 年/日によって、異なる境界を使用する場合
|
2249
|
+
#
|
2250
|
+
class MultiBorder < Border
|
2251
|
+
|
2252
|
+
#
|
2253
|
+
# 境界の配列
|
2254
|
+
# @return [Array<When::Coordinates::Border>]
|
2255
|
+
attr_reader :borders
|
2256
|
+
|
2257
|
+
#
|
2258
|
+
# 境界の振舞
|
2259
|
+
#
|
2260
|
+
# @return [Numeric]
|
2261
|
+
#
|
2262
|
+
# Pair(-1,+1) - 暦年/暦日が進む(境界が前年/日にあり、境界後が当年/日の扱いになる)
|
2263
|
+
#
|
2264
|
+
# Pair( 0, 0) - 暦年/暦日が戻る(境界が当年/日にあり、境界前が前年/日の扱いになる)
|
2265
|
+
#
|
2266
|
+
def behavior
|
2267
|
+
@borders[0][:border].behavior
|
2268
|
+
end
|
2269
|
+
|
2270
|
+
# 境界の取得
|
2271
|
+
#
|
2272
|
+
# @param [Array<Numeric>] date 境界を計算する年/日
|
2273
|
+
# @param [When::TM::ReferenceSystem] frame 使用する暦法/時法
|
2274
|
+
#
|
2275
|
+
# @return [Array<Numeric>] その年/日の境界
|
2276
|
+
#
|
2277
|
+
def border(date=[], frame=nil)
|
2278
|
+
last = date.length-1
|
2279
|
+
return @borders[0][:boder] if (last<0)
|
2280
|
+
@borders.each do |border|
|
2281
|
+
return border[:border].border(date, frame) if date[0] >= border[:key]
|
2282
|
+
end
|
2283
|
+
date[0..last]
|
2284
|
+
end
|
2285
|
+
|
2286
|
+
# 境界の正規化
|
2287
|
+
#
|
2288
|
+
# @param [Array<Numeric>] date 境界を計算する年/日
|
2289
|
+
# @param [When::TM::ReferenceSystem] frame 使用する暦法/時法
|
2290
|
+
#
|
2291
|
+
# @return [Array<Numeric>] その年/日の境界
|
2292
|
+
#
|
2293
|
+
def _adjust_epoch(date, frame=nil)
|
2294
|
+
@borders.each do |border|
|
2295
|
+
next unless date[0] >= border[:key]
|
2296
|
+
s_date = date.dup
|
2297
|
+
e_date = border[:border].border(date[0..0], frame)
|
2298
|
+
branch = border[:border].behavior * 0
|
2299
|
+
branch += 1 if ((s_date[1..-1] <=> e_date[1..-1]) < 0)
|
2300
|
+
s_date[0] = When::Coordinates::Pair.new(+s_date[0]-branch, branch)
|
2301
|
+
return s_date
|
2302
|
+
end
|
2303
|
+
date
|
2304
|
+
end
|
2305
|
+
|
2306
|
+
private
|
2307
|
+
|
2308
|
+
# 要素の正規化
|
2309
|
+
def _normalize(args=[], options={})
|
2310
|
+
if @borders.kind_of?(String)
|
2311
|
+
list = @borders.split(/(\(.+?\))/)
|
2312
|
+
list.shift if list[0]==''
|
2313
|
+
list.unshift(-Float::MAX) unless list[0] =~ /\(/
|
2314
|
+
list.push('0-1-1') if list[-1] =~ /\(/
|
2315
|
+
@borders = []
|
2316
|
+
loop do
|
2317
|
+
key, border, *list = list
|
2318
|
+
break unless key
|
2319
|
+
key = $1.to_i if key.kind_of?(String) && /\((.+?)\)/ =~ key
|
2320
|
+
@borders << {:key=>key, :border=>When.Border(border)}
|
2321
|
+
end
|
2322
|
+
end
|
2323
|
+
@borders = @borders.sort_by {|border| -border[:key]}
|
2324
|
+
end
|
2325
|
+
end
|
2326
|
+
|
2327
|
+
#
|
2328
|
+
# 基準暦法の新年による境界
|
2329
|
+
#
|
2330
|
+
class CalendarBorder < Border
|
2331
|
+
|
2332
|
+
class << self
|
2333
|
+
|
2334
|
+
private
|
2335
|
+
|
2336
|
+
def _behalf_of(iri)
|
2337
|
+
base = iri.dup.sub!('/Coordinates/','/CalendarTypes/')
|
2338
|
+
return nil unless base
|
2339
|
+
self.new({'engine'=>When::Parts::Resource._instance(base)})
|
2340
|
+
end
|
2341
|
+
end
|
2342
|
+
|
2343
|
+
# 境界の取得
|
2344
|
+
#
|
2345
|
+
# @param [Array<Numeric>] date 境界を計算する年
|
2346
|
+
# @param [When::TM::ReferenceSystem] frame 使用する暦法/時法
|
2347
|
+
#
|
2348
|
+
# @return [Array<Numeric>] その年の境界
|
2349
|
+
#
|
2350
|
+
def border(date=[], frame=nil)
|
2351
|
+
last = date.length-1
|
2352
|
+
return @border if last<0
|
2353
|
+
args = date.dup << {:frame=>@engine}
|
2354
|
+
args[0] += frame.origin_of_MSC + @border[last] * 1 + (frame.epoch_in_CE - @engine.epoch_in_CE)
|
2355
|
+
b_date = frame._encode(frame._number_to_coordinates(When.tm_pos(*args).to_i), nil)
|
2356
|
+
branch = @border[last] * 0
|
2357
|
+
b_date[last] = When::Coordinates::Pair.new(date[last] * 1, branch)
|
2358
|
+
return b_date
|
2359
|
+
end
|
2360
|
+
|
2361
|
+
private
|
2362
|
+
|
2363
|
+
# 要素の正規化
|
2364
|
+
def _normalize(args=[], options={})
|
2365
|
+
@border ||= [When::Coordinates::Pair.new(+1,-1),0,0]
|
2366
|
+
@border = When::Coordinates::Pair._en_pair_date_time(@border) if @border.kind_of?(String)
|
2367
|
+
@engine = When.Calendar(@engine)
|
2368
|
+
end
|
2369
|
+
end
|
2370
|
+
|
2371
|
+
#
|
2372
|
+
# 日時要素の境界 - 日の出,日の入り
|
2373
|
+
#
|
2374
|
+
class DayBorder < Border
|
2375
|
+
|
2376
|
+
# 境界の取得
|
2377
|
+
#
|
2378
|
+
# @param [Array<Numeric>] date 境界を計算する日
|
2379
|
+
# @param [When::TM::ReferenceSystem] clock 使用する時法
|
2380
|
+
#
|
2381
|
+
# @return [Array<Numeric>] その日の境界
|
2382
|
+
#
|
2383
|
+
# @note 属性 @event によって境界を計算する (see {When::Ephemeris::Formula#day_event})
|
2384
|
+
#
|
2385
|
+
def border(date=[], clock=When::UTC)
|
2386
|
+
return @border unless date[0] && clock.formula
|
2387
|
+
|
2388
|
+
time =
|
2389
|
+
clock._number_to_coordinates(clock.second *
|
2390
|
+
clock.time_standard.from_dynamical_time(
|
2391
|
+
When::TM::JulianDate._d_to_t(
|
2392
|
+
clock.formula.first.day_event(
|
2393
|
+
clock.time_standard.to_dynamical_date(date[0] + @border[0]*0), @event, When.Resource('_ep:Sun'), @height
|
2394
|
+
))))
|
2395
|
+
|
2396
|
+
time[0] += When::TM::JulianDate::JD19700101
|
2397
|
+
time[0] = When::Coordinates::Pair.new(time[0]-@border[0]*0, @border[0]*0) unless @border[0]*0 == 0
|
2398
|
+
clock._encode(time, false)
|
2399
|
+
end
|
2400
|
+
|
2401
|
+
# 日付の補正
|
2402
|
+
# @private
|
2403
|
+
def _date_adjust(source)
|
2404
|
+
source * 1 + @border[0] * 0
|
2405
|
+
end
|
2406
|
+
end
|
2407
|
+
|
2408
|
+
#
|
2409
|
+
# 日時要素の境界 - 日の出
|
2410
|
+
#
|
2411
|
+
class Sunrise < DayBorder
|
2412
|
+
|
2413
|
+
private
|
2414
|
+
|
2415
|
+
# 要素の正規化
|
2416
|
+
def _normalize(args=[], options={})
|
2417
|
+
@border = [0,0,0,0]
|
2418
|
+
@event = -1
|
2419
|
+
@height ||= '0'
|
2420
|
+
end
|
2421
|
+
end
|
2422
|
+
|
2423
|
+
#
|
2424
|
+
# 日時要素の境界 - 日の入り
|
2425
|
+
#
|
2426
|
+
class Sunset < DayBorder
|
2427
|
+
|
2428
|
+
private
|
2429
|
+
|
2430
|
+
# 要素の正規化
|
2431
|
+
def _normalize(args=[], options={})
|
2432
|
+
@border = [When::Coordinates::Pair.new(+1,-1),0,0,0]
|
2433
|
+
@event = +1
|
2434
|
+
@height ||= '0'
|
2435
|
+
end
|
2436
|
+
end
|
2437
|
+
end
|