when_exe 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -586,8 +586,8 @@ module When::Coordinates
|
|
586
586
|
['三寶吉', '神吉', nil, '解除剃頭壊垣破屋吉', nil , nil ], # 21 乙酉
|
587
587
|
['三寶吉+', nil, nil, '入學起土祠戸種蒔吉', nil , nil ], # 22 丙戌
|
588
588
|
['三寶吉+', nil, nil, '結婚裁衣市買納財種蒔移徒吉', nil , nil ], # 23 丁亥
|
589
|
-
['三寶吉+', nil, '雑事吉', '加冠祠祀移徒出行療病入學修井竈碓吉', 'けんふく 入学' , 'かといて' ], # 24 戊子
|
590
|
-
['三寶吉+', nil, nil, '塞穴吉', '井ほり' , nil ], # 25 己丑
|
589
|
+
['三寶吉+', nil, '雑事吉', '加冠祠祀移徒出行療病入學修井竈碓吉', '(けんふく) (入学)' , 'かといて' ], # 24 戊子
|
590
|
+
['三寶吉+', nil, nil, '塞穴吉', '(井ほり)' , nil ], # 25 己丑
|
591
591
|
['三寶吉', nil, nil, '拜官結婚納婦出行吉', nil , nil ], # 26 庚寅
|
592
592
|
[nil, nil, nil, '此日不裁衣', nil , 'たねまき みそつくり' ], # 27 辛卯
|
593
593
|
[nil, nil, nil, '祀戸経絡裁衣市買納財吉', nil , '木こり' ], # 28 壬辰
|
@@ -633,7 +633,7 @@ module When::Coordinates
|
|
633
633
|
['三寶吉', '神吉', nil, '加冠拜官謝土市買納財吉', nil , nil ], # 6 庚午
|
634
634
|
['三寶吉', nil, nil, '裁衣市買納財安床帳吉', 'くらたて 井ほり' , nil ], # 7 辛未
|
635
635
|
['三寶吉+', '神吉', nil, '解除漁葬斬草除服吉', '入学' , '入学' ], # 8 壬申
|
636
|
-
['三寶吉', nil, nil, '療病剃頭壊垣破屋解除元服葬斬草吉',
|
636
|
+
['三寶吉', nil, nil, '療病剃頭壊垣破屋解除元服葬斬草吉', 'やたて' , 'たねかし たねまき' ], # 9 癸酉
|
637
637
|
['三寶吉+', nil, '雑事吉', '壊垣破屋吉', 'かといて' , 'わたまし' ], # 10 甲戌
|
638
638
|
[nil, nil, '雑事吉', '祠祀移徒入學剃頭起土竪柱上梁修宅門戸井竈碓磑裁衣市買納財吉', 'みそすつくり' , 'たねかし みそすつくり' ], # 11 乙亥
|
639
639
|
['三寶吉+', nil, nil, '加冠嫁娶竪柱納婦結婚移徒起土上梁蓋屋修宅門戸種蒔斬草吉', 'たねかし' , 'あさまき たねかし' ], # 12 丙子
|
@@ -682,8 +682,8 @@ module When::Coordinates
|
|
682
682
|
['三寶吉', '神吉', nil, '裁衣市買納財安床帳吉', 'たねかし' , 'いちたち かといて' ], # 55 己未
|
683
683
|
[nil, '神吉', nil, '漁解除元服葬斬草吉', nil , nil ], # 56 庚申
|
684
684
|
[nil, nil, nil, nil, nil , nil ], # 57 辛酉
|
685
|
-
['三寶吉+', nil, nil, '壊垣破屋吉',
|
686
|
-
['三寶吉+', nil, nil, '祠祀剃頭入學裁衣市買納財吉', 'たねかし
|
685
|
+
['三寶吉+', nil, nil, '壊垣破屋吉', 'あさまき' , 'あさまき たねかし' ], # 58 壬戌
|
686
|
+
['三寶吉+', nil, nil, '祠祀剃頭入學裁衣市買納財吉', 'たねかし' , '入学 たねかし' ], # 59 癸亥
|
687
687
|
],
|
688
688
|
[ # 3月
|
689
689
|
[nil, nil, nil, nil, nil , nil ], # 0 甲子
|
@@ -966,7 +966,7 @@ module When::Coordinates
|
|
966
966
|
['三寶吉', nil, '雑事吉', '加冠拜官移徒剃頭裁衣市買納財吉', 'たねまき' , 'たねまき' ], # 29 癸巳
|
967
967
|
['三寶吉', '神吉', '雑事吉', '加冠拜官納徴嫁娶移徒出行療病入學起土上梁修宅門戸吉', 'かといて' , nil ], # 30 甲午
|
968
968
|
['三寶吉+', nil, nil, '起土修宮室宅坏壊雍水塞穴吉', nil , nil ], # 31 乙未
|
969
|
-
['三寶吉+', '神吉', nil, '拜官出行解除除服吉',
|
969
|
+
['三寶吉+', '神吉', nil, '拜官出行解除除服吉', '入学' , '入学' ], # 32 丙申
|
970
970
|
[nil, nil, nil, '療病解除除服入學壊垣破屋吉', nil , nil ], # 33 丁酉
|
971
971
|
[nil, nil, nil, '経絡裁衣市買納財安床帳吉', 'くらたて かまぬり' , 'くさかり' ], # 34 戊戌
|
972
972
|
['三寶吉+', '神吉', '雑事吉', '加冠祠祀裁衣市買納財吉', nil , nil ], # 35 己亥
|
@@ -1006,11 +1006,11 @@ module When::Coordinates
|
|
1006
1006
|
['三寶吉', nil, nil, '嫁娶移徒入學起土修宅碓磑井倉出行吉', nil , nil ], # 7 辛未
|
1007
1007
|
['三寶吉+', '神吉', nil, '拜官嫁娶剃頭解除塞穴葬斬草除服吉', nil , '田かり' ], # 8 壬申
|
1008
1008
|
['三寶吉', nil, nil, '出行解除除服吉', nil , nil ], # 9 癸酉
|
1009
|
-
['三寶吉+', nil, '雑事吉', '療病解除除服壊垣破屋吉',
|
1009
|
+
['三寶吉+', nil, '雑事吉', '療病解除除服壊垣破屋吉', '竹木こり' , 'かといて' ], # 10 甲戌
|
1010
1010
|
[nil, nil, '雑事吉', '加冠祀門経絡裁衣市買納財奴婢六蓄修宅倉碓磑井安床帳吉', '入学' , '入学 いちたち 竹木こり' ], # 11 乙亥
|
1011
1011
|
['三寶吉+', nil, nil, '加冠拜官祠祀移徒起土竪柱上梁修宅築城郭吉', nil , nil ], # 12 丙子
|
1012
1012
|
['三寶吉', '神吉', nil, '裁衣市買納財安床帳吉', 'ものたち' , nil ], # 13 丁丑
|
1013
|
-
['三寶吉', nil, nil, '結婚納徴療病壊垣吉',
|
1013
|
+
['三寶吉', nil, nil, '結婚納徴療病壊垣吉', '田かり' , '田かり' ], # 14 戊寅
|
1014
1014
|
['三寶吉+', nil, nil, '結婚納徴壊垣吉', nil , nil ], # 15 己卯
|
1015
1015
|
['三寶吉', nil, '雑事吉', '移徒謝土壊垣破屋吉', nil , 'わたまし けんふく' ], # 16 庚辰
|
1016
1016
|
['三寶吉', nil, nil, '加冠拜官冊授祠祀嫁娶入學剃頭謝土移徒起土修宅倉築城郭市買吉', nil , nil ], # 17 辛巳
|
@@ -1046,7 +1046,7 @@ module When::Coordinates
|
|
1046
1046
|
['三寶吉', '神吉', nil, '加冠祠祀冊授結婚経絡謝土移徒起土修宅碓磑築城郭納財六蓄安床帳吉', nil , nil ], # 47 辛亥
|
1047
1047
|
['三寶吉+', '神吉', '雑事吉', '加冠拜官祠祀結婚納徴移徒起土上梁修宅門戸碓磑倉城郭吉', nil , nil ], # 48 壬子
|
1048
1048
|
['三寶吉', '神吉', nil, '移徒起土市買納財安床帳吉', 'たねまき 竹木こり' , nil ], # 49 癸丑
|
1049
|
-
['三寶吉', nil, nil, '結婚納徴殯埋斬草吉', '田かり'
|
1049
|
+
['三寶吉', nil, nil, '結婚納徴殯埋斬草吉', 'かまぬり 田かり' , nil ], # 50 甲寅
|
1050
1050
|
[nil, nil, nil, '此日不見死人焼雷神不同産家不殺木', nil , nil ], # 51 乙卯
|
1051
1051
|
['三寶吉+', nil, '雑事吉', '壊垣破屋吉', nil , nil ], # 52 丙辰
|
1052
1052
|
['三寶吉', nil, '雑事吉', '加冠拜官移徒入學市買納財吉', nil , nil ], # 53 丁巳
|
@@ -1104,7 +1104,7 @@ module When::Coordinates
|
|
1104
1104
|
['三寶吉', '神吉', nil, '猟吉', '田かり' , 'かといて 田かり' ], # 43 丁未
|
1105
1105
|
['三寶吉', nil, nil, '出行療病解除起土上梁修宅門戸碓磑井葬斬草吉', nil , nil ], # 44 戊申
|
1106
1106
|
['三寶吉', '神吉', nil, '起土解除塞穴吉', 'たねまき' , 'むきまき' ], # 45 己酉
|
1107
|
-
[nil, nil, nil, '為解除耳万買不行病人家',
|
1107
|
+
[nil, nil, nil, '為解除耳万買不行病人家', nil , nil ], # 46 庚戌
|
1108
1108
|
['三寶吉', '神吉', nil, '祠祀療病解除謝土掃舎修宅碓磑井市買納財吉', '田かり' , 'いちたち 田かり' ], # 47 辛亥
|
1109
1109
|
['三寶吉+', '神吉', nil, '拜官冊授上梁修宅門戸安床帳吉', nil , nil ], # 48 壬子
|
1110
1110
|
['三寶吉', '神吉', nil, '裁衣市買納財吉', nil , nil ], # 49 癸丑
|
@@ -1138,7 +1138,7 @@ module When::Coordinates
|
|
1138
1138
|
['三寶吉+', '神吉', nil, '加冠拜官祠祀結婚納徴嫁娶納婦移徒出行起土修宅門戸廁吉', nil , nil ], # 15 己卯
|
1139
1139
|
['三寶吉', nil, '雑事吉', '嫁娶起土伐樹猟吉', 'けんふく よめとり' , 'かといて' ], # 16 庚辰
|
1140
1140
|
['三寶吉', nil, nil, '拜官冊授療病市買納財壊垣破屋吉', nil , nil ], # 17 辛巳
|
1141
|
-
['三寶吉', '神吉', '雑事吉', '嫁娶納婦移徒壊垣破屋伐樹吉', '
|
1141
|
+
['三寶吉', '神吉', '雑事吉', '嫁娶納婦移徒壊垣破屋伐樹吉', 'かとたて' , 'むきまき' ], # 18 壬午
|
1142
1142
|
['三寶吉', nil, nil, '入學吉', nil , 'みそさけつくり' ], # 19 癸未
|
1143
1143
|
['三寶吉+', '神吉', nil, '祠祀移徒剃頭解除修宅起土上梁壊城郭伐樹除服吉', nil , nil ], # 20 甲申
|
1144
1144
|
['三寶吉', '神吉', nil, '祠祀移徒出行療病人學起土修宅門戸碓磑井廁壊城郭解除吉', nil , nil ], # 21 乙酉
|
@@ -1258,12 +1258,12 @@ module When::Coordinates
|
|
1258
1258
|
[nil, nil, nil, '療病修宅門戸碓磑廁裁衣市買納財吉', 'いちたち' , 'いちたち' ], # 11 乙亥
|
1259
1259
|
['三寶吉+', nil, nil, '結婚塞穴斬草納財吉', nil , nil ], # 12 丙子
|
1260
1260
|
['三寶吉', '神吉', nil, '嫁娶納婦出行吉', nil , nil ], # 13 丁丑
|
1261
|
-
['三寶吉', nil, nil, '拜官結婚納徴納婦療病壊垣吉', 'すゝはらひ'
|
1261
|
+
['三寶吉', nil, nil, '拜官結婚納徴納婦療病壊垣吉', '木こり すゝはらひ' , '木こり' ], # 14 戊寅
|
1262
1262
|
['三寶吉+', '神吉', nil, '拜官嫁娶斬頭納婦経絡謝土祀井上梁修宅門戸碓磑廁安床帳吉', '正月ことはしめ' , nil ], # 15 己卯
|
1263
1263
|
['三寶吉', nil, '雑事吉', '嫁娶納婦吉', 'よめとり' , 'けんふく' ], # 16 庚辰
|
1264
1264
|
[nil, nil, nil, '拜官冊授上梁修宅門戸裁衣市買納財安床帳吉', 'すゝはらひ' , nil ], # 17 辛巳
|
1265
1265
|
['三寶吉', '神吉', '雑事吉', '拜官納頭謝土伐樹漁猟上梁修宅門戸碓磑納葬斬草吉', '正月ことはしめ' , nil ], # 18 壬午
|
1266
|
-
['三寶吉', nil, nil, '壊垣破屋吉', '
|
1266
|
+
['三寶吉', nil, nil, '壊垣破屋吉', 'たねまき' , 'たねまき' ], # 19 癸未
|
1267
1267
|
['三寶吉+', '神吉', nil, '祠祀壊垣破屋解除除服伐樹葬斬草吉', nil , nil ], # 20 甲申
|
1268
1268
|
['三寶吉', '神吉', nil, '修宅門戸碓磑納解除吉', nil , nil ], # 21 乙酉
|
1269
1269
|
['三寶吉+', nil, nil, '漁猟種蒔吉', nil , nil ], # 22 丙戌
|
data/lib/when_exe/tmposition.rb
CHANGED
@@ -1,2273 +1,2307 @@
|
|
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
|
-
module When::TM
|
9
|
-
#
|
10
|
-
# (5.4) Temporal Position Package
|
11
|
-
#
|
12
|
-
#
|
13
|
-
|
14
|
-
# 列挙データ型である When::TM::IndeterminateValue は,不確定な位置のために
|
15
|
-
# 6つの値を規定する.このうち Min と Max は 本ライブラリでの拡張である.
|
16
|
-
#
|
17
|
-
# These values are interpreted as follows:
|
18
|
-
#- “Unknown” 時間位置を示す値が与えられていないことを示す(本ライブラリでは“Unknown”は使用しない)
|
19
|
-
#- “Now” 常に現時点の時間位置を示す(オブジェクト生成時の時間位置でないことに注意)
|
20
|
-
#- “Before” 実際の時間位置は未知だが、指定した値よりも前であることを示す(本ライブラリでは“Before”は無視される)
|
21
|
-
#- “After” 実際の時間位置は未知だが、指定した値よりも後であることを示す(本ライブラリでは“After”は無視される)
|
22
|
-
#- “Min” 無限の過去を示す
|
23
|
-
#- “Max” 無限の未来を示す
|
24
|
-
#
|
25
|
-
# see {gml schema}[link:http://schemas.opengis.net/gml/3.1.1/base/temporal.xsd#TimeIndeterminateValueType]
|
26
|
-
#
|
27
|
-
module IndeterminateValue
|
28
|
-
|
29
|
-
After = :After
|
30
|
-
Before = :Before
|
31
|
-
Now = :Now
|
32
|
-
Unknown = :Unknown
|
33
|
-
# additional value for this library
|
34
|
-
Min = :Min
|
35
|
-
# additional value for this library
|
36
|
-
Max = :Max
|
37
|
-
|
38
|
-
S = {'After'=>After, 'Before'=>Before, 'Now'=>Now, 'Unknown'=>Unknown, '-Infinity'=>Min, '+Infinity'=>Max}
|
39
|
-
I = S.invert
|
40
|
-
end
|
41
|
-
|
42
|
-
# 時間位置共用体
|
43
|
-
# union of
|
44
|
-
# When::TM::TemporalPosition
|
45
|
-
# When::BasicTypes::Date
|
46
|
-
# When::BasicTypes::Time
|
47
|
-
# When::BasicTypes::DateTime
|
48
|
-
#
|
49
|
-
# see {http://schemas.opengis.net/gml/3.1.1/base/temporal.xsd#TimePositionType gml schema}
|
50
|
-
#
|
51
|
-
class Position
|
52
|
-
|
53
|
-
include IndeterminateValue
|
54
|
-
include When::Parts::Resource
|
55
|
-
|
56
|
-
# @private
|
57
|
-
HashProperty =
|
58
|
-
[:indeterminated_position, :frame,
|
59
|
-
[:precision, When::SYSTEM], :events, :options, :trans, :query,
|
60
|
-
:location, [:time_standard, When::TimeStandard::UniversalTime], [:rate_of_clock, 1.0]]
|
61
|
-
|
62
|
-
# 代表文字列
|
63
|
-
#
|
64
|
-
# @return [When::BasicTypes::DateTime]
|
65
|
-
#
|
66
|
-
attr_reader :date_time8601
|
67
|
-
alias :dateTime8601 :date_time8601
|
68
|
-
|
69
|
-
# 時間位置
|
70
|
-
#
|
71
|
-
# @return [When::TM::TemporalPosition]
|
72
|
-
#
|
73
|
-
attr_reader :any_other
|
74
|
-
alias :anyOther :any_other
|
75
|
-
|
76
|
-
# 諸々のオブジェクトから When::TM::TemporalPosition を取り出す
|
77
|
-
#
|
78
|
-
# @param [Object] position 変換元の時間位置
|
79
|
-
# @param [Hash] options
|
80
|
-
# see {When::TM::TemporalPosition._instance}
|
81
|
-
#
|
82
|
-
# @return [When::TM::TemporalPosition] position の型により下記を返す
|
83
|
-
# - {When::BasicTypes::Date}, {When::BasicTypes::Time}, {When::BasicTypes::DateTime} - When::TM::Calendar#jul_trans による変換結果
|
84
|
-
# - {When::TM::TemporalPosition} - そのまま position ( optionは無視 )
|
85
|
-
# - {When::TM::Position} - position.any_other ( optionは無視 )
|
86
|
-
# - {When::Parts::GeometricComplex} - position.first ( optionは無視 )
|
87
|
-
#
|
88
|
-
def self.any_other(position, options={})
|
89
|
-
case position
|
90
|
-
when TemporalPosition ; position
|
91
|
-
when Position ; position.any_other
|
92
|
-
when When::Parts::GeometricComplex ; position.first
|
93
|
-
else ; When.Calendar(options[:frame] || 'Gregorian').jul_trans(position, options) || position
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
# オブジェクトの生成
|
98
|
-
#
|
99
|
-
# @param [String] specification When.exe Standard Representation として解釈して生成する
|
100
|
-
# @param [Hash] options 暦法や時法などの指定
|
101
|
-
# see {When::TM::TemporalPosition._instance}
|
102
|
-
#
|
103
|
-
# @note
|
104
|
-
# specification が String 以外の場合、そのオブジェクトの代表的な日時
|
105
|
-
# (When::TM::CalendarEra#reference_dateなど)により解釈する
|
106
|
-
#
|
107
|
-
def initialize(specification, options={})
|
108
|
-
|
109
|
-
case specification
|
110
|
-
when String
|
111
|
-
@date_time8601 = specification
|
112
|
-
@any_other = TemporalPosition._instance(specification, options)
|
113
|
-
when Position
|
114
|
-
@date_time8601 = specification.date_time8601
|
115
|
-
@any_other = specification.any_other
|
116
|
-
return
|
117
|
-
else
|
118
|
-
@any_other = specification
|
119
|
-
end
|
120
|
-
|
121
|
-
klass = specification.class
|
122
|
-
message = "Irregal specification type: #{klass}"
|
123
|
-
|
124
|
-
case specification
|
125
|
-
when CalDate ; @date_time8601 = When::BasicTypes::Date.new(specification.to_s)
|
126
|
-
when ClockTime ; @date_time8601 = When::BasicTypes::Time.new(specification.to_s)
|
127
|
-
when TemporalPosition ; @date_time8601 = When::BasicTypes::DateTime.new(specification.to_s)
|
128
|
-
when CalendarEra ; @date_time8601 = When::BasicTypes::Date.new(specification.reference_date.to_s)
|
129
|
-
when OrdinalEra ; @date_time8601 = When::BasicTypes::Date.new(specification.begin.to_s)
|
130
|
-
when When::BasicTypes::Date ; raise TypeError, message unless klass == CalDate
|
131
|
-
when When::BasicTypes::Time ; raise TypeError, message unless klass == ClockTime
|
132
|
-
when String ;
|
133
|
-
else ; raise TypeError, message
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
private
|
138
|
-
|
139
|
-
alias :_method_missing :method_missing
|
140
|
-
|
141
|
-
# その他のメソッド
|
142
|
-
#
|
143
|
-
# @note
|
144
|
-
# When::TM::Position で定義されていないメソッドは
|
145
|
-
# 処理を @date_time8601 (type: When::BasicTypes::DateTime)
|
146
|
-
# または @any_other (type: When::TM::TemporalPosition) に委譲する
|
147
|
-
# (両方ともに有効なメソッドは@any_otherを優先する)
|
148
|
-
#
|
149
|
-
def method_missing(name, *args, &block)
|
150
|
-
return _method_missing(name, *args, &block) if When::Parts::MethodCash::Escape.key?(name)
|
151
|
-
self.class.module_eval %Q{
|
152
|
-
def #{name}(*args, &block)
|
153
|
-
union = @any_other.respond_to?("#{name}") ? @any_other : @date_time8601
|
154
|
-
union.send("#{name}", *args, &block)
|
155
|
-
end
|
156
|
-
} unless When::Parts::MethodCash.escape(name)
|
157
|
-
union = @any_other.respond_to?(name) ? @any_other : @date_time8601
|
158
|
-
union.send(name, *args, &block)
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
# 「時間位置」の基底クラス
|
163
|
-
#
|
164
|
-
# see {http://schemas.opengis.net/gml/3.1.1/base/temporalAppendix.xsd#TemporalPositionType gml schema}
|
165
|
-
#
|
166
|
-
class TemporalPosition < ::Object
|
167
|
-
|
168
|
-
#
|
169
|
-
# When::TM::JulianDate, When::TM::CalDate or DateAndTime への変換メソッドを提供
|
170
|
-
#
|
171
|
-
module Conversion
|
172
|
-
#
|
173
|
-
# 対応する When::TM::JulianDate を生成
|
174
|
-
#
|
175
|
-
# @param [Hash] options 以下の通り
|
176
|
-
# @option options [When::TM::Clock] :clock
|
177
|
-
# @option options [When::Parts::Timezone] :tz
|
178
|
-
#
|
179
|
-
# @return [When::TM::JulianDate]
|
180
|
-
#
|
181
|
-
def julian_date(options={})
|
182
|
-
When::TM::JulianDate.new(self, options)
|
183
|
-
end
|
184
|
-
alias :to_julian_date :julian_date
|
185
|
-
|
186
|
-
#
|
187
|
-
# 対応する When::TM::CalDate or DateAndTime を生成
|
188
|
-
#
|
189
|
-
# @param [Hash] options 暦法や時法などの指定
|
190
|
-
# see {When::TM::TemporalPosition._instance}
|
191
|
-
#
|
192
|
-
# @return [When::TM::CalDate, When::TM::DateAndTime]
|
193
|
-
#
|
194
|
-
def tm_pos(options={})
|
195
|
-
When.Calendar(options[:frame] || 'Gregorian').jul_trans(self, options)
|
196
|
-
end
|
197
|
-
alias :to_tm_pos :tm_pos
|
198
|
-
end
|
199
|
-
|
200
|
-
include When
|
201
|
-
include Comparable
|
202
|
-
include IndeterminateValue
|
203
|
-
include Coordinates
|
204
|
-
include Parts::Resource
|
205
|
-
include Conversion
|
206
|
-
|
207
|
-
# @private
|
208
|
-
HashProperty = Position::HashProperty
|
209
|
-
|
210
|
-
# @private
|
211
|
-
DateTimeInstanceMethods = ::Object.const_defined?(:Date) && ::Date.method_defined?(:+) ? ::DateTime.instance_methods : []
|
212
|
-
|
213
|
-
# この時間位置の意味づけ
|
214
|
-
#
|
215
|
-
# @return [When::TM::IndeterminateValue]
|
216
|
-
#
|
217
|
-
attr_reader :indeterminated_position
|
218
|
-
alias :indeterminatedPosition :indeterminated_position
|
219
|
-
|
220
|
-
# この時間位置と関連付けられた時間参照系 (relation - Reference)
|
221
|
-
#
|
222
|
-
# The time reference system associated with the temporal position being described
|
223
|
-
#
|
224
|
-
# @return [When::TM::ReferenceSystem]
|
225
|
-
#
|
226
|
-
attr_accessor :frame
|
227
|
-
|
228
|
-
# この時間位置と関連付けられたイベント - additional attribute
|
229
|
-
#
|
230
|
-
# @return [Array<When::Parts::Enumerator>]
|
231
|
-
#
|
232
|
-
attr_accessor :events
|
233
|
-
#protected :events=
|
234
|
-
|
235
|
-
# この時間位置の分解能 - additional attribute
|
236
|
-
#
|
237
|
-
# @return [Numeric]
|
238
|
-
#
|
239
|
-
# @note precision より resolution の方が分解能の意味にふさわしいが ISO19108 で別の意味に用いられているため resolution とした。
|
240
|
-
#
|
241
|
-
attr_accessor :precision
|
242
|
-
|
243
|
-
# その他の属性 - additional attribute
|
244
|
-
#
|
245
|
-
# @return [Hash] { String=>Object }
|
246
|
-
#
|
247
|
-
attr_reader :options
|
248
|
-
|
249
|
-
# その他の属性 - additional attribute
|
250
|
-
#
|
251
|
-
# @return [Hash] { String=>Object }
|
252
|
-
#
|
253
|
-
attr_accessor :trans
|
254
|
-
|
255
|
-
# その他の属性 - additional attribute
|
256
|
-
#
|
257
|
-
# @return [Hash] { String=>When::BasicTypes::M17n }
|
258
|
-
#
|
259
|
-
attr_accessor :query
|
260
|
-
|
261
|
-
# その他の属性 - additional attribute
|
262
|
-
#
|
263
|
-
# @return [When::Coordinates::Spatial]
|
264
|
-
#
|
265
|
-
attr_accessor :location
|
266
|
-
|
267
|
-
class << self
|
268
|
-
|
269
|
-
include When
|
270
|
-
include Coordinates
|
271
|
-
|
272
|
-
# Temporal Objetct の生成
|
273
|
-
#
|
274
|
-
# @param [String] specification When.exe Standard Representation
|
275
|
-
# @param [Hash] options 下記の通り
|
276
|
-
# @option options [When::TM::ReferenceSystem] :frame 暦法の指定
|
277
|
-
# @option options [When::Parts::Timezone::Base, String] :clock 時法の指定
|
278
|
-
# @option options [String] :tz 時法の指定(時間帯を指定する場合 :clock の替わりに用いることができる)
|
279
|
-
# @option options [Array<Numeric>] :abbr ISO8601上位省略形式のためのデフォルト日付(省略時 指定なし)
|
280
|
-
# @option options [Integer] :extra_year_digits ISO8601拡大表記のための年の構成要素拡大桁数(省略時 1桁)
|
281
|
-
# @option options [Integer] :ordinal_date_digits ISO8601拡大表記の年内通日の桁数(省略時 3桁)
|
282
|
-
# @option options [String] :wkst ISO8601週日形式のための暦週開始曜日(省略時 'MO')
|
283
|
-
# @option options [Integer] :precision 生成するオブジェクトの分解能
|
284
|
-
# @option options [When::TimeStandard::TimeStandard] :time_standard 時刻系の指定(省略時 When::TimeStandard::UnversalTime)
|
285
|
-
# @option options [When::Ephemeris::Spatial] :location 観測地の指定(省略時 指定なし)
|
286
|
-
# @option options [String] :era_name 暦年代
|
287
|
-
# @option options [Hash] :trans 暦年代の上下限
|
288
|
-
# - :count => 条件に合致する暦年代のうち何番目を採用するか
|
289
|
-
# - :lower => 暦年代適用の下限
|
290
|
-
# true - epoch_of_use の始め(省略時)
|
291
|
-
# :reference_date - 参照事象の日付
|
292
|
-
# - :upper => 暦年代適用の上限
|
293
|
-
# true - epoch_of_use の終わり(省略時)
|
294
|
-
# :reference_date - 参照事象の日付
|
295
|
-
# @option options [Hash] :query 暦年代の絞込み条件
|
296
|
-
# - :area => area による暦年代絞込み
|
297
|
-
# - :period => period による暦年代絞込み
|
298
|
-
# - :name => name による暦年代絞込み(epoch の attribute使用可)
|
299
|
-
#
|
300
|
-
# @note options の中身は本メソッドによって更新されることがある。
|
301
|
-
#
|
302
|
-
# @note :tz は 'Asia/Tokyo'など時間帯を表す文字列をキーにして、登録済みのWhen::V::Timezone, When::Parts::Timezoneを検索して使用する。
|
303
|
-
# :clock はWhen::Parts::Timezone::Baseオブジェクトをそのまま使用するか '+09:00'などの文字列をWhen::TM::Clock化して使用する。
|
304
|
-
# :tz の方が :clock よりも優先される。
|
305
|
-
#
|
306
|
-
# @return [When::TM::TemporalPosition] ISO8601 time point
|
307
|
-
# @return [When::TM::Duration] ISO8601 duration
|
308
|
-
# @return [When::Parts::GeometricComplex] ISO8601 repeating interval
|
309
|
-
#
|
310
|
-
def _instance(specification, options={})
|
311
|
-
|
312
|
-
# prefix - RFC 5545 Options
|
313
|
-
iso8601form = When::Parts::Resource::ContentLine.extract_rfc5545_Property(specification, options)
|
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
|
-
when
|
365
|
-
case element[0]
|
366
|
-
when Duration ;
|
367
|
-
when self ; return When::Parts::GeometricComplex.new(element
|
368
|
-
else ; return When::Parts::GeometricComplex.new(element[0].first
|
369
|
-
end
|
370
|
-
|
371
|
-
case element[0]
|
372
|
-
when Duration ; return When::Parts::GeometricComplex.new([[element[1]
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
when
|
392
|
-
else ; duration =
|
393
|
-
end
|
394
|
-
|
395
|
-
case element[0]
|
396
|
-
when Duration ; duration = -element[0]
|
397
|
-
when self ; duration = element[1]
|
398
|
-
else ; duration = element[1]
|
399
|
-
end
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
date
|
451
|
-
element = args.shift
|
452
|
-
abbr = abbrs.shift
|
453
|
-
res << element.to('
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
position
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
main[:
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
return
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
private
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
#
|
608
|
-
#
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
#
|
614
|
-
#
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
#
|
652
|
-
#
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
#
|
671
|
-
#
|
672
|
-
#
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
#
|
678
|
-
#
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
#
|
688
|
-
#
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
#
|
705
|
-
#
|
706
|
-
#
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
#
|
723
|
-
#
|
724
|
-
#
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
#
|
740
|
-
#
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
#
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
#
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
when
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
#
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
#
|
840
|
-
#
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
#
|
846
|
-
#
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
#
|
852
|
-
#
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
#
|
860
|
-
#
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
#
|
866
|
-
#
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
#
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
#
|
879
|
-
#
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
#
|
893
|
-
#
|
894
|
-
#
|
895
|
-
#
|
896
|
-
#
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
end
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
end
|
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
|
-
end
|
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
|
-
|
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
|
-
end
|
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
|
-
when
|
1187
|
-
options[:frame] ||= When.
|
1188
|
-
universal_time =
|
1189
|
-
when
|
1190
|
-
options[:frame] ||= time.clock
|
1191
|
-
universal_time = time.universal_time
|
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
|
-
# @return [
|
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
|
-
|
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
|
-
|
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
|
-
end
|
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
|
-
# @return [
|
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
|
-
# @return [
|
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
|
-
def
|
1680
|
-
|
1681
|
-
|
1682
|
-
end
|
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
|
-
|
1817
|
-
|
1818
|
-
|
1819
|
-
|
1820
|
-
|
1821
|
-
|
1822
|
-
|
1823
|
-
|
1824
|
-
#
|
1825
|
-
#
|
1826
|
-
def
|
1827
|
-
|
1828
|
-
end
|
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
|
-
def
|
1861
|
-
|
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
|
-
date
|
1954
|
-
|
1955
|
-
|
1956
|
-
|
1957
|
-
|
1958
|
-
|
1959
|
-
|
1960
|
-
|
1961
|
-
|
1962
|
-
|
1963
|
-
|
1964
|
-
|
1965
|
-
|
1966
|
-
|
1967
|
-
|
1968
|
-
|
1969
|
-
|
1970
|
-
|
1971
|
-
|
1972
|
-
|
1973
|
-
|
1974
|
-
|
1975
|
-
|
1976
|
-
|
1977
|
-
|
1978
|
-
|
1979
|
-
|
1980
|
-
|
1981
|
-
|
1982
|
-
|
1983
|
-
|
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
|
-
# @param [
|
2069
|
-
#
|
2070
|
-
# @return [When::TM::DateAndTime]
|
2071
|
-
#
|
2072
|
-
def
|
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
|
-
options =
|
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
|
-
|
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
|
+
module When::TM
|
9
|
+
#
|
10
|
+
# (5.4) Temporal Position Package
|
11
|
+
#
|
12
|
+
#
|
13
|
+
|
14
|
+
# 列挙データ型である When::TM::IndeterminateValue は,不確定な位置のために
|
15
|
+
# 6つの値を規定する.このうち Min と Max は 本ライブラリでの拡張である.
|
16
|
+
#
|
17
|
+
# These values are interpreted as follows:
|
18
|
+
#- “Unknown” 時間位置を示す値が与えられていないことを示す(本ライブラリでは“Unknown”は使用しない)
|
19
|
+
#- “Now” 常に現時点の時間位置を示す(オブジェクト生成時の時間位置でないことに注意)
|
20
|
+
#- “Before” 実際の時間位置は未知だが、指定した値よりも前であることを示す(本ライブラリでは“Before”は無視される)
|
21
|
+
#- “After” 実際の時間位置は未知だが、指定した値よりも後であることを示す(本ライブラリでは“After”は無視される)
|
22
|
+
#- “Min” 無限の過去を示す
|
23
|
+
#- “Max” 無限の未来を示す
|
24
|
+
#
|
25
|
+
# see {gml schema}[link:http://schemas.opengis.net/gml/3.1.1/base/temporal.xsd#TimeIndeterminateValueType]
|
26
|
+
#
|
27
|
+
module IndeterminateValue
|
28
|
+
|
29
|
+
After = :After
|
30
|
+
Before = :Before
|
31
|
+
Now = :Now
|
32
|
+
Unknown = :Unknown
|
33
|
+
# additional value for this library
|
34
|
+
Min = :Min
|
35
|
+
# additional value for this library
|
36
|
+
Max = :Max
|
37
|
+
|
38
|
+
S = {'After'=>After, 'Before'=>Before, 'Now'=>Now, 'Unknown'=>Unknown, '-Infinity'=>Min, '+Infinity'=>Max}
|
39
|
+
I = S.invert
|
40
|
+
end
|
41
|
+
|
42
|
+
# 時間位置共用体
|
43
|
+
# union of
|
44
|
+
# When::TM::TemporalPosition
|
45
|
+
# When::BasicTypes::Date
|
46
|
+
# When::BasicTypes::Time
|
47
|
+
# When::BasicTypes::DateTime
|
48
|
+
#
|
49
|
+
# see {http://schemas.opengis.net/gml/3.1.1/base/temporal.xsd#TimePositionType gml schema}
|
50
|
+
#
|
51
|
+
class Position
|
52
|
+
|
53
|
+
include IndeterminateValue
|
54
|
+
include When::Parts::Resource
|
55
|
+
|
56
|
+
# @private
|
57
|
+
HashProperty =
|
58
|
+
[:indeterminated_position, :frame,
|
59
|
+
[:precision, When::SYSTEM], :events, :options, :trans, :query,
|
60
|
+
:location, [:time_standard, When::TimeStandard::UniversalTime], [:rate_of_clock, 1.0]]
|
61
|
+
|
62
|
+
# 代表文字列
|
63
|
+
#
|
64
|
+
# @return [When::BasicTypes::DateTime]
|
65
|
+
#
|
66
|
+
attr_reader :date_time8601
|
67
|
+
alias :dateTime8601 :date_time8601
|
68
|
+
|
69
|
+
# 時間位置
|
70
|
+
#
|
71
|
+
# @return [When::TM::TemporalPosition]
|
72
|
+
#
|
73
|
+
attr_reader :any_other
|
74
|
+
alias :anyOther :any_other
|
75
|
+
|
76
|
+
# 諸々のオブジェクトから When::TM::TemporalPosition を取り出す
|
77
|
+
#
|
78
|
+
# @param [Object] position 変換元の時間位置
|
79
|
+
# @param [Hash] options
|
80
|
+
# see {When::TM::TemporalPosition._instance}
|
81
|
+
#
|
82
|
+
# @return [When::TM::TemporalPosition] position の型により下記を返す
|
83
|
+
# - {When::BasicTypes::Date}, {When::BasicTypes::Time}, {When::BasicTypes::DateTime} - When::TM::Calendar#jul_trans による変換結果
|
84
|
+
# - {When::TM::TemporalPosition} - そのまま position ( optionは無視 )
|
85
|
+
# - {When::TM::Position} - position.any_other ( optionは無視 )
|
86
|
+
# - {When::Parts::GeometricComplex} - position.first ( optionは無視 )
|
87
|
+
#
|
88
|
+
def self.any_other(position, options={})
|
89
|
+
case position
|
90
|
+
when TemporalPosition ; position
|
91
|
+
when Position ; position.any_other
|
92
|
+
when When::Parts::GeometricComplex ; position.first
|
93
|
+
else ; When.Calendar(options[:frame] || 'Gregorian').jul_trans(position, options) || position
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# オブジェクトの生成
|
98
|
+
#
|
99
|
+
# @param [String] specification When.exe Standard Representation として解釈して生成する
|
100
|
+
# @param [Hash] options 暦法や時法などの指定
|
101
|
+
# see {When::TM::TemporalPosition._instance}
|
102
|
+
#
|
103
|
+
# @note
|
104
|
+
# specification が String 以外の場合、そのオブジェクトの代表的な日時
|
105
|
+
# (When::TM::CalendarEra#reference_dateなど)により解釈する
|
106
|
+
#
|
107
|
+
def initialize(specification, options={})
|
108
|
+
|
109
|
+
case specification
|
110
|
+
when String
|
111
|
+
@date_time8601 = specification
|
112
|
+
@any_other = TemporalPosition._instance(specification, options)
|
113
|
+
when Position
|
114
|
+
@date_time8601 = specification.date_time8601
|
115
|
+
@any_other = specification.any_other
|
116
|
+
return
|
117
|
+
else
|
118
|
+
@any_other = specification
|
119
|
+
end
|
120
|
+
|
121
|
+
klass = specification.class
|
122
|
+
message = "Irregal specification type: #{klass}"
|
123
|
+
|
124
|
+
case specification
|
125
|
+
when CalDate ; @date_time8601 = When::BasicTypes::Date.new(specification.to_s)
|
126
|
+
when ClockTime ; @date_time8601 = When::BasicTypes::Time.new(specification.to_s)
|
127
|
+
when TemporalPosition ; @date_time8601 = When::BasicTypes::DateTime.new(specification.to_s)
|
128
|
+
when CalendarEra ; @date_time8601 = When::BasicTypes::Date.new(specification.reference_date.to_s)
|
129
|
+
when OrdinalEra ; @date_time8601 = When::BasicTypes::Date.new(specification.begin.to_s)
|
130
|
+
when When::BasicTypes::Date ; raise TypeError, message unless klass == CalDate
|
131
|
+
when When::BasicTypes::Time ; raise TypeError, message unless klass == ClockTime
|
132
|
+
when String ;
|
133
|
+
else ; raise TypeError, message
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
private
|
138
|
+
|
139
|
+
alias :_method_missing :method_missing
|
140
|
+
|
141
|
+
# その他のメソッド
|
142
|
+
#
|
143
|
+
# @note
|
144
|
+
# When::TM::Position で定義されていないメソッドは
|
145
|
+
# 処理を @date_time8601 (type: When::BasicTypes::DateTime)
|
146
|
+
# または @any_other (type: When::TM::TemporalPosition) に委譲する
|
147
|
+
# (両方ともに有効なメソッドは@any_otherを優先する)
|
148
|
+
#
|
149
|
+
def method_missing(name, *args, &block)
|
150
|
+
return _method_missing(name, *args, &block) if When::Parts::MethodCash::Escape.key?(name)
|
151
|
+
self.class.module_eval %Q{
|
152
|
+
def #{name}(*args, &block)
|
153
|
+
union = @any_other.respond_to?("#{name}") ? @any_other : @date_time8601
|
154
|
+
union.send("#{name}", *args, &block)
|
155
|
+
end
|
156
|
+
} unless When::Parts::MethodCash.escape(name)
|
157
|
+
union = @any_other.respond_to?(name) ? @any_other : @date_time8601
|
158
|
+
union.send(name, *args, &block)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
# 「時間位置」の基底クラス
|
163
|
+
#
|
164
|
+
# see {http://schemas.opengis.net/gml/3.1.1/base/temporalAppendix.xsd#TemporalPositionType gml schema}
|
165
|
+
#
|
166
|
+
class TemporalPosition < ::Object
|
167
|
+
|
168
|
+
#
|
169
|
+
# When::TM::JulianDate, When::TM::CalDate or DateAndTime への変換メソッドを提供
|
170
|
+
#
|
171
|
+
module Conversion
|
172
|
+
#
|
173
|
+
# 対応する When::TM::JulianDate を生成
|
174
|
+
#
|
175
|
+
# @param [Hash] options 以下の通り
|
176
|
+
# @option options [When::TM::Clock] :clock
|
177
|
+
# @option options [When::Parts::Timezone] :tz
|
178
|
+
#
|
179
|
+
# @return [When::TM::JulianDate]
|
180
|
+
#
|
181
|
+
def julian_date(options={})
|
182
|
+
When::TM::JulianDate.new(self, options)
|
183
|
+
end
|
184
|
+
alias :to_julian_date :julian_date
|
185
|
+
|
186
|
+
#
|
187
|
+
# 対応する When::TM::CalDate or DateAndTime を生成
|
188
|
+
#
|
189
|
+
# @param [Hash] options 暦法や時法などの指定
|
190
|
+
# see {When::TM::TemporalPosition._instance}
|
191
|
+
#
|
192
|
+
# @return [When::TM::CalDate, When::TM::DateAndTime]
|
193
|
+
#
|
194
|
+
def tm_pos(options={})
|
195
|
+
When.Calendar(options[:frame] || 'Gregorian').jul_trans(self, options)
|
196
|
+
end
|
197
|
+
alias :to_tm_pos :tm_pos
|
198
|
+
end
|
199
|
+
|
200
|
+
include When
|
201
|
+
include Comparable
|
202
|
+
include IndeterminateValue
|
203
|
+
include Coordinates
|
204
|
+
include Parts::Resource
|
205
|
+
include Conversion
|
206
|
+
|
207
|
+
# @private
|
208
|
+
HashProperty = Position::HashProperty
|
209
|
+
|
210
|
+
# @private
|
211
|
+
DateTimeInstanceMethods = ::Object.const_defined?(:Date) && ::Date.method_defined?(:+) ? ::DateTime.instance_methods : []
|
212
|
+
|
213
|
+
# この時間位置の意味づけ
|
214
|
+
#
|
215
|
+
# @return [When::TM::IndeterminateValue]
|
216
|
+
#
|
217
|
+
attr_reader :indeterminated_position
|
218
|
+
alias :indeterminatedPosition :indeterminated_position
|
219
|
+
|
220
|
+
# この時間位置と関連付けられた時間参照系 (relation - Reference)
|
221
|
+
#
|
222
|
+
# The time reference system associated with the temporal position being described
|
223
|
+
#
|
224
|
+
# @return [When::TM::ReferenceSystem]
|
225
|
+
#
|
226
|
+
attr_accessor :frame
|
227
|
+
|
228
|
+
# この時間位置と関連付けられたイベント - additional attribute
|
229
|
+
#
|
230
|
+
# @return [Array<When::Parts::Enumerator>]
|
231
|
+
#
|
232
|
+
attr_accessor :events
|
233
|
+
#protected :events=
|
234
|
+
|
235
|
+
# この時間位置の分解能 - additional attribute
|
236
|
+
#
|
237
|
+
# @return [Numeric]
|
238
|
+
#
|
239
|
+
# @note precision より resolution の方が分解能の意味にふさわしいが ISO19108 で別の意味に用いられているため resolution とした。
|
240
|
+
#
|
241
|
+
attr_accessor :precision
|
242
|
+
|
243
|
+
# その他の属性 - additional attribute
|
244
|
+
#
|
245
|
+
# @return [Hash] { String=>Object }
|
246
|
+
#
|
247
|
+
attr_reader :options
|
248
|
+
|
249
|
+
# その他の属性 - additional attribute
|
250
|
+
#
|
251
|
+
# @return [Hash] { String=>Object }
|
252
|
+
#
|
253
|
+
attr_accessor :trans
|
254
|
+
|
255
|
+
# その他の属性 - additional attribute
|
256
|
+
#
|
257
|
+
# @return [Hash] { String=>When::BasicTypes::M17n }
|
258
|
+
#
|
259
|
+
attr_accessor :query
|
260
|
+
|
261
|
+
# その他の属性 - additional attribute
|
262
|
+
#
|
263
|
+
# @return [When::Coordinates::Spatial]
|
264
|
+
#
|
265
|
+
attr_accessor :location
|
266
|
+
|
267
|
+
class << self
|
268
|
+
|
269
|
+
include When
|
270
|
+
include Coordinates
|
271
|
+
|
272
|
+
# Temporal Objetct の生成
|
273
|
+
#
|
274
|
+
# @param [String] specification When.exe Standard Representation
|
275
|
+
# @param [Hash] options 下記の通り
|
276
|
+
# @option options [When::TM::ReferenceSystem] :frame 暦法の指定
|
277
|
+
# @option options [When::Parts::Timezone::Base, String] :clock 時法の指定
|
278
|
+
# @option options [String] :tz 時法の指定(時間帯を指定する場合 :clock の替わりに用いることができる)
|
279
|
+
# @option options [Array<Numeric>] :abbr ISO8601上位省略形式のためのデフォルト日付(省略時 指定なし)
|
280
|
+
# @option options [Integer] :extra_year_digits ISO8601拡大表記のための年の構成要素拡大桁数(省略時 1桁)
|
281
|
+
# @option options [Integer] :ordinal_date_digits ISO8601拡大表記の年内通日の桁数(省略時 3桁)
|
282
|
+
# @option options [String] :wkst ISO8601週日形式のための暦週開始曜日(省略時 'MO')
|
283
|
+
# @option options [Integer] :precision 生成するオブジェクトの分解能
|
284
|
+
# @option options [When::TimeStandard::TimeStandard] :time_standard 時刻系の指定(省略時 When::TimeStandard::UnversalTime)
|
285
|
+
# @option options [When::Ephemeris::Spatial] :location 観測地の指定(省略時 指定なし)
|
286
|
+
# @option options [String] :era_name 暦年代
|
287
|
+
# @option options [Hash] :trans 暦年代の上下限
|
288
|
+
# - :count => 条件に合致する暦年代のうち何番目を採用するか
|
289
|
+
# - :lower => 暦年代適用の下限
|
290
|
+
# true - epoch_of_use の始め(省略時)
|
291
|
+
# :reference_date - 参照事象の日付
|
292
|
+
# - :upper => 暦年代適用の上限
|
293
|
+
# true - epoch_of_use の終わり(省略時)
|
294
|
+
# :reference_date - 参照事象の日付
|
295
|
+
# @option options [Hash] :query 暦年代の絞込み条件
|
296
|
+
# - :area => area による暦年代絞込み
|
297
|
+
# - :period => period による暦年代絞込み
|
298
|
+
# - :name => name による暦年代絞込み(epoch の attribute使用可)
|
299
|
+
#
|
300
|
+
# @note options の中身は本メソッドによって更新されることがある。
|
301
|
+
#
|
302
|
+
# @note :tz は 'Asia/Tokyo'など時間帯を表す文字列をキーにして、登録済みのWhen::V::Timezone, When::Parts::Timezoneを検索して使用する。
|
303
|
+
# :clock はWhen::Parts::Timezone::Baseオブジェクトをそのまま使用するか '+09:00'などの文字列をWhen::TM::Clock化して使用する。
|
304
|
+
# :tz の方が :clock よりも優先される。
|
305
|
+
#
|
306
|
+
# @return [When::TM::TemporalPosition] ISO8601 time point
|
307
|
+
# @return [When::TM::Duration] ISO8601 duration
|
308
|
+
# @return [When::Parts::GeometricComplex] ISO8601 repeating interval
|
309
|
+
#
|
310
|
+
def _instance(specification, options={})
|
311
|
+
|
312
|
+
# prefix - RFC 5545 Options
|
313
|
+
iso8601form = When::Parts::Resource::ContentLine.extract_rfc5545_Property(specification, options).
|
314
|
+
gsub(When::Parts::Resource::IRIDecode) {|c| When::Parts::Resource::IRIDecodeTable[c]}
|
315
|
+
|
316
|
+
# suffix - Frame specification
|
317
|
+
if iso8601form =~ /\A(.*[^\d])\((([-+*&%@!>=<?\dW.]|\{.+?\})+)\)\z/
|
318
|
+
frame, iso8601form = $~[1..2]
|
319
|
+
frame.sub!(/_+\z/, '')
|
320
|
+
else
|
321
|
+
iso8601form, frame, *rest = iso8601form.split(/\^{1,2}/)
|
322
|
+
return rest.inject(_instance(iso8601form + '^' + frame, options)) {|p,c| When.Resource(c, '_c:').jul_trans(p)} unless rest.empty?
|
323
|
+
end
|
324
|
+
|
325
|
+
# add frame to options
|
326
|
+
options = options.merge({:frame=>When.Resource(frame, '_c:')}) if frame
|
327
|
+
|
328
|
+
# indeterminateValue
|
329
|
+
if (iso8601form.sub!(/\/After$|^Before\/|^Now$|^Unknown$|^[-+]Infinity\z/i, ''))
|
330
|
+
options[:indeterminated_position] = When::TimeValue::S[$&.sub(/\//,'')]
|
331
|
+
case options[:indeterminated_position]
|
332
|
+
when When::TimeValue::Now,
|
333
|
+
When::TimeValue::Unknown,
|
334
|
+
When::TimeValue::Max,
|
335
|
+
When::TimeValue::Min
|
336
|
+
return self.new(self._options(options))
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
# each specification
|
341
|
+
splitted = iso8601form.split(/\//)
|
342
|
+
if (splitted[0] =~ /\AR(\d+)?\z/)
|
343
|
+
repeat = $1 ? $1.to_i : true
|
344
|
+
splitted.shift
|
345
|
+
end
|
346
|
+
case splitted.length
|
347
|
+
when 1
|
348
|
+
when 2
|
349
|
+
if (splitted[0] !~ /\A[-+]?P/ && splitted[1] =~ /\A\d/ && splitted[1].length < splitted[0].length)
|
350
|
+
splitted[1] = splitted[0][0..(splitted[0].length-splitted[1].length-1)] + splitted[1]
|
351
|
+
end
|
352
|
+
else
|
353
|
+
raise ArgumentError, "Irregal ISO8601 Format: #{iso8601form}"
|
354
|
+
end
|
355
|
+
options = self._options(options)
|
356
|
+
element = splitted.map { |v| _date_time_or_duration(v, options.dup) }
|
357
|
+
|
358
|
+
# total result
|
359
|
+
case repeat
|
360
|
+
when nil
|
361
|
+
case element[1]
|
362
|
+
when nil
|
363
|
+
return element[0]
|
364
|
+
when Duration
|
365
|
+
case element[0]
|
366
|
+
when Duration ; raise TypeError, "Duplicate Duration: #{element[0]} and #{element[1]}"
|
367
|
+
when self ; return When::Parts::GeometricComplex.new(*element)
|
368
|
+
else ; return When::Parts::GeometricComplex.new(element[0].first, element[1])
|
369
|
+
end
|
370
|
+
when self
|
371
|
+
case element[0]
|
372
|
+
when Duration ; return When::Parts::GeometricComplex.new([[element[1]-element[0],false], [element[1],true ]])
|
373
|
+
when self ; return When::Parts::GeometricComplex.new(element[0]..element[1])
|
374
|
+
else ; return When::Parts::GeometricComplex.new(element[0].first..element[1])
|
375
|
+
end
|
376
|
+
else
|
377
|
+
case element[0]
|
378
|
+
when Duration ; return When::Parts::GeometricComplex.new([[element[1].first-element[0],false],
|
379
|
+
[element[1].last-element[0]-1,true ]])
|
380
|
+
when self ; return When::Parts::GeometricComplex.new(element[0]...element[1].last)
|
381
|
+
else ; return When::Parts::GeometricComplex.new(element[0].first...element[1].last)
|
382
|
+
end
|
383
|
+
end
|
384
|
+
when 0 ; return []
|
385
|
+
when Integer ; return [element[0]] * repeat unless element[1]
|
386
|
+
end
|
387
|
+
|
388
|
+
case element[1]
|
389
|
+
when Duration
|
390
|
+
case element[0]
|
391
|
+
when Duration ; raise TypeError, "Duplicate Duration: #{element[0]} and #{element[1]}"
|
392
|
+
else ; duration = element[1]
|
393
|
+
end
|
394
|
+
when self
|
395
|
+
case element[0]
|
396
|
+
when Duration ; duration = -element[0]
|
397
|
+
when self ; duration = element[1] - element[0]
|
398
|
+
else ; duration = element[1] - element[0].first
|
399
|
+
end
|
400
|
+
else
|
401
|
+
case element[0]
|
402
|
+
when Duration ; duration = -element[0]
|
403
|
+
when self ; duration = element[1].first - element[0]
|
404
|
+
else ; duration = element[1].first - element[0].first
|
405
|
+
end
|
406
|
+
end
|
407
|
+
base = element[0].kind_of?(Duration) ? element[1] : element[0]
|
408
|
+
|
409
|
+
if repeat.kind_of?(Integer)
|
410
|
+
result = case base
|
411
|
+
when self ; (1..repeat-1).inject([base]) {|a,i| a << (a[-1] + duration) }
|
412
|
+
else ; (1..repeat-1).inject([base]) {|a,i| a << When::Parts::GeometricComplex.new(
|
413
|
+
a[-1].first+duration...a[-1].last+duration)}
|
414
|
+
end
|
415
|
+
result.reverse! if duration.sign < 0
|
416
|
+
return result
|
417
|
+
|
418
|
+
else
|
419
|
+
duration = -duration if duration.sign < 0
|
420
|
+
return case base
|
421
|
+
when self ; When::V::Event.new({'rrule'=>{'FREQ'=>duration}, 'dtstart'=>base})
|
422
|
+
else ; When::V::Event.new({'rrule'=>{'FREQ'=>duration}, 'dtstart'=>base.first,
|
423
|
+
'dtend' =>base.last})
|
424
|
+
end
|
425
|
+
end
|
426
|
+
end
|
427
|
+
|
428
|
+
# When::TM::TemporalPosition の生成
|
429
|
+
#
|
430
|
+
# @see When.TemporalPosition
|
431
|
+
#
|
432
|
+
def _temporal_position(*args)
|
433
|
+
# 引数の解釈
|
434
|
+
options = args[-1].kind_of?(Hash) ? args.pop.dup : {}
|
435
|
+
validate = options.delete(:invalid)
|
436
|
+
options = TemporalPosition._options(options)
|
437
|
+
options[:frame] ||= 'Gregorian'
|
438
|
+
options[:frame] = When.Resource(options[:frame], '_c:') if options[:frame].kind_of?(String)
|
439
|
+
case args[0]
|
440
|
+
when String
|
441
|
+
options[:era_name] = When::EncodingConversion.to_internal_encoding(args.shift)
|
442
|
+
when Array
|
443
|
+
options[:era_name] = args.shift
|
444
|
+
options[:era_name][0] = When::EncodingConversion.to_internal_encoding(options[:era_name][0])
|
445
|
+
end
|
446
|
+
|
447
|
+
# 時間位置の生成
|
448
|
+
res = []
|
449
|
+
abbrs = Array(options[:abbr])
|
450
|
+
date = Array.new(options[:frame].indices.length-1) {
|
451
|
+
element = args.shift
|
452
|
+
abbr = abbrs.shift
|
453
|
+
res << element.to('year') if element.kind_of?(When::Coordinates::Residue)
|
454
|
+
element.kind_of?(Numeric) ? element : (abbr || 1)
|
455
|
+
}
|
456
|
+
date += Array.new(2) {
|
457
|
+
element = args.shift
|
458
|
+
abbr = abbrs.shift
|
459
|
+
res << element.to('day') if element.kind_of?(When::Coordinates::Residue)
|
460
|
+
case element
|
461
|
+
when Numeric ; element
|
462
|
+
when nil ; abbr
|
463
|
+
else ; nil
|
464
|
+
end
|
465
|
+
}
|
466
|
+
if args.length > 0
|
467
|
+
options[:clock] ||= Clock.local_time
|
468
|
+
options[:clock] = When.Clock(options[:clock])
|
469
|
+
time = Array.new(options[:clock].indices.length) {args.shift}
|
470
|
+
position = DateAndTime.new(date, time.unshift(0), options)
|
471
|
+
else
|
472
|
+
position = CalDate.new(date, options)
|
473
|
+
end
|
474
|
+
res.each do |residue|
|
475
|
+
position = position.succ if residue.carry < 0
|
476
|
+
position &= residue
|
477
|
+
end
|
478
|
+
|
479
|
+
return position unless [:raise, :check].include?(validate)
|
480
|
+
|
481
|
+
# 時間位置の存在確認
|
482
|
+
date[0] = -date[0] if position.calendar_era_props && position.calendar_era_reverse # 紀元前
|
483
|
+
date.each_index do |i|
|
484
|
+
break unless date[i]
|
485
|
+
next if When::Coordinates::Pair._force_pair(date[i]) == When::Coordinates::Pair._force_pair(position.cal_date[i])
|
486
|
+
return nil if validate == :check
|
487
|
+
raise ArgumentError, "Specified date not found: #{date}"
|
488
|
+
end
|
489
|
+
return position unless time
|
490
|
+
time.each_index do |i|
|
491
|
+
break unless time[i]
|
492
|
+
next if When::Coordinates::Pair._force_pair(time[i]) == When::Coordinates::Pair._force_pair(position.clk_time.clk_time[i])
|
493
|
+
return nil if validate == :check
|
494
|
+
raise ArgumentError, "Specified time not found: #{time}"
|
495
|
+
end
|
496
|
+
return position
|
497
|
+
end
|
498
|
+
|
499
|
+
# option の正規化
|
500
|
+
# @private
|
501
|
+
def _options(options)
|
502
|
+
query = options.dup
|
503
|
+
main = {}
|
504
|
+
clock = Clock.get_clock_option(query)
|
505
|
+
main[:clock] = clock if clock
|
506
|
+
[:indeterminated_position, :frame, :events, :precision,
|
507
|
+
:era_name, :era, :abbr, :extra_year_digits, :ordinal_date_digits, :wkst, :time_standard, :location].each do |key|
|
508
|
+
main[key] = query.delete(key) if (query.key?(key))
|
509
|
+
end
|
510
|
+
long = query.delete(:long)
|
511
|
+
lat = query.delete(:lat)
|
512
|
+
alt = query.delete(:alt)
|
513
|
+
main[:location] ||= "_l:long=#{long||0}&lat=#{lat||0}&alt=#{alt||0}" if long && lat
|
514
|
+
trans = query.delete(:trans) || {}
|
515
|
+
[:lower, :upper, :count].each do |key|
|
516
|
+
trans[key] = query.delete(key) if (query.key?(key))
|
517
|
+
end
|
518
|
+
query = query.merge(query.delete(:query)) if (query.key?(:query))
|
519
|
+
main[:query] = query if (query.size > 0)
|
520
|
+
main[:trans] = trans if (trans.size > 0)
|
521
|
+
return main
|
522
|
+
end
|
523
|
+
|
524
|
+
# 比較
|
525
|
+
# @private
|
526
|
+
def _verify(source, target)
|
527
|
+
return source.universal_time <=> target.universal_time if source.time_standard.equal?(target.time_standard)
|
528
|
+
return source.dynamical_time <=> target.dynamical_time
|
529
|
+
end
|
530
|
+
|
531
|
+
private
|
532
|
+
|
533
|
+
# date_time_or_duration
|
534
|
+
def _date_time_or_duration(specification, options)
|
535
|
+
# IntervalLength
|
536
|
+
args = IntervalLength._to_array(specification)
|
537
|
+
return IntervalLength.new(*args) if args
|
538
|
+
|
539
|
+
# PeriodDuration
|
540
|
+
sign, *args = PeriodDuration._to_array(specification)
|
541
|
+
if (sign)
|
542
|
+
args << options
|
543
|
+
duration = PeriodDuration.new(*args)
|
544
|
+
return (sign >= 0) ? duration : -duration
|
545
|
+
end
|
546
|
+
|
547
|
+
# TemporalPosition
|
548
|
+
specification =~ /(.+?)(?:\[([-+]?\d+)\])?\z/
|
549
|
+
options[:sdn] = $2.to_i if $2
|
550
|
+
f, d, t, z, e, r = When::BasicTypes::DateTime._to_array($1, options)
|
551
|
+
raise ArgumentError, "Timezone conflict: #{z} - #{options[:clock]}" if (z && options[:clock])
|
552
|
+
options.delete(:abbr)
|
553
|
+
z ||= options[:clock]
|
554
|
+
z = When.Clock(z) if (z =~ /\A[A-Z]+\z/)
|
555
|
+
|
556
|
+
unless d
|
557
|
+
# ClockTime
|
558
|
+
raise ArgumentError, "Timezone conflict: #{z} - #{options[:clock]}" if (z && options[:frame])
|
559
|
+
options[:frame] ||= z
|
560
|
+
options.delete(:clock)
|
561
|
+
return ClockTime.new(t, options)
|
562
|
+
end
|
563
|
+
|
564
|
+
options[:era_name] = e if e
|
565
|
+
options[:_format ] = f if f
|
566
|
+
d, w = d[0..0], d[1..-1] if (f == :week || f == :day)
|
567
|
+
position = z ? DateAndTime.new(d, t||[0], options.update({:clock => z})) :
|
568
|
+
t ? DateAndTime.new(d, t, options) :
|
569
|
+
CalDate.new(d, options)
|
570
|
+
case f
|
571
|
+
when :day
|
572
|
+
position += PeriodDuration.new(w[0]-1, DAY)
|
573
|
+
when :week
|
574
|
+
position = ((position + PeriodDuration.new(4, DAY)) & (Residue.day_of_week(options[:wkst]) << 1)) +
|
575
|
+
PeriodDuration.new((w[0]-1)*7 + (w[1]||1)-1, DAY)
|
576
|
+
position = When::Parts::GeometricComplex.new(position...(position+P1W)) unless w[1]
|
577
|
+
end
|
578
|
+
if r
|
579
|
+
r.keys.sort.each do |count|
|
580
|
+
residue = When.Residue(r[count])
|
581
|
+
if count == 0
|
582
|
+
residue = residue.to('year')
|
583
|
+
else
|
584
|
+
position = position.succ if residue.carry < 0
|
585
|
+
end
|
586
|
+
position &= residue
|
587
|
+
end
|
588
|
+
end
|
589
|
+
return position
|
590
|
+
end
|
591
|
+
end
|
592
|
+
|
593
|
+
# 時刻系
|
594
|
+
#
|
595
|
+
# @return [When::TimeStandard]
|
596
|
+
#
|
597
|
+
def time_standard
|
598
|
+
return @time_standard if @time_standard.kind_of?(When::TimeStandard)
|
599
|
+
@time_standard ||= clock.time_standard if respond_to?(:clock) && clock
|
600
|
+
@time_standard ||= frame.time_standard if frame
|
601
|
+
@time_standard ||= 'UniversalTime'
|
602
|
+
@time_standard = When.Resource(@time_standard, '_t:')
|
603
|
+
end
|
604
|
+
|
605
|
+
# 時間の歩度
|
606
|
+
#
|
607
|
+
# @return [Numeric]
|
608
|
+
#
|
609
|
+
def rate_of_clock
|
610
|
+
time_standard.rate_of_clock
|
611
|
+
end
|
612
|
+
|
613
|
+
# 内部時間
|
614
|
+
#
|
615
|
+
# @return [Numeric]
|
616
|
+
#
|
617
|
+
# 1970-01-01T00:00:00Z からの Universal Time, Coordinated の経過時間 / 128秒
|
618
|
+
#
|
619
|
+
# 暦法によっては、異なる意味を持つことがある
|
620
|
+
#
|
621
|
+
def universal_time
|
622
|
+
case @indeterminated_position
|
623
|
+
when Now ; time_standard.from_time_object(Time.now)
|
624
|
+
when Max ; +Float::MAX/4
|
625
|
+
when Min ; -Float::MAX/4
|
626
|
+
else ; raise NameError, "Temporal Reference System is not defined"
|
627
|
+
end
|
628
|
+
end
|
629
|
+
alias :local_time :universal_time
|
630
|
+
|
631
|
+
# 外部時間
|
632
|
+
#
|
633
|
+
# @return [Numeric]
|
634
|
+
#
|
635
|
+
# 1970-01-01T00:00:00TT からの terrestrial time の経過時間 / 128秒
|
636
|
+
#
|
637
|
+
def dynamical_time
|
638
|
+
return @dynamical_time if @dynamical_time && @indeterminated_position != Now
|
639
|
+
@dynamical_time =
|
640
|
+
case @indeterminated_position
|
641
|
+
when Max ; +Float::MAX/4
|
642
|
+
when Min ; -Float::MAX/4
|
643
|
+
else ; time_standard.to_dynamical_time(local_time)
|
644
|
+
end
|
645
|
+
end
|
646
|
+
|
647
|
+
# ユリウス日時(実数)
|
648
|
+
#
|
649
|
+
# @return [Float]
|
650
|
+
#
|
651
|
+
# universal time での経過日数を, ユリウス日と1970-01-01T00:00:00Zで時計あわせしたもの
|
652
|
+
#
|
653
|
+
def to_f
|
654
|
+
JulianDate._t_to_d(universal_time)
|
655
|
+
end
|
656
|
+
|
657
|
+
# ユリウス日(整数)
|
658
|
+
#
|
659
|
+
# @return [Integer]
|
660
|
+
#
|
661
|
+
# -4712-01-01T12:00:00Z からの経過日数に対応する通番(当該時間帯での午前0時に1進める)
|
662
|
+
#
|
663
|
+
def to_i
|
664
|
+
sd = universal_time
|
665
|
+
sd -= @frame.universal_time if @frame.kind_of?(Clock)
|
666
|
+
div, mod = sd.divmod(Duration::DAY)
|
667
|
+
div + JulianDate::JD19700101
|
668
|
+
end
|
669
|
+
|
670
|
+
# 剰余類化
|
671
|
+
#
|
672
|
+
# @param [Numeric] remainder 剰余
|
673
|
+
# @param [Integer] divisor 法(>0)
|
674
|
+
#
|
675
|
+
# @return [When::Coordinates::Residue]
|
676
|
+
#
|
677
|
+
# 当日を基準とする剰余類
|
678
|
+
#
|
679
|
+
def to_residue(remainder, divisor)
|
680
|
+
When::Coordinates::Residue.new(remainder, divisor, {'day'=>to_i})
|
681
|
+
end
|
682
|
+
|
683
|
+
# ユリウス日時(実数)
|
684
|
+
#
|
685
|
+
# @return [Float]
|
686
|
+
#
|
687
|
+
# dynamical time での経過日数を, ユリウス日と1970-01-01T00:00:00TTで時計あわせしたもの
|
688
|
+
#
|
689
|
+
def +@
|
690
|
+
JulianDate._t_to_d(dynamical_time)
|
691
|
+
end
|
692
|
+
|
693
|
+
# When::TM::ClockTime オブジェクトへの変換
|
694
|
+
#
|
695
|
+
# @return [When::TM::ClokTime]
|
696
|
+
#
|
697
|
+
def to_clock_time
|
698
|
+
raise TypeError, "Clock not assigned" unless clock
|
699
|
+
clk_time = clock.to_clk_time(universal_time - (to_i - JulianDate::JD19700101)*Duration::DAY)
|
700
|
+
clk_time.clk_time[0] += to_i
|
701
|
+
return clk_time
|
702
|
+
end
|
703
|
+
|
704
|
+
# 標準ライブラリの DateTime オブジェクトへの変換
|
705
|
+
#
|
706
|
+
# @param [Hash] option 時間の歩度が1.0でない場合のための option
|
707
|
+
# see {When::TM::TemporalPosition._instance}
|
708
|
+
#
|
709
|
+
# @param [Integer] start ::DateTime オブジェクトのグレゴリオ改暦日(ユリウス通日)
|
710
|
+
#
|
711
|
+
# @return [::DateTime]
|
712
|
+
#
|
713
|
+
def to_datetime(option={:frame=>When::UTC}, start=_default_start)
|
714
|
+
return JulianDate.dynamical_time(dynamical_time, option).to_datetime unless time_standard.rate_of_clock == 1.0
|
715
|
+
raise TypeError, "Clock not assigned" unless clock
|
716
|
+
Rational
|
717
|
+
offset = Rational(-(clock.universal_time/Duration::SECOND).to_i, (Duration::DAY/Duration::SECOND).to_i)
|
718
|
+
clk_time = clock.to_clk_time(universal_time - (to_i - JulianDate::JD19700101)*Duration::DAY).clk_time
|
719
|
+
::DateTime.jd(to_i, clk_time[1], clk_time[2], clk_time[3].to_i, offset, start)
|
720
|
+
end
|
721
|
+
|
722
|
+
# 標準ライブラリの Date オブジェクトへの変換
|
723
|
+
#
|
724
|
+
# @param [Hash] option 時間の歩度が1.0でない場合のための option
|
725
|
+
# see {When::TM::TemporalPosition._instance}
|
726
|
+
#
|
727
|
+
# @param [Integer] start ::DateTime オブジェクトのグレゴリオ改暦日(ユリウス通日)
|
728
|
+
#
|
729
|
+
# @return [::Date]
|
730
|
+
#
|
731
|
+
def to_date(option={}, start=_default_start)
|
732
|
+
return JulianDate.dynamical_time(dynamical_time, option).to_date unless time_standard.rate_of_clock == 1.0
|
733
|
+
::Date.jd(to_i, start)
|
734
|
+
end
|
735
|
+
alias :to_date_or_datetime :to_date
|
736
|
+
|
737
|
+
# 組み込みライブラリの Time オブジェクトへの変換
|
738
|
+
#
|
739
|
+
# @return [::Time]
|
740
|
+
#
|
741
|
+
def to_time
|
742
|
+
time_standard.to_time_object(universal_time)
|
743
|
+
end
|
744
|
+
|
745
|
+
# 要素の参照
|
746
|
+
#
|
747
|
+
# @param [Integer, String] index 参照する要素の指定
|
748
|
+
#
|
749
|
+
# @return [Numeric]
|
750
|
+
#
|
751
|
+
def [](index)
|
752
|
+
return value(index) if index.kind_of?(String) || !index.respond_to?(:inject)
|
753
|
+
index.inject([]) {|list, i| list << value(i) }
|
754
|
+
end
|
755
|
+
|
756
|
+
# 加算
|
757
|
+
#
|
758
|
+
# @param [Numeric, When::TM::Duration] other
|
759
|
+
#
|
760
|
+
# @return [When::TM::TemporalPosition]
|
761
|
+
#
|
762
|
+
def +(other)
|
763
|
+
case other
|
764
|
+
when Integer ; self + PeriodDuration.new(other, When::DAY)
|
765
|
+
when Numeric ; self + IntervalLength.new(other, 'day')
|
766
|
+
when PeriodDuration ; _plus(other)
|
767
|
+
when Duration ; @frame.kind_of?(Calendar) ? @frame.jul_trans(JulianDate.dynamical_time(dynamical_time + other.duration), self._attr) :
|
768
|
+
JulianDate.dynamical_time(dynamical_time + other.duration, self._attr)
|
769
|
+
else ; raise TypeError, "The right operand should be Numeric or Duration"
|
770
|
+
end
|
771
|
+
rescue RangeError
|
772
|
+
(@frame ^ self) + other
|
773
|
+
end
|
774
|
+
|
775
|
+
# 減算
|
776
|
+
#
|
777
|
+
# @param [Numeric, When::TM::Duration, When::TM::TemporalPosition] other
|
778
|
+
#
|
779
|
+
# @return [When::TM::TemporalPosition] if other is a Numeric or When::TM::Duration
|
780
|
+
# @return [When::TM::Duration] if other is a When::TM::TemporalPosition
|
781
|
+
#
|
782
|
+
def -(other)
|
783
|
+
case other
|
784
|
+
when TimeValue ; self.time_standard.rate_of_clock == other.time_standard.rate_of_clock && [@precision, other.precision].min <= When::DAY ?
|
785
|
+
PeriodDuration.new(self.to_i - other.to_i, When::DAY) :
|
786
|
+
IntervalLength.new((self.dynamical_time - other.dynamical_time) / Duration::SECOND, 'second')
|
787
|
+
when Integer ; self - PeriodDuration.new(other, When::DAY)
|
788
|
+
when Numeric ; self - IntervalLength.new(other, 'day')
|
789
|
+
when PeriodDuration ; _plus(-other)
|
790
|
+
when Duration ; @frame.kind_of?(Calendar) ? @frame.jul_trans(JulianDate.dynamical_time(dynamical_time - other.duration), self._attr) :
|
791
|
+
JulianDate.dynamical_time(dynamical_time - other.duration, self._attr)
|
792
|
+
else ; raise TypeError, "The right operand should be Numeric, Duration or TemporalPosition"
|
793
|
+
end
|
794
|
+
rescue RangeError
|
795
|
+
(@frame ^ self) - other
|
796
|
+
end
|
797
|
+
|
798
|
+
# 分解能に対応する Duration
|
799
|
+
#
|
800
|
+
# @return [When::TM::PeriodDuration]
|
801
|
+
#
|
802
|
+
def period
|
803
|
+
return @period if @period
|
804
|
+
period_name = When::Coordinates::PERIOD_NAME[@precision]
|
805
|
+
raise ArgumentError, "Presicion not defined" unless period_name
|
806
|
+
@period = When.Duration(period_name)
|
807
|
+
end
|
808
|
+
|
809
|
+
# 前の日時
|
810
|
+
#
|
811
|
+
# @return [When::TM::TemporalPosition]
|
812
|
+
#
|
813
|
+
# 分解能に対応する Duration だけ,日時を戻す
|
814
|
+
#
|
815
|
+
def prev
|
816
|
+
@precision==When::DAY ? _force_euqal_day(-1) : self-period
|
817
|
+
rescue RangeError
|
818
|
+
(When::Gregorian ^ self) - period
|
819
|
+
end
|
820
|
+
|
821
|
+
# 次の日時
|
822
|
+
#
|
823
|
+
# @return [When::TM::TemporalPosition]
|
824
|
+
#
|
825
|
+
# 分解能に対応する Duration だけ,日時を進める
|
826
|
+
#
|
827
|
+
def succ
|
828
|
+
@precision==When::DAY ? _force_euqal_day(+1) : self+period
|
829
|
+
rescue RangeError
|
830
|
+
(When::Gregorian ^ self) + period
|
831
|
+
end
|
832
|
+
alias :next :succ
|
833
|
+
|
834
|
+
#
|
835
|
+
# 前後の日時を取得可能か?
|
836
|
+
#
|
837
|
+
# @return [Boolean]
|
838
|
+
# [ true - 可能 ]
|
839
|
+
# [ false - 不可 ]
|
840
|
+
#
|
841
|
+
def has_next?
|
842
|
+
When::Coordinates::PERIOD_NAME[@precision] != nil
|
843
|
+
end
|
844
|
+
|
845
|
+
# 下位桁の切り捨て
|
846
|
+
#
|
847
|
+
# @param [Integer] digit これより下の桁を切り捨てる(省略すると When::DAY)
|
848
|
+
#
|
849
|
+
# @param [Integer] precision 切り捨て結果の分解能
|
850
|
+
#
|
851
|
+
# @return [When::TM::TemporalPosition] (本 Class では、実際には切り捨てない)
|
852
|
+
#
|
853
|
+
def floor(digit=DAY, precision=digit)
|
854
|
+
self
|
855
|
+
end
|
856
|
+
|
857
|
+
# 分解能が時刻を持つか
|
858
|
+
#
|
859
|
+
# @return [Boolean]
|
860
|
+
#
|
861
|
+
def has_time?
|
862
|
+
(@precision > 0)
|
863
|
+
end
|
864
|
+
|
865
|
+
# 指定の日時を含むか?
|
866
|
+
#
|
867
|
+
# @param [When::TM::TemporalPosition] date チェックされる日時
|
868
|
+
#
|
869
|
+
# @return [Boolean]
|
870
|
+
# [ true - 含む ]
|
871
|
+
# [ false - 含まない ]
|
872
|
+
#
|
873
|
+
def include?(date)
|
874
|
+
return false if self.precision > date.precision
|
875
|
+
return self == date
|
876
|
+
end
|
877
|
+
|
878
|
+
# オブジェクトの同値
|
879
|
+
#
|
880
|
+
# @param [比較先] other
|
881
|
+
#
|
882
|
+
# @return [Boolean]
|
883
|
+
# [ true - 同値 ]
|
884
|
+
# [ false - 非同値 ]
|
885
|
+
#
|
886
|
+
def ==(other)
|
887
|
+
(self <=> other) == 0
|
888
|
+
rescue
|
889
|
+
false
|
890
|
+
end
|
891
|
+
|
892
|
+
# 大小比較
|
893
|
+
#
|
894
|
+
# @param [When::TM::TemporalPosition] other チェックされる日時
|
895
|
+
# @param [Numeric] other チェックされる日時の universal time(self と同じtime_standardとみなす)
|
896
|
+
#
|
897
|
+
# @return [Integer] (-1, 0, 1)
|
898
|
+
#
|
899
|
+
# 分解能の低い方にあわせて比較を行う
|
900
|
+
#
|
901
|
+
# Ex. when?('2011-03') <=> when?('2011-03-10') -> 0
|
902
|
+
#
|
903
|
+
def <=>(other)
|
904
|
+
other = other.first if other.kind_of?(Range)
|
905
|
+
return universal_time <=> other if other.kind_of?(Numeric)
|
906
|
+
|
907
|
+
[self.indeterminated_position, other.indeterminated_position].each do |position|
|
908
|
+
prec = SYSTEM if [TimeValue::Min, TimeValue::Max].include?(position)
|
909
|
+
end
|
910
|
+
prec = [self.precision, other.precision].min unless prec
|
911
|
+
|
912
|
+
case prec
|
913
|
+
when DAY ; return self.to_i <=> other.to_i
|
914
|
+
when SYSTEM ; return TemporalPosition._verify(self, other)
|
915
|
+
end
|
916
|
+
|
917
|
+
if prec < DAY && respond_to?(:most_significant_coordinate) &&
|
918
|
+
other.respond_to?(:most_significant_coordinate) && @frame.equal?(other.frame)
|
919
|
+
self_year = most_significant_coordinate
|
920
|
+
other_year = other.most_significant_coordinate
|
921
|
+
if @cal_date.length + prec == 1
|
922
|
+
self_year *= 1
|
923
|
+
other_year *= 1
|
924
|
+
end
|
925
|
+
result = self_year <=> other_year
|
926
|
+
return result unless result == 0 && @cal_date.length + prec > 1
|
927
|
+
(@cal_date.length + prec - 2).times do |i|
|
928
|
+
result = @cal_date[i+1] <=> other.cal_date[i+1]
|
929
|
+
return result unless result == 0
|
930
|
+
end
|
931
|
+
@cal_date[prec - 1] <=> other.cal_date[prec - 1]
|
932
|
+
else
|
933
|
+
source = (prec >= self.precision ) ? self : self.floor(prec)
|
934
|
+
target = (prec >= other.precision) ? other : other.floor(prec)
|
935
|
+
return source.to_i <=> target.to_i if prec <= DAY
|
936
|
+
TemporalPosition._verify(source, target)
|
937
|
+
end
|
938
|
+
end
|
939
|
+
|
940
|
+
# 条件を満たすオブジェクトの抽出
|
941
|
+
#
|
942
|
+
# @param [Module, Array<Moduel>, When::Coordinates::Residue, When::TM::Duration, When::TM::Calendar, When::TM::CalendarEra] other
|
943
|
+
# @param [Boolean] leaf extract only leaf Objects.
|
944
|
+
# @param [Block] block If block is given, the specified block is yield.
|
945
|
+
#
|
946
|
+
# @return [Array of (element^self) for all When::Parts::Resource registered elements] (If other is Module)
|
947
|
+
# @return [Array of (self^element) for elemnt of other which belong to the specified module or class] (If other is [Array])
|
948
|
+
# @return [Enumerator which generates temporal position sequence begins from self with the specified duration] (If other is [When::TM::Duration])
|
949
|
+
# @return [Array of temporal position using the specified calendar as a frame] (If other is [When::TM::Calendar])
|
950
|
+
# @return [Array of temporal position using the specified calendar era as a calendarEraName] (If other is [When::TM::CalendarEra])
|
951
|
+
#
|
952
|
+
def scan(other, leaf=false, &block)
|
953
|
+
list = []
|
954
|
+
case other
|
955
|
+
when Numeric, TemporalPosition, Position
|
956
|
+
raise TypeError, "Operand should not be Numeric or (Temporal)Position"
|
957
|
+
|
958
|
+
when Module
|
959
|
+
objects = []
|
960
|
+
ObjectSpace.each_object(other) do |object|
|
961
|
+
objects << object if object.registered?
|
962
|
+
end
|
963
|
+
objects.each do |object|
|
964
|
+
element = (object ^ self)
|
965
|
+
if element && !(leaf && element.respond_to?(:leaf?) && !element.leaf?)
|
966
|
+
list << element
|
967
|
+
yield(element) if block_given?
|
968
|
+
end
|
969
|
+
end
|
970
|
+
return list
|
971
|
+
|
972
|
+
when Array
|
973
|
+
return other.map {|v| scan(v, leaf, &block)}
|
974
|
+
|
975
|
+
else
|
976
|
+
if other.respond_to?(:_enumerator)
|
977
|
+
enumerator = other._enumerator(self)
|
978
|
+
return enumerator unless block_given?
|
979
|
+
return enumerator.each(&block)
|
980
|
+
end
|
981
|
+
|
982
|
+
element = (other ^ self)
|
983
|
+
if element && !(leaf && element.respond_to?(:leaf?) && !element.leaf?)
|
984
|
+
list << element
|
985
|
+
yield(element) if block_given?
|
986
|
+
end
|
987
|
+
if (other.respond_to?(:child) && other.child)
|
988
|
+
other.child.each do |object|
|
989
|
+
list += scan(object, leaf, &block)
|
990
|
+
end
|
991
|
+
end
|
992
|
+
return list
|
993
|
+
end
|
994
|
+
end
|
995
|
+
|
996
|
+
# 条件を満たすオブジェクトの抽出
|
997
|
+
#
|
998
|
+
# @param (see #scan)
|
999
|
+
# @return (see #scan)
|
1000
|
+
#
|
1001
|
+
def ^(other, leaf=true, &block)
|
1002
|
+
scan(other, leaf, &block)
|
1003
|
+
end
|
1004
|
+
|
1005
|
+
# 属性を変更したコピーを作る
|
1006
|
+
#
|
1007
|
+
# @param [Hash] options { 属性=>属性値 }
|
1008
|
+
#
|
1009
|
+
# @return [When::TM::TemporalPosition]
|
1010
|
+
#
|
1011
|
+
def copy(options={})
|
1012
|
+
position = self.dup
|
1013
|
+
position._copy(options)
|
1014
|
+
position
|
1015
|
+
end
|
1016
|
+
|
1017
|
+
# 属性の Hash
|
1018
|
+
# @private
|
1019
|
+
def _attr
|
1020
|
+
attributes = {}
|
1021
|
+
[:frame, :events, :precision, :options, :trans, :query].each do |key|
|
1022
|
+
attributes[key] = instance_variable_get("@#{key}")
|
1023
|
+
end
|
1024
|
+
attributes[:location] = location
|
1025
|
+
attributes[:time_standard] = time_standard
|
1026
|
+
return attributes.delete_if {|k,v| !v}
|
1027
|
+
end
|
1028
|
+
|
1029
|
+
protected
|
1030
|
+
|
1031
|
+
# 属性のコピー
|
1032
|
+
# @private
|
1033
|
+
def _copy(options={})
|
1034
|
+
@frame = options[:frame] if (options.key?(:frame))
|
1035
|
+
@events = options[:events] if (options.key?(:events))
|
1036
|
+
@precision = options[:precision] if (options.key?(:precision))
|
1037
|
+
@query = options[:query] if (options.key?(:query))
|
1038
|
+
@location = options[:location] if (options.key?(:location))
|
1039
|
+
@time_standard = options[:time_standard] if (options.key?(:time_standard))
|
1040
|
+
@sdn = @universal_time = @local_time = @dynamical_time = @period = nil
|
1041
|
+
_normalize(options)
|
1042
|
+
return self
|
1043
|
+
end
|
1044
|
+
|
1045
|
+
private
|
1046
|
+
|
1047
|
+
# オブジェクトの生成
|
1048
|
+
#
|
1049
|
+
# @param [Hash] options see {When::TM::TemporalPosition._instance}
|
1050
|
+
#
|
1051
|
+
def initialize(options={})
|
1052
|
+
options.reject! {|key,value| value == nil}
|
1053
|
+
options.each_pair do |key,value|
|
1054
|
+
self.instance_variable_set("@#{key}", value)
|
1055
|
+
end
|
1056
|
+
@keys = []
|
1057
|
+
@location = When.Resource(@location, '_l:') if @location.kind_of?(String)
|
1058
|
+
# @sdn = @universal_time = @dynamical_time = nil
|
1059
|
+
_normalize(options)
|
1060
|
+
end
|
1061
|
+
|
1062
|
+
# オブジェクトの正規化
|
1063
|
+
def _normalize(options={})
|
1064
|
+
@precision ||= SYSTEM
|
1065
|
+
@period = nil
|
1066
|
+
@keys |= @frame.keys if @frame
|
1067
|
+
end
|
1068
|
+
|
1069
|
+
# 指定桁のチェック
|
1070
|
+
def _digit(index)
|
1071
|
+
digit = index.kind_of?(String) ? PRECISION[index.upcase] : index
|
1072
|
+
raise RangeError, " wrong digit: #{index}" unless digit.kind_of?(Integer) && (!block_given? || yield(digit))
|
1073
|
+
digit
|
1074
|
+
end
|
1075
|
+
|
1076
|
+
# 指定の日を探す
|
1077
|
+
def _force_euqal_day(diff)
|
1078
|
+
return self if diff == 0
|
1079
|
+
date = self + When::P1D * diff
|
1080
|
+
return date if date.to_i - to_i == diff
|
1081
|
+
if @calendar_era
|
1082
|
+
options = _attr
|
1083
|
+
options.delete(:era_name)
|
1084
|
+
era = @calendar_era
|
1085
|
+
jdn = (clock ? to_f : to_i)+diff
|
1086
|
+
while era
|
1087
|
+
date = era.^(jdn, options)
|
1088
|
+
return date if date
|
1089
|
+
era = diff > 0 ? era.succ : era.prev
|
1090
|
+
end
|
1091
|
+
raise RangeError, "can't find target date: #{self} -> #{jdn}"
|
1092
|
+
else
|
1093
|
+
done = {}
|
1094
|
+
jdn = to_i + diff
|
1095
|
+
loop do
|
1096
|
+
case
|
1097
|
+
when date.to_i == jdn
|
1098
|
+
return date
|
1099
|
+
when date.to_i > jdn
|
1100
|
+
next_date = date - When::P1D
|
1101
|
+
date = (date.to_i == next_date.to_i) ? date - When::P2D : next_date
|
1102
|
+
when date.to_i < jdn
|
1103
|
+
next_date = date + When::P1D
|
1104
|
+
date = (date.to_i == next_date.to_i) ? date + When::P2D : next_date
|
1105
|
+
end
|
1106
|
+
raise RangeError, "can't find target date: #{self} -> #{jdn}" if done.key?(date.to_i)
|
1107
|
+
done[date.to_i] = true
|
1108
|
+
end
|
1109
|
+
end
|
1110
|
+
end
|
1111
|
+
|
1112
|
+
#
|
1113
|
+
# 対応する ::Date の start 属性
|
1114
|
+
def _default_start
|
1115
|
+
frame ? frame._default_start : ::Date::GREGORIAN
|
1116
|
+
end
|
1117
|
+
|
1118
|
+
alias :_method_missing :method_missing
|
1119
|
+
|
1120
|
+
# その他のメソッド
|
1121
|
+
#
|
1122
|
+
# @note
|
1123
|
+
# When::TM::TemporalPosition で定義されていないメソッドは
|
1124
|
+
# 処理を @frame(class: When::TM::Calendar or When::TM::Clock)
|
1125
|
+
# または to_date_or_datetime(class: ::Date or ::DateTime) に委譲する
|
1126
|
+
#
|
1127
|
+
def method_missing(name, *args, &block)
|
1128
|
+
|
1129
|
+
return _method_missing(name, *args, &block) if When::Parts::MethodCash::Escape.key?(name)
|
1130
|
+
if DateTimeInstanceMethods.include?(name) && ! @frame.respond_to?(name)
|
1131
|
+
self.class.module_eval %Q{
|
1132
|
+
def #{name}(*args, &block)
|
1133
|
+
self.to_date_or_datetime.send("#{name}", *args, &block)
|
1134
|
+
end
|
1135
|
+
} unless When::Parts::MethodCash.escape(name)
|
1136
|
+
self.to_date_or_datetime.send(name, *args, &block)
|
1137
|
+
else
|
1138
|
+
self.class.module_eval %Q{
|
1139
|
+
def #{name}(*args, &block)
|
1140
|
+
@frame.send("#{name}", self, *args, &block)
|
1141
|
+
end
|
1142
|
+
} unless When::Parts::MethodCash.escape(name)
|
1143
|
+
@frame.send(name, self, *args, &block)
|
1144
|
+
end
|
1145
|
+
end
|
1146
|
+
end
|
1147
|
+
|
1148
|
+
#
|
1149
|
+
# 時間座標 - 単一の時間間隔によって定義する連続な間隔尺度を基礎とする
|
1150
|
+
#
|
1151
|
+
# see {http://schemas.opengis.net/gml/3.1.1/base/temporalAppendix.xsd#TimeCoordinateType gml schema}
|
1152
|
+
#
|
1153
|
+
class Coordinate < TemporalPosition
|
1154
|
+
|
1155
|
+
class << self
|
1156
|
+
# 内部時間によるオブジェクトの生成
|
1157
|
+
alias :universal_time :new
|
1158
|
+
|
1159
|
+
# 外部時間によるオブジェクトの生成
|
1160
|
+
#
|
1161
|
+
# @param [Numeric] dynamical_time 外部時間による時間座標値
|
1162
|
+
#
|
1163
|
+
# @param [Hash] options 下記の通り
|
1164
|
+
# @option options [When::TimeStandard] :time_standard
|
1165
|
+
#
|
1166
|
+
# @return [When::TM::Coordinate]
|
1167
|
+
#
|
1168
|
+
def dynamical_time(dynamical_time, options={})
|
1169
|
+
universal_time(When.Resource(options[:time_standard] || 'UniversalTime', '_t:').from_dynamical_time(dynamical_time), options)
|
1170
|
+
end
|
1171
|
+
|
1172
|
+
# 他種の時間位置によるオブジェクトの生成
|
1173
|
+
#
|
1174
|
+
# @param [Numeric, When::TM::ClockTime, ::Time, ::Date, ::DateTime] time 他種の時間位置によるオブジェクト
|
1175
|
+
#
|
1176
|
+
# @param [Hash] options 下記の通り
|
1177
|
+
# @option options [When::TM::Clock] :clock
|
1178
|
+
# @option options [When::Parts::Timezone] :tz
|
1179
|
+
#
|
1180
|
+
# @return [When::TM::Coordinate]
|
1181
|
+
#
|
1182
|
+
def new(time, options={})
|
1183
|
+
options = options.dup
|
1184
|
+
options[:frame] = Clock.get_clock_option(options)
|
1185
|
+
case time
|
1186
|
+
when Numeric
|
1187
|
+
options[:frame] ||= When::UTC unless time.kind_of?(Integer)
|
1188
|
+
universal_time = (2*time - (2*JulianDate::JD19700101-1)) * Duration::DAY.to_i / 2.0
|
1189
|
+
when ClockTime
|
1190
|
+
options[:frame] ||= time.clock
|
1191
|
+
universal_time = time.clk_time[0] + time.universal_time
|
1192
|
+
when ::Time
|
1193
|
+
options[:frame] ||= When.Clock(time.gmtoff)
|
1194
|
+
universal_time = options[:frame].time_standard.from_time_object(time)
|
1195
|
+
when TimeValue
|
1196
|
+
options[:frame] ||= time.clock
|
1197
|
+
universal_time = time.universal_time
|
1198
|
+
else
|
1199
|
+
if ::Object.const_defined?(:Date) && ::Date.method_defined?(:+) && time.respond_to?(:ajd)
|
1200
|
+
case time
|
1201
|
+
when ::DateTime
|
1202
|
+
options[:frame] ||= When.Clock((time.offset * 86400).to_i)
|
1203
|
+
universal_time = (2*time.ajd - (2*JulianDate::JD19700101-1)) * Duration::DAY.to_i / 2.0
|
1204
|
+
when ::Date
|
1205
|
+
universal_time = JulianDate._d_to_t(time.jd)
|
1206
|
+
if options[:frame] && options[:frame].rate_of_clock != 1.0
|
1207
|
+
universal_time = options[:frame].time_standard.from_dynamical_time(
|
1208
|
+
When::TimeStandard.to_dynamical_time(universal_time))
|
1209
|
+
end
|
1210
|
+
end
|
1211
|
+
end
|
1212
|
+
end
|
1213
|
+
raise TypeError, "Can't create #{self} from #{time.class}" unless universal_time
|
1214
|
+
universal_time(universal_time, options)
|
1215
|
+
end
|
1216
|
+
end
|
1217
|
+
|
1218
|
+
# この時間位置と関連付けられた時間参照系 (relation - Reference)
|
1219
|
+
#
|
1220
|
+
# The time reference system associated with the temporal position being described
|
1221
|
+
#
|
1222
|
+
# @return [When::TM::ReferenceSystem]
|
1223
|
+
#
|
1224
|
+
alias :clock :frame
|
1225
|
+
|
1226
|
+
# 内部時間による時間座標値
|
1227
|
+
#
|
1228
|
+
# @return [Numeric]
|
1229
|
+
#
|
1230
|
+
attr_accessor :universal_time
|
1231
|
+
alias :coordinateValue :universal_time
|
1232
|
+
protected :universal_time=
|
1233
|
+
|
1234
|
+
# 内部時間(ローカル)
|
1235
|
+
#
|
1236
|
+
# @return [Numeric]
|
1237
|
+
#
|
1238
|
+
# 1970-01-01T00:00:00(ローカル) からの Universal Coordinated Time の経過時間 / 128秒
|
1239
|
+
#
|
1240
|
+
def local_time
|
1241
|
+
@universal_time
|
1242
|
+
end
|
1243
|
+
|
1244
|
+
# CoordinateSystem による時間座標値
|
1245
|
+
#
|
1246
|
+
# @return [Numeric]
|
1247
|
+
#
|
1248
|
+
def coordinateValue
|
1249
|
+
(universal_time - frame.origin.universal_time) / frame.interval.to_f
|
1250
|
+
end
|
1251
|
+
|
1252
|
+
# 加算
|
1253
|
+
#
|
1254
|
+
# @param [Numeric, When::TM::IntervalLength] other
|
1255
|
+
#
|
1256
|
+
# @return [When::TM::TemporalPosition]
|
1257
|
+
#
|
1258
|
+
def +(other)
|
1259
|
+
other = other.to_interval_length if other.kind_of?(PeriodDuration)
|
1260
|
+
super(other)
|
1261
|
+
end
|
1262
|
+
|
1263
|
+
# 減算
|
1264
|
+
#
|
1265
|
+
# @param [When::TM::TemporalPosition, Numeric, When::TM::IntervalLength] other
|
1266
|
+
#
|
1267
|
+
# @return [When::TM::TemporalPosition] if other is a Numeric or When::TM::IntervalLength
|
1268
|
+
# @return [When::TM::IntervalLength] if other is a When::TM::TemporalPosition
|
1269
|
+
#
|
1270
|
+
def -(other)
|
1271
|
+
other = other.to_interval_length if other.kind_of?(PeriodDuration)
|
1272
|
+
super(other)
|
1273
|
+
end
|
1274
|
+
|
1275
|
+
# オブジェクトの生成
|
1276
|
+
#
|
1277
|
+
# @param [Numeric] universal_time 内部時間による時間座標値
|
1278
|
+
#
|
1279
|
+
# @param [Hash] options 下記の通り
|
1280
|
+
# @option options [When::TM::CoordinateSystem] :frame
|
1281
|
+
#
|
1282
|
+
def initialize(universal_time, options={})
|
1283
|
+
super(options)
|
1284
|
+
@universal_time = universal_time
|
1285
|
+
end
|
1286
|
+
end
|
1287
|
+
|
1288
|
+
#
|
1289
|
+
# ユリウス日
|
1290
|
+
#
|
1291
|
+
# see {http://schemas.opengis.net/gml/3.1.1/base/temporalAppendix.xsd#JulianDateType CALENdeRsign}
|
1292
|
+
#
|
1293
|
+
class JulianDate < Coordinate
|
1294
|
+
|
1295
|
+
# Julian Day Number
|
1296
|
+
# 19700101T120000Z
|
1297
|
+
JD19700101 = 2440588
|
1298
|
+
|
1299
|
+
# Modified Julian Date
|
1300
|
+
#
|
1301
|
+
# see {http://en.wikipedia.org/wiki/Julian_day#Variants MJD}
|
1302
|
+
JDN_of_MJD = 2400000.5
|
1303
|
+
|
1304
|
+
# Countdown to Equinoctial Planetconjunction
|
1305
|
+
#
|
1306
|
+
# see {http://www.calendersign.com/en/cs_cep-pec.php CEP}
|
1307
|
+
JDN_of_CEP = 2698162
|
1308
|
+
|
1309
|
+
class << self
|
1310
|
+
|
1311
|
+
JD19700100_5 = JD19700101 - 0.5
|
1312
|
+
|
1313
|
+
#
|
1314
|
+
# 日時の内部表現をユリウス日に変換
|
1315
|
+
#
|
1316
|
+
# @param [Numeric] t
|
1317
|
+
#
|
1318
|
+
# @return [Numeric]
|
1319
|
+
#
|
1320
|
+
def _t_to_d(t)
|
1321
|
+
t / Duration::DAY + JD19700100_5
|
1322
|
+
end
|
1323
|
+
|
1324
|
+
#
|
1325
|
+
# ユリウス日をに日時の内部表現変換
|
1326
|
+
#
|
1327
|
+
# @param [Numeric] d
|
1328
|
+
#
|
1329
|
+
# @return [Numeric]
|
1330
|
+
#
|
1331
|
+
def _d_to_t(d)
|
1332
|
+
(d - JD19700100_5) * Duration::DAY
|
1333
|
+
end
|
1334
|
+
|
1335
|
+
# Generation of Temporal Objetct
|
1336
|
+
#
|
1337
|
+
# @param [String] specification ユリウス通日を表す文字列
|
1338
|
+
# @param [Hash] options 暦法や時法などの指定 (see {When::TM::TemporalPosition._instance})
|
1339
|
+
#
|
1340
|
+
# @return [When::TM::TemporalPosition, When::TM::Duration, When::Parts::GeometricComplex or Array<them>]
|
1341
|
+
#
|
1342
|
+
def parse(specification, options={})
|
1343
|
+
num, *calendars = specification.split(/\^{1,2}/)
|
1344
|
+
jdn = num.sub!(/[.@]/, '.') ? num.to_f : num.to_i
|
1345
|
+
case num
|
1346
|
+
when/MJD/i ; jdn += JDN_of_MJD
|
1347
|
+
when/CEP/i ; jdn += JDN_of_CEP
|
1348
|
+
end
|
1349
|
+
frame = calendars.shift || options[:frame]
|
1350
|
+
return self.new(jdn, options) unless frame
|
1351
|
+
calendars.unshift(frame).inject(jdn) {|date, calendar| When.Calendar(calendar).jul_trans(date, options)}
|
1352
|
+
end
|
1353
|
+
end
|
1354
|
+
|
1355
|
+
# 加算
|
1356
|
+
#
|
1357
|
+
# @param [Numeric, When::TM::IntervalLength] other
|
1358
|
+
#
|
1359
|
+
# @return [When::TM::TemporalPosition]
|
1360
|
+
#
|
1361
|
+
def +(other)
|
1362
|
+
new_date = super
|
1363
|
+
new_date.frame = new_date.frame._daylight(new_date.universal_time) if new_date.frame && new_date.frame._need_validate
|
1364
|
+
return new_date
|
1365
|
+
end
|
1366
|
+
|
1367
|
+
# ユリウス日が指定の剰余となる日
|
1368
|
+
#
|
1369
|
+
# @param [When::Coordinates::Residue] other
|
1370
|
+
#
|
1371
|
+
# @return [When::TM::TemporalPosition]
|
1372
|
+
#
|
1373
|
+
def &(other)
|
1374
|
+
raise TypeError,"The right operand should be When::Coordinates::Residue" unless other.kind_of?(Residue)
|
1375
|
+
raise ArgumentError,"The right operand should have a unit 'day'" unless other.event == 'day'
|
1376
|
+
jdn = to_i
|
1377
|
+
new_date = self.dup
|
1378
|
+
new_date.universal_time += ((other & jdn) - jdn) * Duration::DAY
|
1379
|
+
return new_date
|
1380
|
+
end
|
1381
|
+
|
1382
|
+
# ユリウス日の剰余
|
1383
|
+
#
|
1384
|
+
# @param [When::Coordinates::Residue] other
|
1385
|
+
#
|
1386
|
+
# @return [Numeric]
|
1387
|
+
#
|
1388
|
+
def %(other)
|
1389
|
+
raise TypeError,"The right operand should be When::Coordinates::Residue" unless other.kind_of?(Residue)
|
1390
|
+
raise ArgumentError,"The right operand should have a unit 'day'" unless other.event == 'day'
|
1391
|
+
other % to_i
|
1392
|
+
end
|
1393
|
+
|
1394
|
+
private
|
1395
|
+
|
1396
|
+
# オブジェクトの生成
|
1397
|
+
#
|
1398
|
+
# @param [Numeric] universal_time 内部時間による時間座標値
|
1399
|
+
#
|
1400
|
+
# @param [Hash] options 以下の通り
|
1401
|
+
# @option options [When::TM::Clock] :frame
|
1402
|
+
# @option options [Integer] :precision
|
1403
|
+
#
|
1404
|
+
def initialize(universal_time, options={})
|
1405
|
+
@frame = options.delete(:frame)
|
1406
|
+
@frame = When.Clock(@frame) if (@frame.kind_of?(String))
|
1407
|
+
@frame = @frame._daylight(universal_time) if @frame && @frame._need_validate
|
1408
|
+
precision = options.delete(:precision)
|
1409
|
+
precision ||= DAY unless @frame.kind_of?(Clock)
|
1410
|
+
@precision = Index.precision(precision)
|
1411
|
+
super
|
1412
|
+
end
|
1413
|
+
end
|
1414
|
+
|
1415
|
+
#
|
1416
|
+
# 順序時間参照系で参照する位置
|
1417
|
+
#
|
1418
|
+
# see {http://schemas.opengis.net/gml/3.1.1/base/temporalAppendix.xsd#TimeOrdinalPositionType gml schema}
|
1419
|
+
#
|
1420
|
+
class OrdinalPosition < TemporalPosition
|
1421
|
+
|
1422
|
+
# この順序位置と関連付けられた順序年代 (relation - Reference)
|
1423
|
+
#
|
1424
|
+
# The ordinal era associated with the ordinal position being described
|
1425
|
+
#
|
1426
|
+
# @return [When::TM::OrdinalEra]
|
1427
|
+
#
|
1428
|
+
attr_reader :ordinal_position
|
1429
|
+
alias :ordinalPosition :ordinal_position
|
1430
|
+
|
1431
|
+
# オブジェクトの生成
|
1432
|
+
#
|
1433
|
+
# @param [When::TM::OrdinalEra] ordinal_position この順序位置と関連付けられた順序年代
|
1434
|
+
# @param [Hash] options see {When::TM::TemporalPosition._instance}
|
1435
|
+
#
|
1436
|
+
def initialize(ordinal_position, options={})
|
1437
|
+
super(options)
|
1438
|
+
@ordinal_position = ordinal_position
|
1439
|
+
end
|
1440
|
+
end
|
1441
|
+
|
1442
|
+
#
|
1443
|
+
# 時刻
|
1444
|
+
#
|
1445
|
+
# see {http://schemas.opengis.net/gml/3.1.1/base/temporalAppendix.xsd#ClockTimeType gml schema}
|
1446
|
+
#
|
1447
|
+
class ClockTime < TemporalPosition
|
1448
|
+
|
1449
|
+
# 時刻要素
|
1450
|
+
#
|
1451
|
+
# @return [Array<Numeric>]
|
1452
|
+
#
|
1453
|
+
# @note ISO19108 では sequence<Integer> だが、閏時・閏秒などが表現可能なよう Numeric としている。
|
1454
|
+
#
|
1455
|
+
attr_reader :clk_time
|
1456
|
+
alias :clkTime :clk_time
|
1457
|
+
|
1458
|
+
# この時間位置と関連付けられた時間参照系 (relation - Reference)
|
1459
|
+
#
|
1460
|
+
# The time reference system associated with the temporal position being described
|
1461
|
+
#
|
1462
|
+
# @return [When::TM::ReferenceSystem]
|
1463
|
+
#
|
1464
|
+
alias :clock :frame
|
1465
|
+
|
1466
|
+
# 内部時間
|
1467
|
+
#
|
1468
|
+
# @param [Integer] sdn 参照事象の通し番号
|
1469
|
+
#
|
1470
|
+
# @return [Numeric]
|
1471
|
+
#
|
1472
|
+
# T00:00:00Z からの Universal Coordinated Time の経過時間 / 128秒
|
1473
|
+
#
|
1474
|
+
# 時法によっては、異なる意味を持つことがある
|
1475
|
+
#
|
1476
|
+
def universal_time(sdn=nil)
|
1477
|
+
raise NameError, "Temporal Reference System is not defined" unless @frame
|
1478
|
+
@universal_time ||= @frame.to_universal_time(@clk_time, sdn)
|
1479
|
+
end
|
1480
|
+
|
1481
|
+
# 内部時間(ローカル)
|
1482
|
+
#
|
1483
|
+
# @param [Integer] sdn 参照事象の通し番号
|
1484
|
+
#
|
1485
|
+
# @return [Numeric]
|
1486
|
+
#
|
1487
|
+
# T00:00:00(ローカル) からの Universal Coordinated Time の経過時間 / 128秒
|
1488
|
+
#
|
1489
|
+
# 時法によっては、異なる意味を持つことがある
|
1490
|
+
#
|
1491
|
+
def local_time(sdn=nil)
|
1492
|
+
raise NameError, "Temporal Reference System is not defined" unless @frame
|
1493
|
+
@local_time ||= @frame.to_local_time(@clk_time, sdn)
|
1494
|
+
end
|
1495
|
+
|
1496
|
+
# 繰り上がり
|
1497
|
+
#
|
1498
|
+
# @return [Numeric]
|
1499
|
+
#
|
1500
|
+
# 日付の境界が午前0時でない場合、clk_time の最上位桁に 0 以外が入ることがある
|
1501
|
+
#
|
1502
|
+
def carry
|
1503
|
+
return @clk_time[0]
|
1504
|
+
end
|
1505
|
+
|
1506
|
+
# 要素の参照
|
1507
|
+
#
|
1508
|
+
# @param [Integer, String] index 参照する要素の指定
|
1509
|
+
#
|
1510
|
+
# @return [Numeric]
|
1511
|
+
#
|
1512
|
+
def value(index)
|
1513
|
+
@clk_time[_digit(index) {|digit| digit >= DAY}]
|
1514
|
+
end
|
1515
|
+
|
1516
|
+
#protected
|
1517
|
+
# 属性のコピー
|
1518
|
+
# @private
|
1519
|
+
def _copy(options={})
|
1520
|
+
@clk_time = options[:time] if (options.key?(:time))
|
1521
|
+
@frame = options[:clock] if (options.key?(:clock))
|
1522
|
+
if (options.key?(:tz_prop))
|
1523
|
+
@frame = @frame.dup
|
1524
|
+
@frame.tz_prop = options[:tz_prop]
|
1525
|
+
end
|
1526
|
+
return super
|
1527
|
+
end
|
1528
|
+
|
1529
|
+
# オブジェクトの生成
|
1530
|
+
#
|
1531
|
+
# @param [String] time ISO8601形式の時刻表現
|
1532
|
+
# @param [Array<Numeric>] time (日, 時, 分, 秒)
|
1533
|
+
#
|
1534
|
+
#
|
1535
|
+
# @param [Hash] options 以下の通り
|
1536
|
+
# @option options [When::TM::Clock] :frame
|
1537
|
+
# @option options [Integer] :precision
|
1538
|
+
#
|
1539
|
+
def initialize(time, options={})
|
1540
|
+
# 参照系の取得
|
1541
|
+
@frame = options[:frame] || Clock.local_time
|
1542
|
+
@frame = When.Clock(@frame) if (@frame.kind_of?(String))
|
1543
|
+
options.delete(:frame)
|
1544
|
+
|
1545
|
+
# 時刻表現の解読 ( Time Zone の解釈 )
|
1546
|
+
if (time.kind_of?(String))
|
1547
|
+
case time
|
1548
|
+
when /\A([-+])?(\d{2,}?):?(\d{2})?:?(\d{2}(\.\d+)?)?\z/
|
1549
|
+
sign, hh, mm, ss = $~[1..4]
|
1550
|
+
time = @frame._validate([0,0,0,0],
|
1551
|
+
[0,
|
1552
|
+
-(sign.to_s + "0" + hh.to_s).to_i,
|
1553
|
+
-(sign.to_s + "0" + mm.to_s).to_i,
|
1554
|
+
Pair._en_number(-(sign.to_s + "0" + ss.to_s).to_f)])
|
1555
|
+
time[0] = Pair.new(0, time[0].to_i) if (time[0] != 0)
|
1556
|
+
when /\AZ\z/
|
1557
|
+
time = [0,0,0,0]
|
1558
|
+
else
|
1559
|
+
raise ArgumentError, "Invalid Time Format"
|
1560
|
+
end
|
1561
|
+
end
|
1562
|
+
@clk_time = time
|
1563
|
+
|
1564
|
+
# 分解能
|
1565
|
+
@precision = @frame._precision(time, options.delete(:precision))
|
1566
|
+
|
1567
|
+
super(options)
|
1568
|
+
end
|
1569
|
+
|
1570
|
+
private
|
1571
|
+
|
1572
|
+
# オブジェクトの正規化
|
1573
|
+
def _normalize(options={})
|
1574
|
+
# strftime で使用する locale
|
1575
|
+
@keys |= @frame.keys
|
1576
|
+
|
1577
|
+
# 時刻の正規化
|
1578
|
+
@clk_time = @frame._validate(@clk_time) unless options[:validate]
|
1579
|
+
end
|
1580
|
+
|
1581
|
+
# 加減算共通処理
|
1582
|
+
def _plus(period)
|
1583
|
+
self.dup._copy({:time=>@frame._validate(@clk_time, @frame._arrange_length(period.time)),
|
1584
|
+
:events=>nil, :query=>nil, :validate=>:done})
|
1585
|
+
end
|
1586
|
+
end
|
1587
|
+
|
1588
|
+
#
|
1589
|
+
# 暦日
|
1590
|
+
#
|
1591
|
+
# see {gml schema}[link:http://schemas.opengis.net/gml/3.1.1/base/temporalAppendix.xsd#CalDateType]
|
1592
|
+
#
|
1593
|
+
class CalDate < TemporalPosition
|
1594
|
+
|
1595
|
+
# 検索オプション
|
1596
|
+
# @private
|
1597
|
+
SearchOption = {After=>[0, -2, Before], Before=>[-2, 0, After]}
|
1598
|
+
|
1599
|
+
# 日付要素
|
1600
|
+
#
|
1601
|
+
# @return [Array<Numeric>]
|
1602
|
+
#
|
1603
|
+
# @note ISO19108 では sequence<Integer> だが、閏月などが表現可能なよう Numeric としている。
|
1604
|
+
#
|
1605
|
+
attr_reader :cal_date
|
1606
|
+
alias :calDate :cal_date
|
1607
|
+
|
1608
|
+
# この時間位置と関連付けられた時間参照系 (relation - Reference)
|
1609
|
+
#
|
1610
|
+
# The time reference system associated with the temporal position being described
|
1611
|
+
#
|
1612
|
+
# @return [When::TM::ReferenceSystem]
|
1613
|
+
#
|
1614
|
+
alias :calendar :frame
|
1615
|
+
|
1616
|
+
# 暦年代
|
1617
|
+
#
|
1618
|
+
# @return [When::TM::CalendarEra]
|
1619
|
+
#
|
1620
|
+
attr_accessor :calendar_era
|
1621
|
+
private :calendar_era=
|
1622
|
+
alias :calendarEra :calendar_era
|
1623
|
+
|
1624
|
+
# 暦年代属性
|
1625
|
+
#
|
1626
|
+
# @return [Array] ( name, epoch, reverse, go back )
|
1627
|
+
# - name [String] 暦年代名
|
1628
|
+
# - epoch [Integer] 使用する When::TM::Calendar で暦元に対応する年
|
1629
|
+
# - reverse [Boolean] 年数が昇順(false,nil)か降順(true)か
|
1630
|
+
# - go back [Boolean] 参照イベントより前の暦日か(true)、否か(false,nil)
|
1631
|
+
#
|
1632
|
+
attr_accessor :calendar_era_props
|
1633
|
+
private :calendar_era_props=
|
1634
|
+
|
1635
|
+
# 暦年代名
|
1636
|
+
#
|
1637
|
+
# @return [String] 暦年代名
|
1638
|
+
#
|
1639
|
+
def calendar_era_name
|
1640
|
+
@calendar_era_props ? @calendar_era_props[0] : nil
|
1641
|
+
end
|
1642
|
+
alias :calendarEraName :calendar_era_name
|
1643
|
+
|
1644
|
+
# 暦年代元期
|
1645
|
+
#
|
1646
|
+
# @return [Integer] 使用する When::TM::Calendar で暦元に対応する年
|
1647
|
+
#
|
1648
|
+
def calendar_era_epoch
|
1649
|
+
@calendar_era_props ? @calendar_era_props[1] : 0
|
1650
|
+
end
|
1651
|
+
|
1652
|
+
# 暦年代正逆
|
1653
|
+
#
|
1654
|
+
# @return [Boolean] 年数が昇順(false,nil)か降順(true)か
|
1655
|
+
#
|
1656
|
+
def calendar_era_reverse
|
1657
|
+
@calendar_era_props ? @calendar_era_props[2] : false
|
1658
|
+
end
|
1659
|
+
|
1660
|
+
# 暦年代遡及
|
1661
|
+
#
|
1662
|
+
# @return [Boolean] 参照イベントより前の暦日か(true)、否か(false,nil)
|
1663
|
+
#
|
1664
|
+
def calendar_era_go_back
|
1665
|
+
@calendar_era_props ? @calendar_era_props[3] : false
|
1666
|
+
end
|
1667
|
+
|
1668
|
+
# 時法の取得 - ダミー
|
1669
|
+
def clock
|
1670
|
+
nil
|
1671
|
+
end
|
1672
|
+
|
1673
|
+
# 内部時間
|
1674
|
+
#
|
1675
|
+
# @return [Numeric]
|
1676
|
+
#
|
1677
|
+
# 当日正午の 1970-01-01T00:00:00Z からの Universal Coordinated Time の経過時間 / 128秒
|
1678
|
+
#
|
1679
|
+
def universal_time
|
1680
|
+
return super if [Now, Max, Min].include?(@indeterminated_position)
|
1681
|
+
@universal_time ||= JulianDate._d_to_t(to_i)
|
1682
|
+
end
|
1683
|
+
alias :local_time :universal_time
|
1684
|
+
|
1685
|
+
# ユリウス日
|
1686
|
+
#
|
1687
|
+
# @return [Integer]
|
1688
|
+
#
|
1689
|
+
# -4712-01-01からの経過日数に対応する通番
|
1690
|
+
#
|
1691
|
+
def to_i
|
1692
|
+
@sdn ||= _to_i
|
1693
|
+
end
|
1694
|
+
|
1695
|
+
#
|
1696
|
+
# 暦法上の通日
|
1697
|
+
#
|
1698
|
+
def _to_i
|
1699
|
+
void, epoch = @calendar_era_props
|
1700
|
+
if epoch
|
1701
|
+
date = @cal_date.dup
|
1702
|
+
date[0] += epoch
|
1703
|
+
else
|
1704
|
+
date = @cal_date
|
1705
|
+
end
|
1706
|
+
@frame.to_julian_date(date)
|
1707
|
+
end
|
1708
|
+
private :_to_i
|
1709
|
+
|
1710
|
+
# 剰余類化
|
1711
|
+
#
|
1712
|
+
# @param [Numeric] remainder 剰余
|
1713
|
+
# @param [Integer] divisor 法(>0)
|
1714
|
+
#
|
1715
|
+
# @return [When::Coordinates::Residue] 当日、当年を基準とする剰余類
|
1716
|
+
#
|
1717
|
+
def to_residue(remainder, divisor)
|
1718
|
+
When::Coordinates::Residue.new(remainder, divisor, {'day' => least_significant_coordinate,
|
1719
|
+
'year' => most_significant_coordinate})
|
1720
|
+
end
|
1721
|
+
|
1722
|
+
# 要素の参照
|
1723
|
+
#
|
1724
|
+
# @param [Integer, String] index 参照する要素の指定
|
1725
|
+
#
|
1726
|
+
# @return [Numeric]
|
1727
|
+
#
|
1728
|
+
def value(index)
|
1729
|
+
@cal_date[(_digit(index) {|digit| digit <= DAY})-1]
|
1730
|
+
end
|
1731
|
+
|
1732
|
+
#
|
1733
|
+
# 最上位の要素
|
1734
|
+
#
|
1735
|
+
# @return [Numeric] 暦年代の epoch に関わらず暦法に従った年の通し番号を返す
|
1736
|
+
#
|
1737
|
+
def most_significant_coordinate
|
1738
|
+
coordinate = @cal_date[0]
|
1739
|
+
coordinate += calendar_era_epoch if @calendar_era_props
|
1740
|
+
@frame.index_of_MSC.times do |i|
|
1741
|
+
coordinate = +coordinate * @frame.indices[i].unit + @cal_date[i+1] - @frame.indices[i].base
|
1742
|
+
end
|
1743
|
+
coordinate
|
1744
|
+
end
|
1745
|
+
|
1746
|
+
#
|
1747
|
+
# 最下位の要素
|
1748
|
+
#
|
1749
|
+
# @return [Numeric] 剰余類の演算に用いる日の通し番号を返す
|
1750
|
+
#
|
1751
|
+
def least_significant_coordinate
|
1752
|
+
return to_i + @frame.indices[-1].shift
|
1753
|
+
end
|
1754
|
+
|
1755
|
+
# ユリウス日または通年が指定の剰余となる日
|
1756
|
+
#
|
1757
|
+
# @param [When::Coordinates::Residue] other
|
1758
|
+
#
|
1759
|
+
# @return [When::TM::CalDate]
|
1760
|
+
#
|
1761
|
+
def &(other)
|
1762
|
+
raise TypeError,"The right operand should be When::Coordinates::Residue" unless other.kind_of?(Residue)
|
1763
|
+
case other.event
|
1764
|
+
when 'day'
|
1765
|
+
# 指定の剰余となる日
|
1766
|
+
sdn = other & to_i
|
1767
|
+
options = {:date=>_date_with_era(@frame.to_cal_date(sdn)), :events=>nil, :query=>@query, :validate=>:done}
|
1768
|
+
options[:precision] = When::DAY if precision < When::DAY
|
1769
|
+
result = self.dup._copy(options)
|
1770
|
+
result.send(:_force_euqal_day, sdn-result.to_i)
|
1771
|
+
|
1772
|
+
when 'year'
|
1773
|
+
# 指定の剰余となる年
|
1774
|
+
date = @frame.send(:_decode, _date_without_era)
|
1775
|
+
date[0] = (other & (date[0] + @frame.diff_to_CE)) - @frame.diff_to_CE
|
1776
|
+
options = {:date=>_date_with_era(@frame.send(:_encode, date)), :events=>nil, :query=>@query}
|
1777
|
+
options[:precision] = When::YEAR if precision < When::YEAR
|
1778
|
+
return self.dup._copy(options)
|
1779
|
+
|
1780
|
+
else
|
1781
|
+
raise ArgumentError,"The right operand should have a unit 'day' or 'year'"
|
1782
|
+
end
|
1783
|
+
end
|
1784
|
+
|
1785
|
+
# ユリウス日または通年の剰余
|
1786
|
+
#
|
1787
|
+
# @param [When::Coordinates::Residue] other
|
1788
|
+
#
|
1789
|
+
# @return [Numeric]
|
1790
|
+
#
|
1791
|
+
def %(other)
|
1792
|
+
raise TypeError,"The right operand should be When::Coordinates::Residue" unless other.kind_of?(Residue)
|
1793
|
+
if precision <= When::YEAR && other.units['year'] && other.event != 'year'
|
1794
|
+
other.to('year') % (most_significant_coordinate + @frame.epoch_in_CE)
|
1795
|
+
else
|
1796
|
+
case other.event
|
1797
|
+
when 'day' ; other % least_significant_coordinate
|
1798
|
+
when 'year' ; other % (most_significant_coordinate + @frame.epoch_in_CE)
|
1799
|
+
else ; raise ArgumentError,"The right operand should have a unit 'day' or 'year'"
|
1800
|
+
end
|
1801
|
+
end
|
1802
|
+
end
|
1803
|
+
|
1804
|
+
# 下位桁の切り捨て
|
1805
|
+
#
|
1806
|
+
# @param [Integer] digit 切り捨てずに残す、最下位の桁
|
1807
|
+
#
|
1808
|
+
# @param [Integer] precision 切り捨て結果の分解能
|
1809
|
+
#
|
1810
|
+
# @return [When::TM::CalDate]
|
1811
|
+
#
|
1812
|
+
def floor(digit=DAY, precision=digit)
|
1813
|
+
options = {:date=>@cal_date[0..(digit-1)], :events=>nil, :query=>nil}
|
1814
|
+
options[:precision] = precision if precision
|
1815
|
+
self.dup._copy(options)
|
1816
|
+
end
|
1817
|
+
|
1818
|
+
# 下位桁の切り上げ
|
1819
|
+
#
|
1820
|
+
# @param [Integer] digit 切り上げずに残す、最下位の桁
|
1821
|
+
#
|
1822
|
+
# @param [Integer] precision 切り上げ結果の分解能
|
1823
|
+
#
|
1824
|
+
# @return [When::TM::CalDate]
|
1825
|
+
#
|
1826
|
+
def ceil(digit=DAY, precision=digit)
|
1827
|
+
(self + PeriodDuration.new(1, digit, (-@frame.indices.length)..0)).floor(digit, precision)
|
1828
|
+
end
|
1829
|
+
|
1830
|
+
# 要素数 ― 上位要素に含まれる下位要素の数
|
1831
|
+
#
|
1832
|
+
# @param [Integer] upper 上位要素のインデックス
|
1833
|
+
# @param [Integer] lower 下位要素のインデックス(DAY または MONTH)
|
1834
|
+
#
|
1835
|
+
# @return [Integer]
|
1836
|
+
#
|
1837
|
+
def length(upper, lower=DAY)
|
1838
|
+
range = [floor(upper).to_i, ceil(upper).to_i]
|
1839
|
+
range = range.map {|d| (Residue.mod(d) {|m| frame._new_month(m)})[0]} if lower == MONTH
|
1840
|
+
range[1] - range[0]
|
1841
|
+
end
|
1842
|
+
|
1843
|
+
# 時刻情報のない When::TM::CalDate を返す
|
1844
|
+
#
|
1845
|
+
# @return [When::TM::CalDate]
|
1846
|
+
#
|
1847
|
+
alias :to_cal_date :dup
|
1848
|
+
alias :to_CalDate :to_cal_date
|
1849
|
+
|
1850
|
+
# 暦年代が末端の参照であるか?
|
1851
|
+
#
|
1852
|
+
# @return [Boolean]
|
1853
|
+
#
|
1854
|
+
def leaf?
|
1855
|
+
! @calendar_era.respond_to?(:_pool) || @calendar_era.leaf?
|
1856
|
+
end
|
1857
|
+
|
1858
|
+
# 属性の Hash
|
1859
|
+
# @private
|
1860
|
+
def _attr
|
1861
|
+
super.merge({:era_name=>@calendar_era_props, :era=>@calendar_era})
|
1862
|
+
end
|
1863
|
+
protected
|
1864
|
+
|
1865
|
+
# 属性のコピー
|
1866
|
+
# @private
|
1867
|
+
def _copy(options={})
|
1868
|
+
@cal_date = options[:date] if (options.key?(:date))
|
1869
|
+
return super
|
1870
|
+
end
|
1871
|
+
|
1872
|
+
# オブジェクトの生成
|
1873
|
+
#
|
1874
|
+
# @param [Array<Numeric>] date 日付表現
|
1875
|
+
#
|
1876
|
+
# @param [Hash] options 下記の通り (see also {When::TM::TemporalPosition._instance})
|
1877
|
+
# @option options [When::TM::Calendar] :frame
|
1878
|
+
# @option options [When::TM::CalendarEra, When::BasicTypes::M17n, Array<When::BasicTypes::M17n, Integer>] :era_name
|
1879
|
+
# (Integer は 当該年号の 0 年に相当する通年)
|
1880
|
+
# @option options [Integer] :precision
|
1881
|
+
#
|
1882
|
+
def initialize(date, options={})
|
1883
|
+
# 年号 & 日付
|
1884
|
+
@calendar_era_props = options[:era_name]
|
1885
|
+
@calendar_era = options[:era]
|
1886
|
+
@cal_date = date
|
1887
|
+
|
1888
|
+
super(options)
|
1889
|
+
end
|
1890
|
+
|
1891
|
+
private
|
1892
|
+
|
1893
|
+
# オブジェクトの正規化
|
1894
|
+
def _normalize(options={})
|
1895
|
+
|
1896
|
+
# 日付配列の長さ
|
1897
|
+
cal_date_index = @cal_date.index(nil) || @cal_date.length
|
1898
|
+
|
1899
|
+
# 日付の正規化
|
1900
|
+
if @calendar_era_props
|
1901
|
+
# Calendar Era がある場合
|
1902
|
+
trans_options = @trans || {} # TODO? 消す
|
1903
|
+
count = trans_options[:count] || 1
|
1904
|
+
query_options = (@query || {}).dup
|
1905
|
+
query_options[:label] = @calendar_era_props
|
1906
|
+
query_options[:count] = count
|
1907
|
+
era = date = nil
|
1908
|
+
if @calendar_era
|
1909
|
+
era, date = _search_era(@calendar_era, trans_options)
|
1910
|
+
else
|
1911
|
+
eras = CalendarEra._instance(query_options)
|
1912
|
+
raise ArgumentError, "CalendarEraName doesn't exist: #{query_options[:label]}" if (eras.size==0)
|
1913
|
+
eras.each do |e|
|
1914
|
+
era, date = _search_era(e, trans_options)
|
1915
|
+
next unless era
|
1916
|
+
count -= 1
|
1917
|
+
break unless count > 0
|
1918
|
+
end
|
1919
|
+
end
|
1920
|
+
raise RangeError, "Out of CalendarEra Range" unless era
|
1921
|
+
@calendar_era_props = date.calendar_era_props
|
1922
|
+
@calendar_era = era
|
1923
|
+
@cal_date = date.cal_date
|
1924
|
+
@frame = date.frame
|
1925
|
+
@query = (@query||{}).merge(date.query)
|
1926
|
+
@trans = (@trans||{}).merge(date.trans)
|
1927
|
+
@keys |= calendar_era_name.keys | @frame.keys
|
1928
|
+
else
|
1929
|
+
# Calendar Era がない場合
|
1930
|
+
@frame = When.Resource(options[:frame] || @frame || 'Gregorian', '_c:')
|
1931
|
+
@cal_date = @frame._validate(@cal_date) unless options[:validate] == :done
|
1932
|
+
@keys |= @frame.keys
|
1933
|
+
end
|
1934
|
+
|
1935
|
+
# 分解能
|
1936
|
+
precision = options.delete(:precision) || @precision
|
1937
|
+
cal_date_index =
|
1938
|
+
case options.delete(:_format)
|
1939
|
+
when :century ; CENTURY
|
1940
|
+
when :week, :day ; DAY
|
1941
|
+
else ; cal_date_index - (@frame.indices.length + 1)
|
1942
|
+
end
|
1943
|
+
precision ||= cal_date_index if cal_date_index < DAY
|
1944
|
+
precision ||= @clk_time.precision if @clk_time
|
1945
|
+
@precision = Index.precision(precision || DAY)
|
1946
|
+
end
|
1947
|
+
|
1948
|
+
# 暦年代を探す
|
1949
|
+
def _search_era(era, trans_options)
|
1950
|
+
cal_date = @cal_date.dup
|
1951
|
+
cal_date[0] = -cal_date[0] if era.reverse?
|
1952
|
+
cal_date[0] += era.epoch_year
|
1953
|
+
date = era.trans(cal_date, trans_options)
|
1954
|
+
loop do
|
1955
|
+
case date
|
1956
|
+
when Before, After
|
1957
|
+
i0, i1, reverse = SearchOption[date]
|
1958
|
+
new_era = (date == Before) ? era.prev : era.succ
|
1959
|
+
break unless new_era
|
1960
|
+
date = new_era.trans(cal_date, trans_options)
|
1961
|
+
if date == reverse
|
1962
|
+
cal_date = new_era.epoch[i0].frame.to_cal_date(era.epoch[i1].frame.to_julian_date(cal_date))
|
1963
|
+
date = new_era.trans(cal_date, trans_options)
|
1964
|
+
break if date == reverse
|
1965
|
+
end
|
1966
|
+
era = new_era
|
1967
|
+
when TimeValue
|
1968
|
+
return era, date
|
1969
|
+
else
|
1970
|
+
break
|
1971
|
+
end
|
1972
|
+
end
|
1973
|
+
return nil
|
1974
|
+
end
|
1975
|
+
|
1976
|
+
# 加減算共通処理
|
1977
|
+
def _plus(period)
|
1978
|
+
_frame_adjust(period, self.dup._copy({:date=>_date_with_era(@frame._validate(_date_without_era,
|
1979
|
+
@frame._arrange_length(period.date))),
|
1980
|
+
:events=>nil, :query=>nil, :validate=>:done}))
|
1981
|
+
end
|
1982
|
+
|
1983
|
+
# 年号を除外した @frame の暦法に対応する日付
|
1984
|
+
def _date_without_era
|
1985
|
+
date = @cal_date.dup
|
1986
|
+
date[0] += calendar_era_epoch if @calendar_era_props
|
1987
|
+
date
|
1988
|
+
end
|
1989
|
+
|
1990
|
+
# 年号に続く日付
|
1991
|
+
def _date_with_era(date)
|
1992
|
+
date[0] -= calendar_era_epoch if @calendar_era_props
|
1993
|
+
date
|
1994
|
+
end
|
1995
|
+
|
1996
|
+
# 暦法が変わった場合の補正
|
1997
|
+
def _frame_adjust(period, date)
|
1998
|
+
return date if @frame.equal?(date.frame) || (period.to_day||0) == 0
|
1999
|
+
diff = period.to_day - (date.to_i - to_i)
|
2000
|
+
return date if diff == 0
|
2001
|
+
date.send(:_force_euqal_day, diff)
|
2002
|
+
end
|
2003
|
+
end
|
2004
|
+
|
2005
|
+
#
|
2006
|
+
# 時刻を伴った日付
|
2007
|
+
#
|
2008
|
+
# see {http://schemas.opengis.net/gml/3.1.1/base/temporalAppendix.xsd#DateAndTimeType gml schema}
|
2009
|
+
#
|
2010
|
+
class DateAndTime < CalDate
|
2011
|
+
|
2012
|
+
# 時刻要素
|
2013
|
+
#
|
2014
|
+
# @return [When::TM::ClockTime]
|
2015
|
+
#
|
2016
|
+
attr_reader :clk_time
|
2017
|
+
alias :clkTime :clk_time
|
2018
|
+
|
2019
|
+
# 時法の取得
|
2020
|
+
#
|
2021
|
+
# @return [When::TM::Clock]
|
2022
|
+
#
|
2023
|
+
def clock
|
2024
|
+
@clk_time.frame
|
2025
|
+
end
|
2026
|
+
|
2027
|
+
# 内部時間
|
2028
|
+
#
|
2029
|
+
# @return [Numeric]
|
2030
|
+
#
|
2031
|
+
# 1970-01-01T00:00:00Z からの Universal Coordinated Time の経過時間 / 128秒
|
2032
|
+
#
|
2033
|
+
# 暦法によっては、異なる意味を持つことがある
|
2034
|
+
#
|
2035
|
+
def universal_time
|
2036
|
+
return super if [Now, Max, Min].include?(@indeterminated_position)
|
2037
|
+
raise NameError, "Temporal Reference System is not defined" unless (@frame && clock)
|
2038
|
+
@universal_time ||= (to_i - JulianDate::JD19700101) * Duration::DAY + @clk_time.universal_time(to_i)
|
2039
|
+
end
|
2040
|
+
|
2041
|
+
# 内部時間(ローカル)
|
2042
|
+
#
|
2043
|
+
# @return [Numeric]
|
2044
|
+
#
|
2045
|
+
# 1970-01-01T00:00:00(ローカル) からの Universal Coordinated Time の経過時間 / 128秒
|
2046
|
+
#
|
2047
|
+
# 暦法によっては、異なる意味を持つことがある
|
2048
|
+
#
|
2049
|
+
def local_time
|
2050
|
+
return super if [Now, Max, Min].include?(@indeterminated_position)
|
2051
|
+
raise NameError, "Temporal Reference System is not defined" unless (@frame && clock)
|
2052
|
+
@local_time ||= (to_i - JulianDate::JD19700101) * Duration::DAY + @clk_time.local_time(to_i)
|
2053
|
+
end
|
2054
|
+
|
2055
|
+
# 要素の参照
|
2056
|
+
#
|
2057
|
+
# @param [Integer] index 参照する要素の指定
|
2058
|
+
#
|
2059
|
+
# @return [Numeric]
|
2060
|
+
#
|
2061
|
+
def value(index)
|
2062
|
+
digit = _digit(index)
|
2063
|
+
return (digit <= DAY) ? @cal_date[digit-1] : @clk_time.clk_time[digit]
|
2064
|
+
end
|
2065
|
+
|
2066
|
+
# ユリウス日または通年が指定の剰余となる日
|
2067
|
+
#
|
2068
|
+
# @param [When::Coordinates::Residue] other
|
2069
|
+
#
|
2070
|
+
# @return [When::TM::DateAndTime]
|
2071
|
+
#
|
2072
|
+
def &(other)
|
2073
|
+
raise TypeError,"The right operand should be When::Coordinates::Residue" unless other.kind_of?(Residue)
|
2074
|
+
case other.event
|
2075
|
+
when 'day'
|
2076
|
+
# 指定の剰余となる日
|
2077
|
+
sdn = other & to_i
|
2078
|
+
options = {:date=>_date_with_era(@frame.to_cal_date(sdn)), :time=>@clk_time.clk_time.dup,
|
2079
|
+
:events=>nil, :query=>@query, :validate=>:done}
|
2080
|
+
options[:precision] = When::DAY if precision < When::DAY
|
2081
|
+
result = self.dup._copy(options)
|
2082
|
+
result.send(:_force_euqal_day, sdn-result.to_i)
|
2083
|
+
|
2084
|
+
when 'year'
|
2085
|
+
# 指定の剰余となる年
|
2086
|
+
date = @frame.send(:_decode, _date_without_era)
|
2087
|
+
date[0] = (other & (date[0] + @frame.diff_to_CE)) - @frame.diff_to_CE
|
2088
|
+
options = {:date=>_date_with_era(@frame.send(:_encode, date)), :time=>@clk_time.clk_time.dup,
|
2089
|
+
:events=>nil, :query=>@query}
|
2090
|
+
options[:precision] = When::YEAR if precision < When::YEAR
|
2091
|
+
return self.dup._copy(options)
|
2092
|
+
|
2093
|
+
else
|
2094
|
+
raise ArgumentError,"The right operand should have a unit 'day' or 'year'"
|
2095
|
+
end
|
2096
|
+
end
|
2097
|
+
|
2098
|
+
# 下位桁の切り捨て
|
2099
|
+
#
|
2100
|
+
# @param [Integer] digit 切り捨てずに残す、最下位の桁
|
2101
|
+
#
|
2102
|
+
# @param [Integer] precision 切り捨て結果の分解能
|
2103
|
+
#
|
2104
|
+
# @return [When::TM::DateAndTime]
|
2105
|
+
#
|
2106
|
+
def floor(digit=DAY, precision=digit)
|
2107
|
+
count = digit - clock.indices.length
|
2108
|
+
date = (digit>=DAY) ? @cal_date.dup : @frame._validate(@cal_date[0..(digit-1)])
|
2109
|
+
time = @clk_time.clk_time[0..((digit<=DAY) ? 0 : ((count>=0) ? -1 : digit))]
|
2110
|
+
time[0] += to_i
|
2111
|
+
time = clock._validate(time)
|
2112
|
+
time[0] -= to_i
|
2113
|
+
|
2114
|
+
if (count >= 0)
|
2115
|
+
factor = 10**count
|
2116
|
+
time[-1] = (time[-1] * factor).floor.to_f / factor
|
2117
|
+
end
|
2118
|
+
|
2119
|
+
# オブジェクトの生成
|
2120
|
+
options = {:date=>date, :validate=>:done, :events=>nil, :query=>nil,
|
2121
|
+
:time=>(digit<=DAY) ? time : @clk_time.dup._copy({:time=>time})}
|
2122
|
+
options[:precision] = precision if precision
|
2123
|
+
return self.dup._copy(options)
|
2124
|
+
end
|
2125
|
+
|
2126
|
+
# 下位桁の切り上げ
|
2127
|
+
#
|
2128
|
+
# @param [Integer] digit 切り上げずに残す、最下位の桁
|
2129
|
+
#
|
2130
|
+
# @param [Integer] precision 切り上げ結果の分解能
|
2131
|
+
#
|
2132
|
+
# @return [When::TM::DateAndTime]
|
2133
|
+
#
|
2134
|
+
def ceil(digit=DAY, precision=digit)
|
2135
|
+
length = clock.indices.length
|
2136
|
+
count = digit - length
|
2137
|
+
period = PeriodDuration.new((count<=0) ? 1 : 0.1**count, digit, (-@frame.indices.length)..length)
|
2138
|
+
result = floor(digit, precision) + period
|
2139
|
+
result += clock.tz_difference if (result.universal_time <= self.universal_time)
|
2140
|
+
return result
|
2141
|
+
end
|
2142
|
+
|
2143
|
+
# 位置情報
|
2144
|
+
#
|
2145
|
+
# @return [When::Coordinates::Spatial]
|
2146
|
+
#
|
2147
|
+
def location
|
2148
|
+
@location ||= @clk_time.frame.location
|
2149
|
+
end
|
2150
|
+
|
2151
|
+
# 時刻情報のない When::TM::CalDate を返す
|
2152
|
+
#
|
2153
|
+
# @return [When::TM::CalDate]
|
2154
|
+
#
|
2155
|
+
def to_cal_date
|
2156
|
+
options = _attr
|
2157
|
+
options.delete(:clock)
|
2158
|
+
options[:precision] = [When::DAY, options[:precision]].min
|
2159
|
+
CalDate.new(@cal_date, options)
|
2160
|
+
end
|
2161
|
+
alias :to_CalDate :to_cal_date
|
2162
|
+
|
2163
|
+
# 標準ライブラリの DateTime オブジェクトへの変換
|
2164
|
+
#
|
2165
|
+
alias :to_date_or_datetime :to_datetime
|
2166
|
+
|
2167
|
+
#protected
|
2168
|
+
|
2169
|
+
# 属性の Hash
|
2170
|
+
# @private
|
2171
|
+
def _attr
|
2172
|
+
super.merge({:clock=>clock})
|
2173
|
+
end
|
2174
|
+
|
2175
|
+
# 属性のコピー
|
2176
|
+
# @private
|
2177
|
+
def _copy(options={})
|
2178
|
+
# 夏時間の調整
|
2179
|
+
case options[:time]
|
2180
|
+
when Array
|
2181
|
+
if clock._need_validate
|
2182
|
+
new_clock = clock._daylight([@frame, options[:date], options[:time]])
|
2183
|
+
options[:time] = options[:time].map {|t| t * 1}
|
2184
|
+
else
|
2185
|
+
new_clock = clock
|
2186
|
+
end
|
2187
|
+
options[:time] = @clk_time.dup._copy(options.merge({:clock=>new_clock}))
|
2188
|
+
when nil
|
2189
|
+
options[:time] = @clk_time.dup._copy(options)
|
2190
|
+
end
|
2191
|
+
|
2192
|
+
return super(options)
|
2193
|
+
end
|
2194
|
+
|
2195
|
+
# オブジェクトの生成
|
2196
|
+
#
|
2197
|
+
# @param [Array<Numeric>] date 日付表現
|
2198
|
+
# @param [Array<Numeric>] time 時刻表現
|
2199
|
+
# @param [Hash] options 下記の通り (see also {When::TM::TemporalPosition._instance})
|
2200
|
+
# @option options [When::TM::Calendar] :frame
|
2201
|
+
# @option options [When::TM::Clock] :clock
|
2202
|
+
# @option options [When::TM::CalendarEra, When::BasicTypes::M17n, Array<When::BasicTypes::M17n, Integer>] :era_name
|
2203
|
+
# (Integer は 当該年号の 0 年に相当する通年)
|
2204
|
+
# @option options [Integer] :precision
|
2205
|
+
#
|
2206
|
+
def initialize(date, time, options={})
|
2207
|
+
options[:time] = time
|
2208
|
+
super(date, options)
|
2209
|
+
end
|
2210
|
+
|
2211
|
+
private
|
2212
|
+
|
2213
|
+
# オブジェクトの正規化
|
2214
|
+
def _normalize(options={})
|
2215
|
+
|
2216
|
+
# Clock
|
2217
|
+
unless options[:validate]
|
2218
|
+
clock = Clock.get_clock_option(options)
|
2219
|
+
clock ||= options[:time].frame if options[:time].kind_of?(ClockTime)
|
2220
|
+
clock ||= Clock.local_time
|
2221
|
+
end
|
2222
|
+
clock = When.Clock(clock) if clock.kind_of?(String)
|
2223
|
+
clock_is_timezone = clock && !clock.kind_of?(When::TM::Clock)
|
2224
|
+
clock = clock.daylight if clock_is_timezone
|
2225
|
+
|
2226
|
+
# ClockTime
|
2227
|
+
@clk_time =
|
2228
|
+
case options[:time]
|
2229
|
+
when ClockTime ; options[:time]
|
2230
|
+
when Array ; ClockTime.new(options[:time], {:frame=>clock, :precision=>options[:precision], :validate=>:done})
|
2231
|
+
else ; clock.to_clk_time(options[:time], {:precision=>options[:precision]})
|
2232
|
+
end
|
2233
|
+
|
2234
|
+
super
|
2235
|
+
|
2236
|
+
# 日付と時刻の正規化
|
2237
|
+
unless options[:validate]
|
2238
|
+
time = @clk_time.clk_time
|
2239
|
+
precision = @clk_time.precision
|
2240
|
+
second = time[clock.base.length-1]
|
2241
|
+
second -= clock.base[-1] if second
|
2242
|
+
if second && second != 0 && time_standard.has_leap?
|
2243
|
+
zero = DateAndTime.new(@cal_date, time[0..-2],
|
2244
|
+
{:frame=>@frame, :clock=>clock, :precision=>precision,
|
2245
|
+
:era_name=>@calendar_era_props, :era=>options[:era],
|
2246
|
+
:time_standard=>time_standard, :location=>@location})
|
2247
|
+
end
|
2248
|
+
|
2249
|
+
# 日付と時刻の関係の調整
|
2250
|
+
@cal_date = _date_with_era(@frame._validate(_date_without_era) {|jdn|
|
2251
|
+
time[0] += jdn
|
2252
|
+
time[0..-1] = clock._validate(time)
|
2253
|
+
jdn = time[0] * 1
|
2254
|
+
time[0] -= jdn
|
2255
|
+
jdn
|
2256
|
+
})
|
2257
|
+
|
2258
|
+
# 夏時間の調整
|
2259
|
+
if clock._need_validate
|
2260
|
+
if @calendar_era_props
|
2261
|
+
cal_date = @cal_date.dup
|
2262
|
+
cal_date[0] += calendar_era_epoch
|
2263
|
+
else
|
2264
|
+
cal_date = @cal_date
|
2265
|
+
end
|
2266
|
+
clock = clock._daylight([@frame, cal_date, time])
|
2267
|
+
end
|
2268
|
+
time = [time[0]] + time[1..-1].map {|t| t * 1}
|
2269
|
+
@clk_time = ClockTime.new(time, {:frame=>clock, :precision=>precision, :validate=>:done}) if clock_is_timezone
|
2270
|
+
|
2271
|
+
# 閏秒
|
2272
|
+
if zero
|
2273
|
+
leap = ((dynamical_time - zero.dynamical_time) * clock.second - second).to_i
|
2274
|
+
if leap != 0 && leap.abs < clock.second
|
2275
|
+
@cal_date = zero.cal_date
|
2276
|
+
@clk_time = zero.clk_time
|
2277
|
+
@clk_time.clk_time[-1] += second
|
2278
|
+
leap /= clock.second
|
2279
|
+
@universal_time = @local_time = When::Coordinates::LeapSeconds.new(@local_time-leap, leap, 1/clock.second)
|
2280
|
+
@dynamical_time -= leap
|
2281
|
+
end
|
2282
|
+
end
|
2283
|
+
end
|
2284
|
+
|
2285
|
+
# 後処理
|
2286
|
+
@keys |= @clk_time.keys
|
2287
|
+
end
|
2288
|
+
|
2289
|
+
# 加減算共通処理
|
2290
|
+
def _plus(period)
|
2291
|
+
# 日時の加算
|
2292
|
+
time = @clk_time.clk_time.dup
|
2293
|
+
pdate = @frame._arrange_length(period.date)
|
2294
|
+
ptime = clock._arrange_length(period.time)
|
2295
|
+
date = _date_with_era(@frame._validate(_date_without_era, pdate) {|jdn|
|
2296
|
+
time[0] += jdn
|
2297
|
+
time = clock._validate(time, ptime)
|
2298
|
+
jdn = time[0] * 1
|
2299
|
+
time[0] -= jdn
|
2300
|
+
jdn
|
2301
|
+
})
|
2302
|
+
|
2303
|
+
# オブジェクトの生成
|
2304
|
+
_frame_adjust(period, self.dup._copy({:date=>date, :time=>time, :validate=>:done, :events=>nil, :query=>nil}))
|
2305
|
+
end
|
2306
|
+
end
|
2307
|
+
end
|