when_exe 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/locales.rb +2 -2
- data/bin/when.rb +2 -2
- data/lib/when_exe.rb +161 -55
- data/lib/when_exe/basictypes.rb +34 -26
- data/lib/when_exe/calendarnote.rb +654 -0
- data/lib/when_exe/calendartypes.rb +49 -474
- data/lib/when_exe/coordinates.rb +141 -34
- data/lib/when_exe/core/compatibility.rb +22 -2
- data/lib/when_exe/core/extension.rb +47 -3
- data/lib/when_exe/ephemeris.rb +82 -109
- data/lib/when_exe/googlecalendar.rb +1 -1
- data/lib/when_exe/icalendar.rb +26 -14
- data/lib/when_exe/inspect.rb +82 -68
- data/lib/when_exe/locales/af.rb +1 -1
- data/lib/when_exe/locales/ar.rb +1 -1
- data/lib/when_exe/locales/az.rb +1 -1
- data/lib/when_exe/locales/bg.rb +1 -1
- data/lib/when_exe/locales/bn.rb +1 -1
- data/lib/when_exe/locales/bs.rb +1 -1
- data/lib/when_exe/locales/ca.rb +1 -1
- data/lib/when_exe/locales/cs.rb +1 -1
- data/lib/when_exe/locales/cy.rb +1 -1
- data/lib/when_exe/locales/da.rb +1 -1
- data/lib/when_exe/locales/de.rb +1 -1
- data/lib/when_exe/locales/de_AT.rb +1 -1
- data/lib/when_exe/locales/de_CH.rb +1 -1
- data/lib/when_exe/locales/el.rb +1 -1
- data/lib/when_exe/locales/en.rb +1 -1
- data/lib/when_exe/locales/en_AU.rb +1 -1
- data/lib/when_exe/locales/en_CA.rb +1 -1
- data/lib/when_exe/locales/en_GB.rb +1 -1
- data/lib/when_exe/locales/en_IE.rb +1 -1
- data/lib/when_exe/locales/en_IN.rb +1 -1
- data/lib/when_exe/locales/en_NZ.rb +1 -1
- data/lib/when_exe/locales/en_US.rb +1 -1
- data/lib/when_exe/locales/eo.rb +1 -1
- data/lib/when_exe/locales/es.rb +1 -1
- data/lib/when_exe/locales/es_419.rb +1 -1
- data/lib/when_exe/locales/es_AR.rb +1 -1
- data/lib/when_exe/locales/es_CL.rb +1 -1
- data/lib/when_exe/locales/es_CO.rb +1 -1
- data/lib/when_exe/locales/es_CR.rb +1 -1
- data/lib/when_exe/locales/es_EC.rb +1 -1
- data/lib/when_exe/locales/es_MX.rb +1 -1
- data/lib/when_exe/locales/es_PA.rb +1 -1
- data/lib/when_exe/locales/es_PE.rb +1 -1
- data/lib/when_exe/locales/es_VE.rb +1 -1
- data/lib/when_exe/locales/et.rb +1 -1
- data/lib/when_exe/locales/eu.rb +1 -1
- data/lib/when_exe/locales/fa.rb +1 -1
- data/lib/when_exe/locales/fi.rb +1 -1
- data/lib/when_exe/locales/fr.rb +1 -1
- data/lib/when_exe/locales/fr_CA.rb +1 -1
- data/lib/when_exe/locales/fr_CH.rb +1 -1
- data/lib/when_exe/locales/gl.rb +1 -1
- data/lib/when_exe/locales/he.rb +1 -1
- data/lib/when_exe/locales/hi.rb +1 -1
- data/lib/when_exe/locales/hi_IN.rb +1 -1
- data/lib/when_exe/locales/hr.rb +1 -1
- data/lib/when_exe/locales/hu.rb +1 -1
- data/lib/when_exe/locales/id.rb +1 -1
- data/lib/when_exe/locales/is.rb +1 -1
- data/lib/when_exe/locales/it.rb +1 -1
- data/lib/when_exe/locales/it_CH.rb +1 -1
- data/lib/when_exe/locales/ja.rb +1 -1
- data/lib/when_exe/locales/kn.rb +1 -1
- data/lib/when_exe/locales/ko.rb +1 -1
- data/lib/when_exe/locales/lo.rb +1 -1
- data/lib/when_exe/locales/locales.rb +1 -1
- data/lib/when_exe/locales/lt.rb +1 -1
- data/lib/when_exe/locales/lv.rb +1 -1
- data/lib/when_exe/locales/mk.rb +1 -1
- data/lib/when_exe/locales/mn.rb +1 -1
- data/lib/when_exe/locales/ms.rb +1 -1
- data/lib/when_exe/locales/nb.rb +1 -1
- data/lib/when_exe/locales/ne.rb +1 -1
- data/lib/when_exe/locales/nl.rb +1 -1
- data/lib/when_exe/locales/nn.rb +1 -1
- data/lib/when_exe/locales/or.rb +1 -1
- data/lib/when_exe/locales/pl.rb +1 -1
- data/lib/when_exe/locales/pt.rb +1 -1
- data/lib/when_exe/locales/pt_BR.rb +1 -1
- data/lib/when_exe/locales/rm.rb +1 -1
- data/lib/when_exe/locales/ro.rb +1 -1
- data/lib/when_exe/locales/ru.rb +1 -1
- data/lib/when_exe/locales/sk.rb +1 -1
- data/lib/when_exe/locales/sl.rb +1 -1
- data/lib/when_exe/locales/sr.rb +1 -1
- data/lib/when_exe/locales/sv.rb +1 -1
- data/lib/when_exe/locales/sw.rb +1 -1
- data/lib/when_exe/locales/th.rb +1 -1
- data/lib/when_exe/locales/tl.rb +1 -1
- data/lib/when_exe/locales/tr.rb +1 -1
- data/lib/when_exe/locales/uk.rb +1 -1
- data/lib/when_exe/locales/ur.rb +1 -1
- data/lib/when_exe/locales/uz.rb +1 -1
- data/lib/when_exe/locales/vi.rb +1 -1
- data/lib/when_exe/locales/wo.rb +1 -1
- data/lib/when_exe/locales/zh_CN.rb +1 -1
- data/lib/when_exe/locales/zh_HK.rb +1 -1
- data/lib/when_exe/locales/zh_TW.rb +1 -1
- data/lib/when_exe/mini_application.rb +6 -2
- data/lib/when_exe/parts/enumerator.rb +13 -8
- data/lib/when_exe/parts/geometric_complex.rb +3 -5
- data/lib/when_exe/parts/locale.rb +185 -28
- data/lib/when_exe/parts/method_cash.rb +20 -10
- data/lib/when_exe/parts/resource.rb +154 -76
- data/lib/when_exe/parts/timezone.rb +11 -6
- data/lib/when_exe/region/bahai.rb +2 -2
- data/lib/when_exe/region/balinese.rb +296 -296
- data/lib/when_exe/region/chinese.rb +564 -564
- data/lib/when_exe/region/chinese_calendar.rb +5 -1
- data/lib/when_exe/region/chinese_epoch.rb +47 -102
- data/lib/when_exe/region/chinese_twin.rb +798 -0
- data/lib/when_exe/region/christian.rb +314 -338
- data/lib/when_exe/region/coptic.rb +88 -0
- data/lib/when_exe/region/ephemeric_notes.rb +322 -307
- data/lib/when_exe/region/french.rb +2 -2
- data/lib/when_exe/region/indian.rb +361 -272
- data/lib/when_exe/region/iranian.rb +2 -2
- data/lib/when_exe/region/islamic.rb +3 -3
- data/lib/when_exe/region/japanese.rb +1 -1
- data/lib/when_exe/region/japanese_notes.rb +165 -103
- data/lib/when_exe/region/japanese_residues.rb +56 -55
- data/lib/when_exe/region/japanese_twin.rb +228 -0
- data/lib/when_exe/region/javanese.rb +2 -2
- data/lib/when_exe/region/jewish.rb +2 -2
- data/lib/when_exe/region/korean.rb +4 -4
- data/lib/when_exe/region/m17n.rb +19 -19
- data/lib/when_exe/region/martian.rb +21 -9
- data/lib/when_exe/region/mayan.rb +19 -11
- data/lib/when_exe/region/moon.rb +7 -7
- data/lib/when_exe/region/nihon_shoki.rb +7 -7
- data/lib/when_exe/region/roman.rb +100 -100
- data/lib/when_exe/region/shire.rb +130 -147
- data/lib/when_exe/region/thai.rb +2 -2
- data/lib/when_exe/region/tibetan.rb +2 -2
- data/lib/when_exe/region/vietnamese.rb +383 -114
- data/lib/when_exe/region/world.rb +112 -129
- data/lib/when_exe/timestandard.rb +12 -1
- data/lib/when_exe/tmposition.rb +28 -14
- data/lib/when_exe/tmreference.rb +96 -93
- data/lib/when_exe/version.rb +1 -1
- data/test/examples/Terms.m17n +2 -2
- data/test/examples/sample.json +16 -0
- data/test/examples/sample.xml +1 -1
- data/test/test.rb +4 -0
- data/test/test/basictypes.rb +2 -2
- data/test/test/calendarnote.rb +69 -0
- data/test/test/calendartypes.rb +41 -1
- data/test/test/coordinates.rb +12 -1
- data/test/test/ephemeris.rb +13 -66
- data/test/test/icalendar.rb +3 -3
- data/test/test/inspect.rb +1 -1
- data/test/test/parts.rb +7 -4
- data/test/test/region/chinese.rb +45 -0
- data/test/test/region/coptic.rb +27 -0
- data/test/test/region/indian.rb +1 -1
- data/test/test/region/japanese.rb +4 -4
- data/test/test/region/jewish.rb +1 -1
- data/test/test/region/m17n.rb +7 -5
- data/test/test/region/residue.rb +2 -2
- data/test/test/region/vietnamese.rb +102 -0
- data/test/test/timestandard.rb +81 -0
- data/test/test/tmposition.rb +1 -1
- data/test/test/tmreference.rb +1 -1
- data/when_exe.gemspec +2 -2
- metadata +16 -7
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
=begin
|
3
|
-
Copyright (C) 2011-
|
3
|
+
Copyright (C) 2011-2014 Takashi SUGA
|
4
4
|
|
5
5
|
You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
|
6
6
|
=end
|
@@ -12,7 +12,7 @@ module When
|
|
12
12
|
WorldTerms = [self, [
|
13
13
|
"namespace:[en=http://en.wikipedia.org/wiki/, ja=http://ja.wikipedia.org/wiki/]",
|
14
14
|
"locale:[=en:, ja=ja:, alias]",
|
15
|
-
"names:[WorldTerms]",
|
15
|
+
"names:[WorldTerms=]",
|
16
16
|
"[World=en:The_World_Calendar, 世界暦]"
|
17
17
|
]]
|
18
18
|
end
|
@@ -21,159 +21,142 @@ module When
|
|
21
21
|
|
22
22
|
World = [self, [
|
23
23
|
"namespace:[en=http://en.wikipedia.org/wiki/]",
|
24
|
-
"area:[Common]",
|
24
|
+
"area:[Common=]",
|
25
25
|
["[BCE=en:BCE_(disambiguation), alias:BeforeCommonEra]0.1.1"],
|
26
26
|
["[CE=en:Common_Era, alias:CommonEra]1.1.1", "Calendar Epoch", "01-01-01^World"]
|
27
27
|
]]
|
28
28
|
end
|
29
29
|
|
30
|
-
|
30
|
+
#
|
31
|
+
# 世界暦の暦週
|
32
|
+
#
|
33
|
+
class CalendarNote::WorldWeek < CalendarNote
|
31
34
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
NoteObjects = [When::BasicTypes::M17n, [
|
38
|
-
"namespace:[en=http://en.wikipedia.org/wiki/, ja=http://ja.wikipedia.org/wiki/]",
|
39
|
-
"locale:[=en:, ja=ja:, alias]",
|
40
|
-
"names:[World]",
|
35
|
+
NoteObjects = [When::BasicTypes::M17n, [
|
36
|
+
"namespace:[en=http://en.wikipedia.org/wiki/, ja=http://ja.wikipedia.org/wiki/]",
|
37
|
+
"locale:[=en:, ja=ja:, alias]",
|
38
|
+
"names:[World]",
|
41
39
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
40
|
+
# 年の暦注 ----------------------------
|
41
|
+
[When::BasicTypes::M17n,
|
42
|
+
"names:[year]"
|
43
|
+
],
|
46
44
|
|
47
|
-
|
45
|
+
# 月の暦注 ----------------------------
|
46
|
+
[When::BasicTypes::M17n,
|
47
|
+
"names:[month]",
|
48
48
|
[When::BasicTypes::M17n,
|
49
|
-
"names:[
|
50
|
-
|
51
|
-
|
52
|
-
]
|
53
|
-
],
|
49
|
+
"names:[Month]"
|
50
|
+
]
|
51
|
+
],
|
54
52
|
|
55
|
-
|
53
|
+
# 日の暦注 ----------------------------
|
54
|
+
[When::BasicTypes::M17n,
|
55
|
+
"names:[day]",
|
56
56
|
[When::BasicTypes::M17n,
|
57
|
-
"names:[
|
58
|
-
[
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
"[Saturday, 土曜日]",
|
67
|
-
"[Worldsday, 無曜日]"
|
68
|
-
]
|
57
|
+
"names:[Week]",
|
58
|
+
"[Sunday, 日曜日]",
|
59
|
+
"[Monday, 月曜日]",
|
60
|
+
"[Tuesday, 火曜日]",
|
61
|
+
"[Wednesday, 水曜日]",
|
62
|
+
"[Thursday, 木曜日]",
|
63
|
+
"[Friday, 金曜日]",
|
64
|
+
"[Saturday, 土曜日]",
|
65
|
+
"[Worldsday, 無曜日]"
|
69
66
|
]
|
70
|
-
]
|
67
|
+
]
|
68
|
+
]]
|
71
69
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
70
|
+
# イベントの標準的な間隔を返す
|
71
|
+
# @private
|
72
|
+
def _delta(parameter=nil)
|
73
|
+
return When::DurationP1W
|
74
|
+
end
|
77
75
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
76
|
+
# @private
|
77
|
+
def worldsday_delta(parameter=nil)
|
78
|
+
return When::TM::PeriodDuration.new([0,0,7*26+1])
|
79
|
+
end
|
82
80
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
81
|
+
# 当日または直前の worldsday の日
|
82
|
+
# @param date [When::TM::TemporalPosition]
|
83
|
+
# @param parameter [nil] 未使用
|
84
|
+
# @return [When::TM::TemporalPosition]
|
85
|
+
#
|
86
|
+
def worldsday(date, parameter=nil)
|
87
|
+
event_name = 'worldsday'
|
88
|
+
date = When.Calendar('World').jul_trans(date, {:events=>event_name})
|
89
|
+
y,m,d = date.cal_date
|
90
|
+
h, m = (m-1).divmod(6)
|
91
|
+
return date if m == 5 && d == 31
|
92
|
+
dow = [0, 31, 61, 91, 122, 152][m] + d
|
93
|
+
dow += 182 if h == 1 && When.Calendar('World')._sum([y]) == 365
|
94
|
+
date += When::TM::PeriodDuration.new([0,0,-dow])
|
95
|
+
date.events = [event_name]
|
96
|
+
date
|
97
|
+
end
|
100
98
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
alias :#{name}_delta :_delta
|
125
|
-
}
|
126
|
-
end
|
99
|
+
# 当日または直前の week_day の日
|
100
|
+
# @method week_day(date, parameter=nil)
|
101
|
+
# @param date [When::TM::TemporalPosition]
|
102
|
+
# @param parameter [nil] 未使用
|
103
|
+
# @return [When::TM::TemporalPosition]
|
104
|
+
# @note week_day は sunday, monday, tuesday, wednesday, thursday, friday, saturday に読み替えてください。
|
105
|
+
|
106
|
+
# @private
|
107
|
+
7.times do |k|
|
108
|
+
name = When.CalendarNote('WorldWeek/NoteObjects::day::Week')[k].to_s.downcase
|
109
|
+
module_eval %Q{
|
110
|
+
def #{name}(date, parameter=nil)
|
111
|
+
event_name = 'from_#{name}'
|
112
|
+
date = When.Calendar('World').jul_trans(date, {:events=>[event_name], :precision=>When::DAY})
|
113
|
+
y,m,d = date.cal_date
|
114
|
+
dow = (m % 6 == 0 && d == 31) ? 7-#{k} : ([4,6,2][m % 3] + d - #{k}) % 7
|
115
|
+
return date if dow == 0
|
116
|
+
dow += 1 if d <= dow && (m == 1 || m == 7 && When.Calendar('World')._sum([y]) == 366)
|
117
|
+
date += When::TM::PeriodDuration.new([0,0,-dow])
|
118
|
+
date.events = [event_name]
|
119
|
+
date
|
120
|
+
end
|
127
121
|
|
128
|
-
|
122
|
+
alias :#{name}_delta :_delta
|
123
|
+
}
|
124
|
+
end
|
129
125
|
|
130
|
-
|
131
|
-
#
|
132
|
-
# @param [When::TM::TemporalPosition] first 始点
|
133
|
-
# @param [Symbol] direction
|
134
|
-
# [ :forward - 昇順 ]
|
135
|
-
# [ :reverse - 降順 ]
|
136
|
-
# @param [String] event イベント名
|
137
|
-
# @param [Integer] count_limit 繰り返し回数(デフォルトは指定なし)
|
138
|
-
#
|
139
|
-
# @return [When::CalendarTypes::ShireWeek::Enumerator]
|
140
|
-
#
|
141
|
-
def enum_for(first, direction=:forward, event=nil, count_limit=nil)
|
142
|
-
Enumerator.new(self, first, direction, event||@event, count_limit)
|
143
|
-
end
|
144
|
-
alias :to_enum :enum_for
|
126
|
+
alias :week :sunday
|
145
127
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
128
|
+
# オブジェクトの正規化
|
129
|
+
# @private
|
130
|
+
def _normalize(args=[], options={})
|
131
|
+
@event ||= 'sunday'
|
132
|
+
super
|
133
|
+
end
|
134
|
+
|
135
|
+
#
|
136
|
+
# イベントを取得する Enumerator
|
137
|
+
#
|
138
|
+
class Enumerator < When::CalendarNote::Enumerator
|
152
139
|
|
153
140
|
#
|
154
|
-
#
|
141
|
+
# 次のイベントを得る
|
155
142
|
#
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
if @current
|
166
|
-
@first = event_eval(@first) if @delta.sign < 0
|
167
|
-
@current = @first
|
168
|
-
else
|
169
|
-
@current = event_eval(@current + @delta)
|
170
|
-
@current = event_eval(@current + @delta * 2) if @current.to_i == value.to_i
|
171
|
-
end
|
172
|
-
return value
|
143
|
+
# @return [When::TM::TemporalPosition]
|
144
|
+
#
|
145
|
+
def succ
|
146
|
+
value = @current
|
147
|
+
if @current==:first
|
148
|
+
@first = event_eval(@first) if @delta.sign < 0
|
149
|
+
@current = @first
|
150
|
+
else
|
151
|
+
@current = event_eval(@current + @delta)
|
152
|
+
@current = event_eval(@current + @delta * 2) if @current.to_i == value.to_i
|
173
153
|
end
|
154
|
+
return value
|
174
155
|
end
|
175
156
|
end
|
157
|
+
end
|
176
158
|
|
159
|
+
module CalendarTypes
|
177
160
|
#
|
178
161
|
# World calendar based on Gregorian calendar
|
179
162
|
#
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
=begin
|
3
|
-
Copyright (C) 2011-
|
3
|
+
Copyright (C) 2011-2014 Takashi SUGA
|
4
4
|
|
5
5
|
You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
|
6
6
|
=end
|
@@ -91,6 +91,14 @@ module When::TimeStandard
|
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
|
+
# 設定情報を取得する
|
95
|
+
#
|
96
|
+
# @return [Hash] 設定情報
|
97
|
+
#
|
98
|
+
def _setup_info
|
99
|
+
{:leap_seconds => _leap_seconds}
|
100
|
+
end
|
101
|
+
|
94
102
|
# @private
|
95
103
|
# 閏秒の挿入記録を取得する
|
96
104
|
def _leap_seconds
|
@@ -310,6 +318,9 @@ module When::TimeStandard
|
|
310
318
|
# @private
|
311
319
|
module TimeBasis
|
312
320
|
|
321
|
+
# @private
|
322
|
+
attr_reader :_time_basis
|
323
|
+
|
313
324
|
module FixedTimeBasis
|
314
325
|
|
315
326
|
private
|
data/lib/when_exe/tmposition.rb
CHANGED
@@ -172,7 +172,7 @@ module When::TM
|
|
172
172
|
#
|
173
173
|
# 対応する When::TM::JulianDate を生成
|
174
174
|
#
|
175
|
-
# @param [Hash] options
|
175
|
+
# @param [Hash] options 以下の通り
|
176
176
|
# @option options [When::TM::Clock] :clock
|
177
177
|
# @option options [When::Parts::Timezone] :tz
|
178
178
|
#
|
@@ -271,7 +271,7 @@ module When::TM
|
|
271
271
|
# @param [String] specification When.exe Standard Representation
|
272
272
|
# @param [Hash] options 下記の通り
|
273
273
|
# @option options [When::TM::ReferenceSystem] :frame 暦法の指定
|
274
|
-
# @option options [When::
|
274
|
+
# @option options [When::Parts::Timezone::Base, String] :clock 時法の指定
|
275
275
|
# @option options [String] :tz 時法の指定(時間帯を指定する場合 :clock の替わりに用いることができる)
|
276
276
|
# @option options [Array<Numeric>] :abbr ISO8601上位省略形式のためのデフォルト日付(省略時 指定なし)
|
277
277
|
# @option options [Integer] :extra_year_digits ISO8601拡大表記のための年の構成要素拡大桁数(省略時 1桁)
|
@@ -296,7 +296,7 @@ module When::TM
|
|
296
296
|
# @note options の中身は本メソッドによって更新されることがある。
|
297
297
|
#
|
298
298
|
# @note :tz は 'Asia/Tokyo'など時間帯を表す文字列をキーにして、登録済みのWhen::V::Timezone, When::Parts::Timezoneを検索して使用する。
|
299
|
-
# :clock はWhen::
|
299
|
+
# :clock はWhen::Parts::Timezone::Baseオブジェクトをそのまま使用するか '+09:00'などの文字列をWhen::TM::Clock化して使用する。
|
300
300
|
# :tz の方が :clock よりも優先される。
|
301
301
|
#
|
302
302
|
# @return [When::TM::TemporalPosition] ISO8601 time point
|
@@ -630,15 +630,17 @@ module When::TM
|
|
630
630
|
# @param [Hash] option 時間の歩度が1.0でない場合のための option
|
631
631
|
# see {When::TM::TemporalPosition._instance}
|
632
632
|
#
|
633
|
+
# @param [Integer] start ::DateTime オブジェクトのグレゴリオ改暦日(ユリウス通日)
|
634
|
+
#
|
633
635
|
# @return [::DateTime]
|
634
636
|
#
|
635
|
-
def to_date_time(option={:frame=>When.utc})
|
637
|
+
def to_date_time(option={:frame=>When.utc}, start=_default_start)
|
636
638
|
return JulianDate.dynamical_time(dynamical_time, option).to_date_time unless time_standard.rate_of_clock == 1.0
|
637
639
|
raise TypeError, "Clock not assigned" unless clock
|
638
640
|
Rational
|
639
641
|
offset = Rational(-(clock.universal_time/Duration::SECOND).to_i, (Duration::DAY/Duration::SECOND).to_i)
|
640
642
|
clk_time = clock.to_clk_time(universal_time - (to_i - JulianDate::JD19700101)*Duration::DAY).clk_time
|
641
|
-
::DateTime.jd(to_i, clk_time[1], clk_time[2], clk_time[3].to_i, offset,
|
643
|
+
::DateTime.jd(to_i, clk_time[1], clk_time[2], clk_time[3].to_i, offset, start)
|
642
644
|
end
|
643
645
|
|
644
646
|
# 標準ライブラリの Date オブジェクトへの変換
|
@@ -646,11 +648,13 @@ module When::TM
|
|
646
648
|
# @param [Hash] option 時間の歩度が1.0でない場合のための option
|
647
649
|
# see {When::TM::TemporalPosition._instance}
|
648
650
|
#
|
651
|
+
# @param [Integer] start ::DateTime オブジェクトのグレゴリオ改暦日(ユリウス通日)
|
652
|
+
#
|
649
653
|
# @return [::Date]
|
650
654
|
#
|
651
|
-
def to_date(option={})
|
655
|
+
def to_date(option={}, start=_default_start)
|
652
656
|
return JulianDate.dynamical_time(dynamical_time, option).to_date unless time_standard.rate_of_clock == 1.0
|
653
|
-
::Date.jd(to_i,
|
657
|
+
::Date.jd(to_i, start)
|
654
658
|
end
|
655
659
|
|
656
660
|
# 組み込みライブラリの Time オブジェクトへの変換
|
@@ -1007,6 +1011,12 @@ module When::TM
|
|
1007
1011
|
end
|
1008
1012
|
end
|
1009
1013
|
|
1014
|
+
#
|
1015
|
+
# 対応する ::Date の start 属性
|
1016
|
+
def _default_start
|
1017
|
+
frame ? frame._default_start : ::Date::GREGORIAN
|
1018
|
+
end
|
1019
|
+
|
1010
1020
|
alias :_method_missing :method_missing
|
1011
1021
|
|
1012
1022
|
# その他のメソッド
|
@@ -1568,10 +1578,14 @@ module When::TM
|
|
1568
1578
|
#
|
1569
1579
|
def %(other)
|
1570
1580
|
raise TypeError,"The right operand should be When::Coordinates::Residue" unless other.kind_of?(Residue)
|
1571
|
-
|
1572
|
-
|
1573
|
-
|
1574
|
-
|
1581
|
+
if precision <= When::YEAR && other.units['year'] && other.event != 'year'
|
1582
|
+
other.to('year') % (most_significant_coordinate + @frame._diff_to_CE)
|
1583
|
+
else
|
1584
|
+
case other.event
|
1585
|
+
when 'day' ; other % least_significant_coordinate
|
1586
|
+
when 'year' ; other % (most_significant_coordinate + @frame._diff_to_CE)
|
1587
|
+
else ; raise ArgumentError,"The right operand should have a unit 'day' or 'year'"
|
1588
|
+
end
|
1575
1589
|
end
|
1576
1590
|
end
|
1577
1591
|
|
@@ -1887,7 +1901,7 @@ module When::TM
|
|
1887
1901
|
count = digit - length
|
1888
1902
|
period = PeriodDuration.new((count<=0) ? 1 : 0.1**count, digit, (-@frame.indices.length)..length)
|
1889
1903
|
result = floor(digit, precision) + period
|
1890
|
-
result += clock.
|
1904
|
+
result += clock.tz_difference if (result.universal_time <= self.universal_time)
|
1891
1905
|
return result
|
1892
1906
|
end
|
1893
1907
|
|
@@ -1969,8 +1983,8 @@ module When::TM
|
|
1969
1983
|
clock ||= options[:time].frame if options[:time].kind_of?(ClockTime)
|
1970
1984
|
clock ||= Clock.local_time
|
1971
1985
|
end
|
1972
|
-
clock = When.Clock(clock) if
|
1973
|
-
clock_is_timezone = clock.
|
1986
|
+
clock = When.Clock(clock) if clock.kind_of?(String)
|
1987
|
+
clock_is_timezone = clock && !clock.kind_of?(When::TM::Clock)
|
1974
1988
|
clock = clock.daylight if clock_is_timezone
|
1975
1989
|
|
1976
1990
|
# ClockTime
|
data/lib/when_exe/tmreference.rb
CHANGED
@@ -302,6 +302,7 @@ module When::TM
|
|
302
302
|
class Clock < ReferenceSystem
|
303
303
|
|
304
304
|
include When::Coordinates
|
305
|
+
include When::Parts::Timezone::Base
|
305
306
|
include Spatial::Normalize
|
306
307
|
include Temporal
|
307
308
|
|
@@ -310,7 +311,7 @@ module When::TM
|
|
310
311
|
|
311
312
|
# When::TM::Clock Class のグローバルな設定を行う
|
312
313
|
#
|
313
|
-
# @param [When::
|
314
|
+
# @param [When::Parts::Timezone::Base, String] local 地方時を使用する場合、指定する
|
314
315
|
#
|
315
316
|
# @return [void]
|
316
317
|
#
|
@@ -324,11 +325,19 @@ module When::TM
|
|
324
325
|
@local_time = local
|
325
326
|
end
|
326
327
|
|
328
|
+
# 設定情報を取得する
|
329
|
+
#
|
330
|
+
# @return [Hash] 設定情報
|
331
|
+
#
|
332
|
+
def _setup_info
|
333
|
+
{:local => _local_time}
|
334
|
+
end
|
335
|
+
|
327
336
|
# 地方時
|
328
337
|
#
|
329
|
-
# @param [When::
|
338
|
+
# @param [When::Parts::Timezone::Base, String] local 地方時
|
330
339
|
#
|
331
|
-
# @return [When::
|
340
|
+
# @return [When::Parts::Timezone::Base, String]
|
332
341
|
#
|
333
342
|
# @note
|
334
343
|
# @local_timeは、原則、ライブラリ立ち上げ時に _setup_ で初期化する。
|
@@ -344,7 +353,7 @@ module When::TM
|
|
344
353
|
|
345
354
|
# When::TM::Clock のローカルタイムを読みだす
|
346
355
|
#
|
347
|
-
# @return [When::
|
356
|
+
# @return [When::Parts::Timezone::Base]
|
348
357
|
#
|
349
358
|
def local_time
|
350
359
|
_local_time[1]
|
@@ -593,32 +602,51 @@ module When::TM
|
|
593
602
|
return time
|
594
603
|
end
|
595
604
|
|
596
|
-
# When::TM::TemporalPosition の時間帯を変更して複製する
|
597
605
|
#
|
598
|
-
#
|
599
|
-
# @param [Hash] options see {When::TM::TemporalPosition._instance}
|
606
|
+
# _m17n_form のための要素生成
|
600
607
|
#
|
601
|
-
# @
|
608
|
+
# @param [Hash] options 下記のとおり
|
609
|
+
# @option options [Symbol] :method :to_m17n なら時間帯名を返す、その他は When::Parts::Resource#to_h 参照
|
602
610
|
#
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
611
|
+
# @private
|
612
|
+
def _to_hash_value(options={})
|
613
|
+
options[:method] == :to_m17n ? tzname(:hash)[0] : super
|
614
|
+
end
|
615
|
+
|
616
|
+
# この時法のUTCとの差(ISO 8601 basic format)
|
617
|
+
#
|
618
|
+
# @return [String] (±hhmm)
|
619
|
+
#
|
620
|
+
def to_basic
|
621
|
+
return '' unless @zone
|
622
|
+
@zone.gsub(/:/, '')
|
623
|
+
end
|
624
|
+
|
625
|
+
# 期間オブジェクトの桁数合わせ
|
626
|
+
# @private
|
627
|
+
def _arrange_length(period)
|
628
|
+
return period unless period.kind_of?(Array)
|
629
|
+
diff = @indices.length - period.length + 1
|
630
|
+
return period if (diff == 0)
|
631
|
+
return (diff > 0) ? period + Array.new(diff, 0) : period[0...diff]
|
632
|
+
end
|
633
|
+
|
634
|
+
# 時刻配列の分解能
|
635
|
+
# @private
|
636
|
+
def _precision(time, default=nil)
|
637
|
+
nil_index = time.index(nil) || time.length
|
638
|
+
precision = nil_index - 1 if (nil_index < @base.length || time[-1].kind_of?(Integer))
|
639
|
+
When::Coordinates::Index.precision(default || precision)
|
640
|
+
end
|
641
|
+
|
642
|
+
# 丸め量 / When::TM::Duration::SYSTEM
|
643
|
+
# @private
|
644
|
+
def _round_value(precision)
|
645
|
+
offset = When::TM::Duration::DAY / 2
|
646
|
+
precision.times do |i|
|
647
|
+
offset /= @unit[i+1] ? @unit[i+1] : 10
|
621
648
|
end
|
649
|
+
offset
|
622
650
|
end
|
623
651
|
|
624
652
|
# この時法の時間帯名
|
@@ -647,84 +675,43 @@ module When::TM
|
|
647
675
|
name
|
648
676
|
end
|
649
677
|
|
650
|
-
#
|
651
|
-
#
|
652
|
-
|
653
|
-
|
654
|
-
def _to_hash_value(options={})
|
655
|
-
tzname(:hash)[0]
|
678
|
+
# 標準時間帯の時計
|
679
|
+
# @return [When::TM::Clock]
|
680
|
+
def standard
|
681
|
+
_tz_prop ? _tz_prop.standard : self
|
656
682
|
end
|
657
683
|
|
658
|
-
#
|
659
|
-
#
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
684
|
+
# 夏時間帯の時計
|
685
|
+
# @return [When::TM::Clock]
|
686
|
+
def daylight
|
687
|
+
_tz_prop ? _tz_prop.daylight : self
|
688
|
+
end
|
689
|
+
|
690
|
+
# 夏時間帯と標準時間帯の時間差
|
691
|
+
# @return [When::TM:IntervalLength]
|
692
|
+
def tz_difference
|
693
|
+
_tz_prop ? _tz_prop.tz_difference : 0
|
665
694
|
end
|
666
695
|
|
667
696
|
# 夏時間の有無
|
668
697
|
# @private
|
669
698
|
def _need_validate
|
670
|
-
|
671
|
-
when nil ; false
|
672
|
-
when When::V::TimezoneProperty ; @tz_prop._pool['..']._need_validate
|
673
|
-
else ; @tz_prop._need_validate
|
674
|
-
end
|
699
|
+
_tz_prop ? _tz_prop._need_validate : false
|
675
700
|
end
|
676
701
|
|
677
702
|
# 夏時間
|
678
703
|
# @private
|
679
704
|
def _daylight(time)
|
680
|
-
|
681
|
-
when nil ; return self
|
682
|
-
when When::V::TimezoneProperty ; timezone = @tz_prop._pool['..']
|
683
|
-
else ; timezone = @tz_prop
|
684
|
-
end
|
685
|
-
return self unless timezone
|
686
|
-
return timezone._daylight(time)
|
687
|
-
end
|
688
|
-
|
689
|
-
# この時法の夏時間-標準時間変化量
|
690
|
-
# @private
|
691
|
-
def _tz_difference
|
692
|
-
case @tz_prop
|
693
|
-
when nil ; 0
|
694
|
-
when When::V::TimezoneProperty ; @tz_prop._pool['..'].difference
|
695
|
-
else ; @tz_prop.difference
|
696
|
-
end
|
697
|
-
end
|
698
|
-
|
699
|
-
# 期間オブジェクトの桁数合わせ
|
700
|
-
# @private
|
701
|
-
def _arrange_length(period)
|
702
|
-
return period unless period.kind_of?(Array)
|
703
|
-
diff = @indices.length - period.length + 1
|
704
|
-
return period if (diff == 0)
|
705
|
-
return (diff > 0) ? period + Array.new(diff, 0) : period[0...diff]
|
705
|
+
_tz_prop ? _tz_prop._daylight(time) : self
|
706
706
|
end
|
707
707
|
|
708
|
-
|
709
|
-
# @private
|
710
|
-
def _precision(time, default=nil)
|
711
|
-
nil_index = time.index(nil) || time.length
|
712
|
-
precision = nil_index - 1 if (nil_index < @base.length || time[-1].kind_of?(Integer))
|
713
|
-
When::Coordinates::Index.precision(default || precision)
|
714
|
-
end
|
708
|
+
private
|
715
709
|
|
716
|
-
#
|
717
|
-
|
718
|
-
|
719
|
-
offset = When::TM::Duration::DAY / 2
|
720
|
-
precision.times do |i|
|
721
|
-
offset /= @unit[i+1] ? @unit[i+1] : 10
|
722
|
-
end
|
723
|
-
offset
|
710
|
+
# Timezone オブジェクト
|
711
|
+
def _tz_prop
|
712
|
+
@tz_prop.kind_of?(When::V::TimezoneProperty) ? @tz_prop._pool['..'] : @tz_prop
|
724
713
|
end
|
725
714
|
|
726
|
-
private
|
727
|
-
|
728
715
|
# オブジェクトの正規化
|
729
716
|
def _normalize(args=[], options={})
|
730
717
|
@indices ||= DefaultTimeIndices
|
@@ -971,13 +958,21 @@ module When::TM
|
|
971
958
|
@order = order || DefaultEpochs
|
972
959
|
end
|
973
960
|
|
961
|
+
# 設定情報を取得する
|
962
|
+
#
|
963
|
+
# @return [Hash] 設定情報
|
964
|
+
#
|
965
|
+
def _setup_info
|
966
|
+
{:order => @order || _setup_}
|
967
|
+
end
|
968
|
+
|
974
969
|
# When::TM::CalendarEra オブジェクトを検索し取得する
|
975
970
|
#
|
976
971
|
# @overload _instance(key, epoch=nil, reverse=nil, options={})
|
977
972
|
# @param [String, Regexp] key 検索する暦年代または、暦年代にマッチする正規表現
|
978
973
|
# @param [Integer] epoch 年数を昇順にカウントする方式での暦元(0年)の通年(デフォルトは nil - 指定なし)
|
979
974
|
# @param [Integer] reverse 年数を降順にカウントする方式での暦元(0年)の通年(デフォルトは nil - 指定なし)
|
980
|
-
# @param [Hash] options
|
975
|
+
# @param [Hash] options 以下の通り
|
981
976
|
# @option options [String] :area 暦年代の使用地域の指定(デフォルトは nil - 指定なし)
|
982
977
|
# @option options [String] :period 暦年代の使用時代の指定(デフォルトは nil - 指定なし)
|
983
978
|
# @option options [Integer] :count 何件ヒットするまで検索するかを指定(デフォルトは 1件)
|
@@ -1009,7 +1004,15 @@ module When::TM
|
|
1009
1004
|
_compact(pool, parents)
|
1010
1005
|
return pool unless pool.size < count
|
1011
1006
|
|
1012
|
-
|
1007
|
+
order = @order
|
1008
|
+
if /\?.+?=/ =~ parents[-1]
|
1009
|
+
begin
|
1010
|
+
head = When.CalendarEra(parents[-1])
|
1011
|
+
order = order.dup.unshift(head)
|
1012
|
+
rescue
|
1013
|
+
end
|
1014
|
+
end
|
1015
|
+
order.each do |iri|
|
1013
1016
|
When.CalendarEra(iri)
|
1014
1017
|
pool = _candidates(options, area, period, key, epoch, false) +
|
1015
1018
|
_candidates(options, area, period, key, reverse, true)
|
@@ -1295,7 +1298,7 @@ module When::TM
|
|
1295
1298
|
next_ref = next_era.reference_date if next_era.respond_to?(:reference_date)
|
1296
1299
|
next_ref &&
|
1297
1300
|
next_ref.precision == YEAR &&
|
1298
|
-
next_ref.cal_date[YEAR-1] == 0 ? @epoch[-1].ceil(YEAR).to_i :
|
1301
|
+
next_ref.cal_date[YEAR-1] == 0 ? @epoch[-1].ceil(YEAR).to_i - 1 :
|
1299
1302
|
case type
|
1300
1303
|
when true ; @epoch[-1].to_i - 1
|
1301
1304
|
when :reference_date ; @reference_date.to_i
|
@@ -1430,7 +1433,7 @@ module When::TM
|
|
1430
1433
|
f.domain_of_validity = When::EX::Extent.new(
|
1431
1434
|
When::TM::Period.new(
|
1432
1435
|
When::TM::Instant.new(first),
|
1433
|
-
When::TM::Instant.new(last))) if first
|
1436
|
+
When::TM::Instant.new(last))) if first && first <= last
|
1434
1437
|
end
|
1435
1438
|
end
|
1436
1439
|
|
@@ -1466,7 +1469,7 @@ module When::TM
|
|
1466
1469
|
# other attributes
|
1467
1470
|
if (@child && @child.length>0)
|
1468
1471
|
_non_leaf_era(args, term_options)
|
1469
|
-
|
1472
|
+
_register_calendar_era unless _pool['..'].kind_of?(CalendarEra)
|
1470
1473
|
@child.each do |era|
|
1471
1474
|
era._register_calendar_era
|
1472
1475
|
end
|
@@ -1477,7 +1480,7 @@ module When::TM
|
|
1477
1480
|
end
|
1478
1481
|
|
1479
1482
|
def _non_leaf_era(args, term_options)
|
1480
|
-
@label = m17n(@label, nil, nil, term_options) if
|
1483
|
+
@label = m17n(@label, nil, nil, term_options) if @label.instance_of?(String)
|
1481
1484
|
if @label
|
1482
1485
|
@label._pool['..'] = self # TODO ここを ||= にすると leaf? の判定がおかしくなる
|
1483
1486
|
@_pool[@label.to_s] = @label
|