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.
@@ -0,0 +1,37 @@
1
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ Copyright (C) 2014 Takashi SUGA
4
+
5
+ You may use and/or modify this file according to the license
6
+ described in the LICENSE.txt file included in this archive.
7
+ =end
8
+
9
+ Encoding.default_external = 'UTF-8'
10
+ Encoding.default_internal = 'UTF-8'
11
+
12
+ #require 'linkeddata' # gem install linkeddata
13
+ require 'json/ld' # gem install json-ld
14
+ require 'rdf/turtle' # gem install rdf-turtle
15
+ require 'when_exe'
16
+ include When
17
+
18
+ config = JSON.parse(File.read(ARGV[0] || 'make_ttl.rb.config'))
19
+
20
+ PREFIXES = Parts::Resource.namespace_prefixes(*config['resource'])
21
+ CONTEXT = Parts::Resource.prefixs_to_context(PREFIXES)
22
+
23
+ File.open(config['file'], 'w') do |file|
24
+ CONTEXT.each_pair do |key, value|
25
+ file.puts "@prefix #{key}: <#{value}> ."
26
+ end
27
+ (when?(config['begin'])..when?(config['end'])).each do |date|
28
+ graph = RDF::Graph.new <<
29
+ JSON::LD::API.toRdf(date.rdf_graph(
30
+ {'@context'=>CONTEXT, :prefixes=>PREFIXES, :included=>true, :include=>true}))
31
+ graph.dump(:ttl, :prefixes=>CONTEXT).each_line do |line|
32
+ file.puts line unless line =~ /^@/
33
+ end
34
+ STDERR.puts '%4d - %s' % [date[YEAR], Time.now.to_s[/\d+:\d+:\d+/]]
35
+ end
36
+ end
37
+
@@ -0,0 +1,9 @@
1
+ {"begin" : "595^^Japanese",
2
+ "end" : "1872^^Japanese",
3
+ "file" : "japanese.ttl",
4
+ "resource" : [
5
+ "_co:Common",
6
+ "_co:Common?V=0618",
7
+ "_m:Calendar",
8
+ "_m:Japanese",
9
+ "_n:Japanese/Notes"]}
@@ -1,925 +1,923 @@
1
- # -*- coding: utf-8 -*-
2
- =begin
3
- Copyright (C) 2011-2014 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
- begin
9
- require 'json'
10
- rescue LoadError
11
- end
12
- begin
13
- require 'rubygems'
14
- rescue LoadError
15
- end
16
- begin
17
- gem 'tzinfo'
18
- autoload :TZInfo, 'tzinfo'
19
- rescue LoadError, NoMethodError
20
- end
21
- begin
22
- gem 'gcalapi'
23
- autoload :GoogleCalendar, 'when_exe/googlecalendar'
24
- rescue LoadError, NoMethodError
25
- end
26
-
27
- autoload :URI, 'uri'
28
- autoload :OpenURI, 'open-uri'
29
- autoload :OpenSSL, 'openssl'
30
- autoload :FileUtils, 'fileutils'
31
- autoload :REXML, 'rexml/document'
32
- autoload :Mutex, 'thread' unless Object.const_defined?(:Mutex)
33
-
34
- $:.unshift(File.dirname(__FILE__)) unless
35
- $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
36
-
37
- #
38
- # A multicultural and multilingualized calendar library based on ISO 8601, ISO 19108 and RFC 5545
39
- #
40
- module When
41
-
42
- class << self
43
-
44
- #
45
- # マルチスレッド対応の場合 true
46
- #
47
- # @return [Boolean]
48
- #
49
- attr_reader :multi_thread
50
-
51
- #
52
- # Logger オブジェクト
53
- #
54
- # @return [Logger]
55
- #
56
- attr_accessor :logger
57
- private :logger=
58
-
59
- # Initializations
60
- #
61
- # @param [Hash] options 以下の通り
62
- # @option options [When::Parts::Timezone::Base] :local デフォルトの地方時
63
- # @option options [When::Coordinates::Spatial] :location デフォルトの空間位置
64
- # @option options [When::TM::IntervalLength] :until V::Event::Enumerator until
65
- # @option options [Hash{String=>String}] :alias Locale の読替パターン ({ 読替前のlocale=>読替後のlocale })
66
- # @option options [String] :namespace_format 名前空間定義の省略時に名前空間生成に用いる書式
67
- # @option options [Hash{String=>String}] :unification 漢字の包摂パターン ({ 包摂前の文字列=>包摂後の文字列 })
68
- # @option options [Array<String>] :order CalendarEra の検索順序 ([ IRI of When::TM::CalendarEra ])
69
- # @option options [Hash{String=>Array, String}] :format strftime で用いる記号の定義 ({ 記号=>[ 書式,項目名 ] or 記号列 })
70
- # @option options [Array<Array>] :leap_seconds 閏秒の挿入記録 ([ [JD, TAI-UTC, (MJD, OFFSET)] ])
71
- # @option options [String] :base_uri Base URI for When_exe Resources (Default When::SourceURI)
72
- # @option options [Hash<String=>String>] :additional_namespaces User defined namespaces (Default {})
73
- # @option options [String] :root_dir Root Directory for When_exe Resources Cash data (Default When::RootDir)
74
- # @option options [Boolean] :direct '_' で終わるメソッドをキャッシュせずに毎回計算するか否か
75
- # @option options [Hash{Symbol=>boolean}] :escape 毎回 method_missing を発生させるメソッドを true にする
76
- # @option options [false, nil] :escape to_str, to_ary, to_hash のみ毎回 method_missing を発生させる
77
- # @option options [true] :escape すべて毎回 method_missing を発生させる
78
- # @option options [Boolean] :multi_thread マルチスレッド対応 (true: 対応, false/nil: 非対応)
79
- # @option options [Logger] :logger Logger オブジェクト
80
- #
81
- # @return [void]
82
- #
83
- # @note
84
- # 本メソッドでマルチスレッド対応の管理変数の初期化を行っている。
85
- # このため、本メソッド自体および本メソッドから呼んでいる各クラスの _setup_ メソッドはスレッドセーフでない。
86
- #
87
- def _setup_(options={})
88
- @multi_thread = options[:multi_thread]
89
- @logger = options[:logger]
90
- Parts::MethodCash._setup_(options)
91
- Parts::Resource._setup_(options)
92
- Locale._setup_(options)
93
- Coordinates::Spatial._setup_(options[:location])
94
- TM::CalendarEra._setup_(options[:order])
95
- TM::Calendar._setup_
96
- TM::Clock._setup_(options[:local])
97
- TM::TemporalPosition._setup_(options[:format])
98
- V::Event._setup_(options[:until])
99
- V::Timezone._setup_
100
- Parts::Timezone._setup_
101
- TimeStandard._setup_(options[:leap_seconds])
102
- end
103
-
104
- # 設定情報を取得する
105
- #
106
- # @return [Hash] 設定情報
107
- #
108
- def _setup_info
109
- {:multi_thread => @multi_thread}.
110
- update(Parts::MethodCash._setup_info).
111
- update(Parts::Resource._setup_info).
112
- update(Locale._setup_info).
113
- update(Coordinates::Spatial._setup_info).
114
- update(TM::CalendarEra._setup_info).
115
- update(TM::Clock._setup_info).
116
- update(TM::TemporalPosition._setup_info).
117
- update(V::Event._setup_info).
118
- update(TimeStandard._setup_info)
119
- end
120
-
121
- #
122
- # When 直下に定数として定義する時法・暦法(明示的的追加)
123
- #
124
- # @private
125
- def _define_common_calendar_types(list=%w(UTC Gregorian Julian Civil))
126
- list.each do |calendar|
127
- resource = Parts::Resource._instance(calendar, '_c:')
128
- Parts::Resource.synchronize do
129
- Parts::Resource::ConstList << calendar
130
- const_set(calendar, resource)
131
- end
132
- end
133
- end
134
-
135
- alias :_const_missing :const_missing
136
-
137
- #
138
- # When 直下に定数として定義する時法・暦法など(暗黙的追加)
139
- #
140
- def const_missing(constant)
141
- sgn, *args = TM::PeriodDuration._to_array(constant.to_s)
142
- return const_set(constant, TM::PeriodDuration.new(*args)) if sgn
143
- iri = Parts::Resource._abbreviation_to_iri(constant)
144
- return _const_missing(constant) unless iri
145
- resource = Parts::Resource._instance(iri)
146
- return const_get(constant) if const_defined?(constant)
147
- Parts::Resource.synchronize do
148
- Parts::Resource::ConstList << constant
149
- const_set(constant, resource)
150
- end
151
- end
152
- end
153
-
154
- #
155
- # when_exe 用 International Resource Identifier
156
- #
157
- SourceURI = "http://hosi.org/When/"
158
-
159
- #
160
- # ライブラリのあるディレクトリ
161
- #
162
- RootDir = File.dirname(__FILE__).sub(/\/[^\/]*\z/,'')
163
-
164
- require 'when_exe/version'
165
- require 'when_exe/locales/locale'
166
- require 'when_exe/locales/autoload'
167
- require 'when_exe/parts/enumerator'
168
- require 'when_exe/parts/resource'
169
- require 'when_exe/parts/geometric_complex'
170
- require 'when_exe/parts/timezone'
171
- require 'when_exe/core/compatibility'
172
- require 'when_exe/basictypes'
173
- require 'when_exe/ephemeris'
174
- require 'when_exe/coordinates'
175
- require 'when_exe/icalendar'
176
- require 'when_exe/tmobjects'
177
- require 'when_exe/timestandard'
178
- require 'when_exe/tmposition'
179
- require 'when_exe/tmreference'
180
- require 'when_exe/calendartypes'
181
- require 'when_exe/calendarnote'
182
- require 'when_exe/region/m17n'
183
- require 'when_exe/region/residue'
184
- require 'when_exe/inspect'
185
-
186
- #
187
- # Module Constants
188
- #
189
-
190
- # 1 second period duration
191
- PT1S = TM::PeriodDuration.new(nil,[0,0,0,1])
192
-
193
- # 1 minute period duration
194
- PT1M = TM::PeriodDuration.new(nil,[0,0,1,0])
195
-
196
- # 1 hour period duration
197
- PT1H = TM::PeriodDuration.new(nil,[0,1,0,0])
198
-
199
- # 1 day period duration
200
- P1D = TM::PeriodDuration.new([0,0,1])
201
-
202
- # 1 week period duration
203
- P1W = TM::PeriodDuration.new([0,0,7])
204
-
205
- # 1 month period duration
206
- P1M = TM::PeriodDuration.new([0,1,0])
207
-
208
- # 1 year period duration
209
- P1Y = TM::PeriodDuration.new([1,0,0])
210
-
211
- # kind of When::TM::Position or When::TM::TemporalPosition
212
- TimeValue = TM::IndeterminateValue
213
-
214
- # 7 days week residue
215
- Week = When::Parts::Resource._instance('_co:Common::Week')
216
-
217
- # Gregorian months
218
- Month = When::Parts::Resource._instance('_m:Calendar::Month')
219
-
220
- # + ∞
221
- PlusInfinity = TM::TemporalPosition.new({:indeterminated_position=>TimeValue::Max})
222
-
223
- # - ∞
224
- MinusInfinity = TM::TemporalPosition.new({:indeterminated_position=>TimeValue::Min})
225
-
226
- # UTF-8 encoding
227
- UTF8 = '.UTF-8'
228
-
229
- # Windows-31J encoding
230
- W31J = '.Windows-31J'
231
-
232
- # eucJP encoding
233
- EUCJP = '.eucJP'
234
-
235
- class BasicTypes::M17n
236
- autoload :Japanese, 'when_exe/region/japanese'
237
- autoload :Chinese, 'when_exe/region/chinese'
238
- autoload :Yi, 'when_exe/region/chinese'
239
- autoload :Tibetan, 'when_exe/region/tibetan'
240
- autoload :Thai, 'when_exe/region/thai'
241
- autoload :Balinese, 'when_exe/region/balinese'
242
- autoload :Javanese, 'when_exe/region/javanese'
243
- autoload :Indian, 'when_exe/region/indian'
244
- autoload :Iranian, 'when_exe/region/iranian'
245
- autoload :Islamic, 'when_exe/region/islamic'
246
- autoload :Jewish, 'when_exe/region/jewish'
247
- autoload :AncientOrient, 'when_exe/region/babylonian'
248
- autoload :Armenian, 'when_exe/region/armenian'
249
- autoload :Roman, 'when_exe/region/roman'
250
- autoload :Coptic, 'when_exe/region/coptic'
251
- autoload :French, 'when_exe/region/french'
252
- autoload :World, 'when_exe/region/world'
253
- autoload :Positivist, 'when_exe/region/positivist'
254
- autoload :InternationalFixed, 'when_exe/region/international_fixed'
255
- autoload :WorldSeason, 'when_exe/region/world_season'
256
- autoload :Tranquility, 'when_exe/region/tranquility'
257
- autoload :Pax, 'when_exe/region/pax'
258
- autoload :HankeHenry, 'when_exe/region/hanke_henry'
259
- autoload :Shire, 'when_exe/region/shire'
260
- autoload :Dee, 'when_exe/region/dee'
261
- autoload :VanishingLeprechaun, 'when_exe/region/vanishing_leprechaun'
262
- autoload :Yerm, 'when_exe/region/yerm'
263
- autoload :Goddess, 'when_exe/region/goddess'
264
- autoload :Martian, 'when_exe/region/martian'
265
- autoload :WeekDate, 'when_exe/region/weekdate'
266
- end
267
-
268
- module Locale
269
- autoload :WikipediaLinks, 'when_exe/locales/links'
270
- autoload :IAST, 'when_exe/locales/iast'
271
- autoload :IASTR, 'when_exe/locales/iast'
272
- autoload :AKT, 'when_exe/locales/akt'
273
- end
274
-
275
- module CalendarTypes
276
- autoload :Japanese, 'when_exe/region/japanese/calendars'
277
- autoload :JapaneseTwin, 'when_exe/region/japanese/twins'
278
- autoload :ChineseTwin, 'when_exe/region/chinese/twins'
279
- autoload :ChineseSolar, 'when_exe/region/chinese'
280
- autoload :ChineseLuniSolar, 'when_exe/region/chinese'
281
- autoload :Yi, 'when_exe/region/chinese'
282
- autoload :TenrekiA, 'when_exe/region/chinese'
283
- autoload :TenrekiB, 'when_exe/region/chinese'
284
- autoload :Korean, 'when_exe/region/korean'
285
- autoload :Tibetan, 'when_exe/region/tibetan'
286
- autoload :Thai, 'when_exe/region/thai'
287
- autoload :ThaiP, 'when_exe/region/thai'
288
- autoload :ThaiC, 'when_exe/region/thai'
289
- autoload :ThaiT, 'when_exe/region/thai'
290
- autoload :Tenganan, 'when_exe/region/balinese'
291
- autoload :Pranatamangsa, 'when_exe/region/javanese'
292
- autoload :IndianNationalSolar, 'when_exe/region/indian'
293
- autoload :Nanakshahi, 'when_exe/region/indian'
294
- autoload :RevisedBengali, 'when_exe/region/indian'
295
- autoload :HinduLuniSolar, 'when_exe/region/indian'
296
- autoload :HinduSolar, 'when_exe/region/indian'
297
- autoload :Jalali, 'when_exe/region/iranian'
298
- autoload :TableBasedJalali, 'when_exe/region/iranian'
299
- autoload :Borji, 'when_exe/region/iranian'
300
- autoload :TableBasedBorji, 'when_exe/region/iranian'
301
- autoload :SolarHijri, 'when_exe/region/iranian'
302
- autoload :SolarHijriAlgorithmic, 'when_exe/region/iranian'
303
- autoload :Zoroastrian, 'when_exe/region/zoroastrian'
304
- autoload :Qadimi, 'when_exe/region/zoroastrian'
305
- autoload :Shahanshahi, 'when_exe/region/zoroastrian'
306
- autoload :Fasli, 'when_exe/region/zoroastrian'
307
- autoload :Bahai, 'when_exe/region/bahai'
308
- autoload :TabularIslamic, 'when_exe/region/islamic'
309
- autoload :EphemerisBasedIslamic, 'when_exe/region/islamic'
310
- autoload :Jewish, 'when_exe/region/jewish'
311
- autoload :Hebrew, 'when_exe/region/jewish'
312
- autoload :Armenian, 'when_exe/region/armenian'
313
- autoload :Babylonian, 'when_exe/region/babylonian'
314
- autoload :BabylonianPD, 'when_exe/region/babylonian'
315
- autoload :Seleucid, 'when_exe/region/babylonian'
316
- autoload :SeleucidPD, 'when_exe/region/babylonian'
317
- autoload :Ptolemaic, 'when_exe/region/coptic'
318
- autoload :Coptic, 'when_exe/region/coptic'
319
- autoload :JulianA, 'when_exe/region/roman'
320
- autoload :JulianB, 'when_exe/region/roman'
321
- autoload :JulianC, 'when_exe/region/roman'
322
- autoload :Roman, 'when_exe/region/roman'
323
- autoload :Gregorian, 'when_exe/region/christian'
324
- autoload :FrenchRepublican, 'when_exe/region/french'
325
- autoload :World, 'when_exe/region/world'
326
- autoload :LongCount, 'when_exe/region/mayan'
327
- autoload :Positivist, 'when_exe/region/positivist'
328
- autoload :InternationalFixed, 'when_exe/region/international_fixed'
329
- autoload :WorldSeason, 'when_exe/region/world_season'
330
- autoload :Pax, 'when_exe/region/pax'
331
- autoload :Tranquility, 'when_exe/region/tranquility'
332
- autoload :HankeHenry, 'when_exe/region/hanke_henry'
333
- autoload :Discordian, 'when_exe/region/discordian'
334
- autoload :Shire, 'when_exe/region/shire'
335
- autoload :Sym454, 'when_exe/region/symmetry'
336
- autoload :Sym010, 'when_exe/region/symmetry'
337
- autoload :Dee, 'when_exe/region/dee'
338
- autoload :DeeCecil, 'when_exe/region/dee'
339
- autoload :VanishingLeprechaun, 'when_exe/region/vanishing_leprechaun'
340
- autoload :Yerm, 'when_exe/region/yerm'
341
- autoload :Goddess, 'when_exe/region/goddess'
342
- autoload :Darian, 'when_exe/region/martian'
343
- autoload :WeekDate, 'when_exe/region/weekdate'
344
-
345
- _time_systems = {
346
- 'LMT' => nil, # Local Mean Time
347
- 'LAT' => nil, # Local Apparent Time
348
- 'THS' => nil, # Temporal Hour System
349
- 'MTC' => 'when_exe/region/martian', # Martian Time, Coordinated
350
- }
351
- TimeSystems = _time_systems.keys.join('|')
352
- _time_systems.each_pair do |key, required|
353
- autoload key.to_sym, required if required
354
- end
355
- end
356
-
357
- class CalendarNote
358
- autoload :SolarTerms, 'when_exe/ephemeris/notes'
359
- autoload :LunarPhases, 'when_exe/ephemeris/notes'
360
- autoload :Ephemeris, 'when_exe/ephemeris/notes'
361
- autoload :Japanese, 'when_exe/region/japanese/notes'
362
- autoload :CommonWithRokuyo, 'when_exe/region/japanese/weeks'
363
- autoload :RokuyoWeek, 'when_exe/region/japanese/weeks'
364
- autoload :Yis, 'when_exe/region/chinese'
365
- autoload :Balinese, 'when_exe/region/balinese'
366
- autoload :Javanese, 'when_exe/region/javanese'
367
- autoload :Tibetan, 'when_exe/region/tibetan'
368
- autoload :Bahai, 'when_exe/region/bahai'
369
- autoload :Roman, 'when_exe/region/roman'
370
- autoload :Mayan, 'when_exe/region/mayan'
371
- autoload :DiscordianWeek, 'when_exe/region/discordian'
372
- autoload :CommonWithSovietFiveDay, 'when_exe/region/soviet'
373
- autoload :SovietFiveDayWeek, 'when_exe/region/soviet'
374
- autoload :CommonWithSovietSixDay, 'when_exe/region/soviet'
375
- autoload :SovietSixDayWeek, 'when_exe/region/soviet'
376
- # autoload :Yerm, 'when_exe/region/yerm'
377
- autoload :WorldWeek, 'when_exe/region/world'
378
- autoload :PositivistWeek, 'when_exe/region/positivist'
379
- autoload :InternationalFixedWeek, 'when_exe/region/international_fixed'
380
- autoload :TranquilityWeek, 'when_exe/region/tranquility'
381
- autoload :WorldSeasonWeek, 'when_exe/region/world_season'
382
- autoload :ShireWeek, 'when_exe/region/shire'
383
-
384
- Default = [['_m:Calendar::Month'], ['Common::Week']]
385
- JulianDay = [['Common::Week', 'Common::干支']]
386
- Chinese = [['Common::干支'], ['_m:Calendar::Month'], ['Common::Week', 'Common::干支']]
387
- end
388
-
389
- module Coordinates
390
- autoload :Tibetan, 'when_exe/region/tibetan'
391
- autoload :Yi, 'when_exe/region/chinese'
392
- autoload :Javanese, 'when_exe/region/javanese'
393
- autoload :Indian, 'when_exe/region/indian'
394
- autoload :Iranian, 'when_exe/region/iranian'
395
- autoload :Bahai, 'when_exe/region/bahai'
396
- autoload :Roman, 'when_exe/region/roman'
397
- autoload :Mayan, 'when_exe/region/mayan'
398
-
399
- # default index for day coordinate
400
- DefaultDayIndex = Index.new
401
-
402
- # default indices for date coordinates
403
- DefaultDateIndices = [
404
- Index.new(When::Parts::Resource._instance('_m:Calendar::Month'), {:unit =>12}),
405
- DefaultDayIndex
406
- ]
407
-
408
- # default indices for time coordinates
409
- DefaultTimeIndices = [
410
- Index.new({:base=>0, :unit=>24}),
411
- Index.new({:base=>0, :unit=>60}),
412
- Index.new({:base=>0, :unit=>60})
413
- ]
414
- end
415
-
416
- module TM
417
- class OrdinalReferenceSystem
418
- autoload :GeologicalAge, 'when_exe/region/geologicalage'
419
- end
420
-
421
- class CalendarEra
422
- autoload :Japanese, 'when_exe/region/japanese/epochs'
423
- autoload :JapanesePrimeMinister, 'when_exe/region/japanese/epochs'
424
- autoload :NihonKoki, 'when_exe/region/japanese/nihon_shoki'
425
- autoload :NihonShoki, 'when_exe/region/japanese/nihon_shoki'
426
- autoload :JapaneseSolar, 'when_exe/region/japanese/twins'
427
- autoload :JapaneseLuniSolar, 'when_exe/region/japanese/twins'
428
- autoload :Chinese, 'when_exe/region/chinese/epochs'
429
- autoload :ChineseSolar, 'when_exe/region/chinese/twins'
430
- autoload :ChineseLuniSolar, 'when_exe/region/chinese/twins'
431
- autoload :Ryukyu, 'when_exe/region/ryukyu'
432
- autoload :Korean, 'when_exe/region/korean'
433
- autoload :Vietnamese, 'when_exe/region/vietnamese'
434
- autoload :Manchurian, 'when_exe/region/east_asian'
435
- autoload :Rouran, 'when_exe/region/east_asian'
436
- autoload :Gaochang, 'when_exe/region/east_asian'
437
- autoload :Yunnan, 'when_exe/region/east_asian'
438
- autoload :WesternXia, 'when_exe/region/east_asian'
439
- autoload :KaraKhitan, 'when_exe/region/east_asian'
440
- # autoload :Tibetan, 'when_exe/region/tibetan'
441
- autoload :BalineseLuniSolar, 'when_exe/region/balinese'
442
- autoload :JavaneseLunar, 'when_exe/region/javanese'
443
- autoload :Iranian, 'when_exe/region/iranian'
444
- autoload :Hijra, 'when_exe/region/islamic'
445
- autoload :Jewish, 'when_exe/region/jewish'
446
- autoload :AncientOrient, 'when_exe/region/babylonian'
447
- autoload :Roman, 'when_exe/region/roman'
448
- autoload :Julian, 'when_exe/region/roman'
449
- autoload :Pope, 'when_exe/region/pope'
450
- autoload :Byzantine, 'when_exe/region/christian'
451
- autoload :LongCount, 'when_exe/region/mayan'
452
-
453
- # Defualt search path for Epochs and Eras
454
- DefaultEpochs = ['Common', 'ModernJapanese',
455
- 'Hijra', 'Jewish', 'Iranian',
456
- 'Roman', 'Byzantine', 'AncientOrient', 'LongCount',
457
- 'BalineseLuniSolar', 'JavaneseLunar',
458
- 'Japanese', 'NihonKoki', 'NihonShoki',
459
- 'Chinese', 'Ryukyu', 'Vietnamese', 'Korean',
460
- 'JapaneseLuniSolar', 'JapaneseSolar',
461
- 'ChineseLuniSolar', 'ChineseSolar',
462
- 'Manchurian', 'Rouran', 'Gaochang',
463
- 'Yunnan', 'WesternXia', 'KaraKhitan', # 'Tibetan',
464
- 'Pope', 'JapanesePrimeMinister']
465
-
466
- # Defualt events for Epochs and Eras
467
- DefaultEvents = Hash[*([['@A', 'Accession' ],
468
- ['@FE', 'FelicitousEvent' ],
469
- ['@ND', 'NaturalDisaster' ],
470
- ['@IY', 'InauspiciousYear'],
471
- ['@F', 'Foundation' ],
472
- ['@CR', 'CalendarReform' ],
473
- ['@CE', 'CalendarEpoch' ]].map {|e|
474
- [e[0], When::Parts::Resource._instance('EpochEvents::'+e[1], '_m:')]
475
- }.flatten)]
476
-
477
- # Common Era
478
- Common = [{}, self, [
479
- 'area:Common#{?Reform=Reform}',
480
- ['[BeforeCommonEra=en:BCE_(disambiguation),*alias:BCE]0.1.1'],
481
- ['[CommonEra=en:Common_Era,*alias:CE]1.1.1', '@CE', '01-01-01^Julian'],
482
- ['[CommonEra=en:Common_Era,*alias:CE]#{Reform:1582.10.15}', '@CR', '#{Reform:1582.10.15}^Gregorian']
483
- ]]
484
-
485
- # Modern Japanese Eras after the calendar reform to the Gregorian Calendar
486
- ModernJapanese = [self, [
487
- 'area:[ModernJapanese]',
488
- ['[M=,alias:明=ja:%%<明治>]6.01.01', '@CR', '1873-01-01^Gregorian?note=Default'],
489
- ['[T=,alias:大=ja:%%<大正>]1.07.30', '@A', '1912-07-30'],
490
- ['[S=,alias:昭=ja:%%<昭和>]1.12.25', '@A', '1926-12-25'],
491
- ['[H=,alias:平=ja:%%<平成>]1.01.08', '@A', '1989-01-08']
492
- ]]
493
- end
494
- end
495
-
496
- #
497
- # Module Functions
498
- #
499
- module_function
500
-
501
- # Generation of Temporal Objetct, duration or When::Parts::GeometricComplex
502
- #
503
- # @param [String] specification When.exe Standard Representation または ユリウス日JDN として解釈して生成する
504
- # @param [Numeric] specification ユリウス日として解釈して生成する
505
- # @param [Array] specification 要素を個別に解釈して生成したオブジェクトのArrayを返す
506
- # @param [When::TM::TemporalPosition, When::Parts::GeometricComplex] specification specificationをそのまま返す
507
- # @param [When::TM::TemporalPosition] specification specification.any_otherを返す
508
- #
509
- # @param [Hash] options 暦法や時法などの指定 (see {When::TM::TemporalPosition._instance})
510
- #
511
- # @return [When::TM::TemporalPosition, When::TM::Duration, When::Parts::GeometricComplex or Array<them>]
512
- #
513
- def when?(specification, options={})
514
-
515
- # フォーマットごとの処理
516
- case specification
517
- when TM::TemporalPosition, Parts::GeometricComplex ; specification
518
- when TM::Position ; specification.any_other
519
- when Array ; begin options = TM::TemporalPosition._options(options) ; specification.map {|e| when?(e, options)} end
520
- when /\Atoday\z/i ; today(options)
521
- when /\Anow\z/i ; now(options)
522
- when /(JDN|MJD|SDN|CEP)(\z|\^)/i; TM::JulianDate.parse(specification, options)
523
- when /[\n\r]+/ ; when?(specification.split(/[\n\r]+/), options)
524
- when String ; TM::TemporalPosition._instance(EncodingConversion.to_internal_encoding(specification), options)
525
- when Numeric ; TM::JulianDate.new(+specification, TM::TemporalPosition._options(options))
526
- else ; Calendar(options[:frame] || 'Gregorian').jul_trans(specification, options)
527
- end
528
- end
529
-
530
- # When::TM::TemporalPosition の生成
531
- #
532
- # @overload TemporalPosition(*args, options={})
533
- # @param [String or [String, Integer], Numeric, ...] args
534
- # [String] 年号
535
- # [Array<String, Integer>] 年号と 0 年の通年
536
- # [Numeric] 年月日時分秒(途中で打ち切り可)
537
- # @param [Hash] options 暦法や時法などの指定
538
- # @option options [Symbol] :invalid
539
- # [:raise 日時が存在しない場合例外発生 ]
540
- # [:check 日時が存在しない場合 nil を返す ]
541
- # [その他/nil 日時が存在することを確認しない(デフォルト)]
542
- # @see When::TM::TemporalPosition._instance
543
- #
544
- # @return [When::TM::TemporalPosition]
545
- # @raise [ArgumentError]
546
- # options[ :invalid ] が :raise で、日時が存在しない場合
547
- #
548
- def TemporalPosition(*args)
549
- TM::TemporalPosition._temporal_position(*args)
550
- end
551
-
552
- alias :tm_pos :TemporalPosition
553
- module_function :tm_pos
554
-
555
- # 指定日時に対応する When::TM::TemporalPosition の生成
556
- # (When::TM::DateAndTime of specified Time)
557
- #
558
- # @param [::Time] time 変換元の日時のTimeオブジェクト
559
- # @param [Float] time 1970-01-01T00:00:00Z からの経過秒数
560
- # @param [Hash] options 暦法や時法などの指定
561
- # @see When::TM::TemporalPosition._instance
562
- #
563
- # @return [When::TM::DateAndTime]
564
- #
565
- def at(time, options={})
566
- options = options._attr if options.kind_of?(TM::TemporalPosition)
567
- options[:frame] ||= 'Gregorian'
568
- options[:frame] = Resource(options[:frame], '_c:') if options[:frame].kind_of?(String)
569
- options[:clock] ||= Clock(time.utc_offset) if time.kind_of?(::Time)
570
- jdt = TM::JulianDate.universal_time(time.to_f * TM::IntervalLength::SECOND, {:frame=>TM::Clock.get_clock(options)})
571
- options[:clock] = jdt.frame
572
- date = options[:frame].jul_trans(jdt, options)
573
- date = TM::CalDate.new(date.cal_date, options) if options[:precision] &&
574
- options[:precision] <= DAY
575
- return date
576
- end
577
-
578
- # 現在日時に対応する When::TM::TemporalPosition の生成
579
- # (When::TM::DateAndTime of now)
580
- # @note メソッド実行時の「現在日時」である。@indeterminated_position は設定しないので自動的に日時が進むことはない
581
- #
582
- # @param [Hash] options 暦法や時法などの指定
583
- # @see When::TM::TemporalPosition._instance
584
- #
585
- # @return [When::TM::DateAndTime]
586
- #
587
- def now(options={})
588
- When.at(Time.now, options)
589
- end
590
-
591
- # 本日に対応する When::TM::CalDate の生成
592
- # (When::TM::CalDate of today)
593
- # @note メソッド実行時の「本日」である。@indeterminated_position は設定しないので自動的に日時が進むことはない
594
- # @note options で時間帯を指定しても「本日」の決定に使用するのみで、戻り値には反映されない
595
- #
596
- # @param [Hash] options 暦法や時法などの指定
597
- # @see When::TM::TemporalPosition._instance
598
- #
599
- # @return [When::TM::CalDate]
600
- #
601
- def today(options={})
602
- now(options.merge({:precision=>DAY}))
603
- end
604
-
605
- # When::TM::Duration の生成
606
- #
607
- # @param [String] period When.exe Standard Representation として解釈して生成する
608
- # @param [Numeric] period When::TM::IntervalLength::SYSTEM 単位の値として解釈して生成する
609
- # @param [Array] period 要素を個別に解釈して生成したオブジェクトのArrayを返す
610
- # @param [When::TM::Duration] period 処理を行わず、そのまま返す
611
- # @param [Hash] options 現時点では未使用
612
- #
613
- # @return [When::TM::Duration or Array<them>]
614
- #
615
- def Duration(period, options={})
616
- case period
617
- when Array
618
- period.map {|e| Duration(e, options)}
619
-
620
- when TM::Duration
621
- period
622
-
623
- when 0
624
- TM::IntervalLength.new(0, 'day')
625
-
626
- when Numeric
627
- [TM::Duration::YEAR, TM::Duration::MONTH, TM::Duration::WEEK, TM::Duration::DAY,
628
- TM::Duration::HOUR, TM::Duration::MINUTE, TM::Duration::SECOND].each do |unit|
629
- div, mod = period.divmod(unit)
630
- return TM::IntervalLength.new(div, TM::Duration::Unit.invert[unit]) if mod == 0
631
- end
632
- TM::IntervalLength.new(period, 'system')
633
-
634
- when String
635
- # IntervalLength
636
- args = TM::IntervalLength._to_array(period)
637
- return TM::IntervalLength.new(*args) if args
638
-
639
- # PeriodDuration
640
- sign, *args = TM::PeriodDuration._to_array(period)
641
- raise TypeError, "Argument 'period' is not a Duration" unless (sign)
642
- args << options
643
- duration = TM::PeriodDuration.new(*args)
644
- return (sign >= 0) ? duration : -duration
645
-
646
- else
647
- nil
648
- end
649
- end
650
-
651
- # When::TM::Calendar の生成/参照
652
- #
653
- # @param [String] calendar 暦法を表す文字列
654
- #
655
- # @return [When::TM::Calendar] calendar に対応する When::TM::Calendar オブジェクト
656
- #
657
- def Calendar(calendar)
658
- Parts::Resource._instance(calendar, '_c:')
659
- end
660
-
661
- # When::CalendarNote の生成/参照
662
- #
663
- # @param [String] note 暦注リストを表す文字列
664
- #
665
- # @return [When::CalendarNote] note に対応する When::CalendarNote オブジェクト
666
- #
667
- def CalendarNote(note)
668
- Parts::Resource._instance(note, '_n:')
669
- end
670
-
671
- # When::TM::CalendarEra の生成/参照
672
- #
673
- # @param [String] era 暦年代を表す文字列
674
- #
675
- # @return [When::TM::CalendarEra] era に対応する When::TM::CalendarEra オブジェクト
676
- #
677
- def CalendarEra(era)
678
- Parts::Resource._instance(era, '_e:') do |iri|
679
- TM::CalendarEra.send(:_behalf_of, iri)
680
- end
681
- end
682
-
683
- # When::TM::CalendarEra の検索
684
- #
685
- # @overload era(key, epoch=nil, reverse=nil, options={})
686
- # @param [String, Regexp] key 検索する暦年代または、暦年代にマッチする正規表現
687
- # @param [Integer] epoch 年数を昇順にカウントする方式での暦元(0年)の通年(デフォルトは nil - 指定なし)
688
- # @param [Integer] reverse 年数を降順にカウントする方式での暦元(0年)の通年(デフォルトは nil - 指定なし)
689
- # @param [Hash] options 以下の通り
690
- # @option options [String] :area 暦年代の使用地域の指定(デフォルトは nil - 指定なし)
691
- # @option options [String] :period 暦年代の使用時代の指定(デフォルトは nil - 指定なし)
692
- # @option options [Integer] :count 何件ヒットするまで検索するかを指定(デフォルトは 1件)
693
- # @option options [String] the_others 例えば When::TM::CalendarEra オブジェクトの epoch_of_use に 'name' などの
694
- # 指定がある場合、:name に指定しておけば、検索での絞り込みに使用できる。
695
- #
696
- # @return [Array<When::TM::CalendarEra>] 検索結果を When::TM::CalendarEra オブジェクトの Array で返す
697
- # @note ヒット数が不足している場合は、_setup_ で指定した順序で When::TM::CalendarEra オブジェクトを生成しつつ読み込んで検索する。
698
- #
699
- def era(*args)
700
- TM::CalendarEra._instance(*args)
701
- end
702
-
703
- # When::TM::Clock の生成/参照
704
- #
705
- # @param [When::Parts::Timezone::Base] clock なにもせず clock をそのまま返す
706
- # @param [String] clock 時法を表す文字列
707
- # @param [Numeric] clock 秒を単位として表した時差(東経側を + とする)
708
- #
709
- # @return [When::Parts::Timezone::Base] 生成/参照した When::Parts::Timezone::Base オブジェクト
710
- #
711
- def Clock(clock)
712
- case clock
713
- when Parts::Timezone::Base ; return clock
714
- when 'Z', 0 ; return UTC
715
- when Numeric ; return Parts::Resource._instance("_tm:Clock?label=" + TM::Clock.to_hms(clock))
716
- when /\A#{CalendarTypes::TimeSystems}/ ; return Parts::Resource._instance('_c:' + clock)
717
- when String ;
718
- else ; raise TypeError, "Invalid Type: #{clock.class}"
719
- end
720
- c = TM::Clock[clock] || V::Timezone[clock]
721
- return c if c
722
- clock, options = clock.split('?')
723
- hms = TM::Clock.to_hms(clock)
724
- return Parts::Timezone[clock] unless hms
725
- iri = "_tm:Clock?label=" + hms
726
- iri += "&" + options if options
727
- Parts::Resource._instance(iri)
728
- end
729
-
730
- # When::Coordinates::Spatial の生成/参照
731
- #
732
- # @overload Location(location)
733
- # @param [When::Coordinates::Spatial] location なにもせず location をそのまま返す
734
- # @param [String] location 空間位置の IRI (デフォルトプレフィクス _l:)
735
- # @param [When::Parts::Timezone] 代表する都市の時間帯
736
- #
737
- # @overload Location(longitude, latitide, altitide=0, datum='Earth')
738
- # @param [Numeric] longitude 経度 / 度 (東経を正とする)
739
- # @param [Numeric] latitide 緯度 / 度 (北緯を正とする)
740
- # @param [Numeric] altitide 高度 / m
741
- # @param [When::Ephemeris::Datum] datum 座標系
742
- # @param [String] datum 座標系の IRI (デフォルトプレフィクス _ep:)
743
- #
744
- # @note longitudeが経度を意味する文字列, latitude が緯度を意味する文字列の場合、
745
- # 引数の順番によらず、それぞれ経度および緯度と解釈する
746
- #
747
- # @return [When::Coordinates::Spatial] 生成/参照した When::Coordinates::Spatial オブジェクト
748
- #
749
- def Location(*args)
750
- case args[0]
751
- when Coordinates::Spatial ; return args[0]
752
- when Parts::Timezone ; return args[0].location
753
- when String ; return Parts::Resource._instance(args[0], '_l:') if args.size == 1
754
- when Numeric ;
755
- else ; raise TypeError, "Invalid Type: #{args[0].class}"
756
- end
757
- rest = []
758
- longitude = latitude = nil
759
- args.each do |arg|
760
- case arg
761
- when /\A#{Coordinates::MATCH['EW']}\s*[.@\d]/, /[.@\d]\s*#{Coordinates::MATCH['EW']}\z/; longitude = arg
762
- when /\A#{Coordinates::MATCH['NS']}\s*[.@\d]/, /[.@\d]\s*#{Coordinates::MATCH['NS']}\z/; latitude = arg
763
- else ; rest << arg
764
- end
765
- end
766
- longitude ||= rest.shift
767
- latitude ||= rest.shift
768
- raise ArgumentError, "too few arguments" unless longitude && latitude
769
- altitude, datum = rest
770
- iri = "_l:long=#{longitude}&lat=#{latitude}"
771
- iri += "&alt=#{altitude}" if altitude
772
- iri += "&datum=#{datum}" if datum
773
- Parts::Resource._instance(iri)
774
- end
775
-
776
- # When::Coordinates::Border の生成/参照
777
- #
778
- # @param [String] border 年/日境界を表す文字列
779
- #
780
- # @return [When::Coordinates::Border] border に対応する When::Coordinates::Border オブジェクト
781
- #
782
- def Border(border)
783
- case border
784
- when Coordinates::Border ; return border
785
- when /\([-\d]+?\)/ ; border = "_co:MultiBorder?borders=#{border}"
786
- when /\A[^A-Z_]/i ; border = "_co:Border?border=#{border}"
787
- end
788
-
789
- Parts::Resource._instance(border, '_co:') do |iri|
790
- Coordinates::CalendarBorder.send(:_behalf_of, iri)
791
- end
792
- end
793
-
794
- #
795
- # 曜日(剰余類)
796
- #
797
- # @param [Numeric] day 月曜を 0 とする七曜(剰余類)を返します
798
- # @param [String] day 最初の3文字から決定した七曜(剰余類)を返します。
799
- # 一致する七曜(剰余類)がない場合、名前の一致するその他の剰余類を探して返します。
800
- #
801
- # @return [When::Coordinates::Residue] 月曜を 0 とする七曜(剰余類) または 名前の一致するその他の剰余類
802
- #
803
- def Residue(day)
804
- When::Coordinates::Residue.to_residue(day)
805
- end
806
- alias :day_of_week :Residue
807
-
808
- #
809
- # 月名
810
- #
811
- # @param [Numeric] name 指定の月番号の月名を返します
812
- # @param [String] name 最初の3文字から決定した月名を返します。
813
- # 一致する月名がない場合、名前の一致するその他のM17nを探して返します。
814
- # (name M17n なら name 自身をそのまま返します)
815
- #
816
- # @return [When::BasicTypes::M17n] 月名
817
- #
818
- def MonthName(name)
819
- When::BasicTypes::M17n.month_name(name)
820
- end
821
-
822
- # When::BasicTypes::M17n の生成/参照
823
- #
824
- # @param [String] source 多言語対応文字列のIRI
825
- #
826
- # @return [When::BasicTypes::M17n] source に対応する When::BasicTypes::M17n オブジェクト
827
- #
828
- def M17n(source)
829
- Parts::Resource._instance(source, '_m:')
830
- end
831
-
832
- # When::BasicTypes::M17n の生成/参照
833
- #
834
- # @param [When::BasicTypes::M17n] source 処理を行わず、そのままsourceを返す
835
- # @param [String] source locale と 文字列の対応
836
- # @param [Array] source 要素を個別に解釈して生成したオブジェクトのArrayを返す
837
- # @param [Hash] namespace prefix の指定
838
- # @param [Array] locale locale の定義順序の指定
839
- # @param [Hash] options (see {When::BasicTypes::M17n.new}[link:When/BasicTypes/M17n.html#method-c-new])
840
- #
841
- # @return [When::BasicTypes::M17n or Array<them>]
842
- #
843
- def m17n(source, namespace=nil, locale=nil, options={})
844
- case source
845
- when Array ; BasicTypes::M17n.new(source, namespace, locale, options)
846
- when BasicTypes::M17n ; source
847
- when String
848
- source = EncodingConversion.to_internal_encoding(source)
849
- return self[$1] if source =~ /\A\s*\[((\.{1,2}|::)+[^\]]+)\]/ && self.kind_of?(When::Parts::Resource)
850
- return Parts::Resource[$1] if source =~ /\A\s*\[::([^\]]+)\]/
851
- BasicTypes::M17n.new(source, namespace, locale, options)
852
- else ; raise TypeError, "Invalid Type: #{source.class}"
853
- end
854
- end
855
-
856
- # Wikipedia を参照して When::BasicTypes::M17n を生成する
857
- #
858
- # @param [String] title Wikipedia の項目名
859
- # @param [Hash] options 以下の通り
860
- # @option options [String] :locale Wikipedia の言語(デフォルト 'en' - 英語)
861
- # @option options [Numeric, nil] :interval Wikipedia サイトへのアクセス制御(デフォルト When::Locale.wikipedia_interval)
862
- # @option options [Object] :その他 キャッシュファイルへの追加書き出し要素
863
- #
864
- # @return [When::BasicTypes::M17n] 項目に対応する多言語対応文字列
865
- #
866
- # @note 生成した多言語対応文字列の what が nil でない場合、
867
- # その項目の位置情報を表わす When::Coordinates::Spatial を指す
868
- #
869
- def Wikipedia(title, options={})
870
- locale = options.delete(:locale) || 'en'
871
- title = EncodingConversion.to_internal_encoding(title)
872
- entry, query = title.split('?', 2)
873
- url = "http://#{locale}.wikipedia.org/wiki/#{URI.encode(entry).gsub(' ', '_')}"
874
- Locale.send(:wikipedia_object, url, options) unless options.empty?
875
- url += '?' + query if query
876
- object = Parts::Resource._instance(url)
877
- object.kind_of?(BasicTypes::M17n) ? object : object.label
878
- end
879
-
880
- # When::Parts::Resource の生成/参照
881
- #
882
- # @param [String] iri IRI を表す文字列
883
- # @param [String] namespace デフォルトの namespace
884
- #
885
- # @return [When::Parts::Resourc] iri (または namespace:iri) に対応する When::Parts::Resource オブジェクト
886
- #
887
- def Resource(iri, namespace=nil)
888
- Parts::Resource._instance(iri, namespace)
889
- end
890
- alias :IRI :Resource
891
-
892
- # When::Coordinates::Index の生成
893
- #
894
- # @overload Index(terms=nil, name='Month', options)
895
- # @param [String] terms trunk の用語空間名
896
- # @param [String] name trunk の要素配列名
897
- # @param [Hash] options
898
- # @option options [Array] :trunk 幹の要素(省略時は使用しない)
899
- # @option options [Hash] :branch 枝の要素(省略時は使用しない)
900
- # @option options [Integer] :unit 要素の数(省略時は不定)
901
- # @option options [Integer] :base 要素の最初の添え字(0 or 1(デフォルト))
902
- # @option options [Integer] :shift 幹の要素のローテート数(省略時はローテートしない)
903
- #
904
- # @return [When::Coordinates::Index]
905
- #
906
- def Index(*args)
907
- Coordinates::Index.new(*args)
908
- end
909
-
910
- # When::Coordinates::Pair の生成
911
- #
912
- # @param [Numeric, String] trunk 幹の要素
913
- # @param [Numeric, String] branch 枝の要素
914
- # @see When::Coordinates::Pair._force_pair
915
- #
916
- # @return [When::Coordinates::Pair]
917
- #
918
- def Pair(trunk, branch=nil)
919
- Coordinates::Pair._force_pair(trunk, branch)
920
- end
921
-
922
- # When 直下に定数として時法・暦法を定義する
923
- _define_common_calendar_types
924
-
925
- end
1
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ Copyright (C) 2011-2015 Takashi SUGA
4
+
5
+ You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
6
+ =end
7
+
8
+ begin
9
+ require 'json'
10
+ rescue LoadError
11
+ end
12
+ begin
13
+ require 'rubygems'
14
+ rescue LoadError
15
+ end
16
+ begin
17
+ gem 'tzinfo'
18
+ autoload :TZInfo, 'tzinfo'
19
+ rescue LoadError, NoMethodError
20
+ end
21
+ begin
22
+ gem 'gcalapi'
23
+ autoload :GoogleCalendar, 'when_exe/googlecalendar'
24
+ rescue LoadError, NoMethodError
25
+ end
26
+
27
+ autoload :URI, 'uri'
28
+ autoload :OpenURI, 'open-uri'
29
+ autoload :OpenSSL, 'openssl'
30
+ autoload :FileUtils, 'fileutils'
31
+ autoload :REXML, 'rexml/document'
32
+ autoload :Mutex, 'thread' unless Object.const_defined?(:Mutex)
33
+
34
+ #
35
+ # A multicultural and multilingualized calendar library based on ISO 8601, ISO 19108 and RFC 5545
36
+ #
37
+ module When
38
+
39
+ class << self
40
+
41
+ #
42
+ # マルチスレッド対応の場合 true
43
+ #
44
+ # @return [Boolean]
45
+ #
46
+ attr_reader :multi_thread
47
+
48
+ #
49
+ # Logger オブジェクト
50
+ #
51
+ # @return [Logger]
52
+ #
53
+ attr_accessor :logger
54
+ private :logger=
55
+
56
+ # Initializations
57
+ #
58
+ # @param [Hash] options 以下の通り
59
+ # @option options [When::Parts::Timezone::Base] :local デフォルトの地方時
60
+ # @option options [When::Coordinates::Spatial] :location デフォルトの空間位置
61
+ # @option options [When::TM::IntervalLength] :until V::Event::Enumerator until
62
+ # @option options [Hash{String=>String}] :alias Locale の読替パターン ({ 読替前のlocale=>読替後のlocale })
63
+ # @option options [String] :namespace_format 名前空間定義の省略時に名前空間生成に用いる書式
64
+ # @option options [Hash{String=>String}] :unification 漢字の包摂パターン ({ 包摂前の文字列=>包摂後の文字列 })
65
+ # @option options [Array<String>] :order CalendarEra の検索順序 ([ IRI of When::TM::CalendarEra ])
66
+ # @option options [Hash{String=>Array, String}] :format strftime で用いる記号の定義 ({ 記号=>[ 書式,項目名 ] or 記号列 })
67
+ # @option options [Array<Array>] :leap_seconds 閏秒の挿入記録 ([ [JD, TAI-UTC, (MJD, OFFSET)] ])
68
+ # @option options [String] :base_uri Base URI for When_exe Resources (Default When::SourceURI)
69
+ # @option options [Hash<String=>String>] :additional_namespaces User defined namespaces (Default {})
70
+ # @option options [String] :root_dir Root Directory for When_exe Resources Cash data (Default When::RootDir)
71
+ # @option options [Boolean] :direct '_' で終わるメソッドをキャッシュせずに毎回計算するか否か
72
+ # @option options [Hash{Symbol=>boolean}] :escape 毎回 method_missing を発生させるメソッドを true にする
73
+ # @option options [false, nil] :escape to_str, to_ary, to_hash のみ毎回 method_missing を発生させる
74
+ # @option options [true] :escape すべて毎回 method_missing を発生させる
75
+ # @option options [Boolean] :multi_thread マルチスレッド対応 (true: 対応, false/nil: 非対応)
76
+ # @option options [Logger] :logger Logger オブジェクト
77
+ #
78
+ # @return [void]
79
+ #
80
+ # @note
81
+ # 本メソッドでマルチスレッド対応の管理変数の初期化を行っている。
82
+ # このため、本メソッド自体および本メソッドから呼んでいる各クラスの _setup_ メソッドはスレッドセーフでない。
83
+ #
84
+ def _setup_(options={})
85
+ @multi_thread = options[:multi_thread]
86
+ @logger = options[:logger]
87
+ Parts::MethodCash._setup_(options)
88
+ Parts::Resource._setup_(options)
89
+ Locale._setup_(options)
90
+ Coordinates::Spatial._setup_(options[:location])
91
+ TM::CalendarEra._setup_(options[:order])
92
+ TM::Calendar._setup_
93
+ TM::Clock._setup_(options[:local])
94
+ TM::TemporalPosition._setup_(options[:format])
95
+ V::Event._setup_(options[:until])
96
+ V::Timezone._setup_
97
+ Parts::Timezone._setup_
98
+ TimeStandard._setup_(options[:leap_seconds])
99
+ end
100
+
101
+ # 設定情報を取得する
102
+ #
103
+ # @return [Hash] 設定情報
104
+ #
105
+ def _setup_info
106
+ {:multi_thread => @multi_thread}.
107
+ update(Parts::MethodCash._setup_info).
108
+ update(Parts::Resource._setup_info).
109
+ update(Locale._setup_info).
110
+ update(Coordinates::Spatial._setup_info).
111
+ update(TM::CalendarEra._setup_info).
112
+ update(TM::Clock._setup_info).
113
+ update(TM::TemporalPosition._setup_info).
114
+ update(V::Event._setup_info).
115
+ update(TimeStandard._setup_info)
116
+ end
117
+
118
+ #
119
+ # When 直下に定数として定義する時法・暦法(明示的的追加)
120
+ #
121
+ # @private
122
+ def _define_common_calendar_types(list=%w(UTC Gregorian Julian Civil))
123
+ list.each do |calendar|
124
+ resource = Parts::Resource._instance(calendar, '_c:')
125
+ Parts::Resource.synchronize do
126
+ Parts::Resource::ConstList << calendar
127
+ const_set(calendar, resource)
128
+ end
129
+ end
130
+ end
131
+
132
+ alias :_const_missing :const_missing
133
+
134
+ #
135
+ # When 直下に定数として定義する時法・暦法など(暗黙的追加)
136
+ #
137
+ def const_missing(constant)
138
+ sgn, *args = TM::PeriodDuration._to_array(constant.to_s)
139
+ return const_set(constant, TM::PeriodDuration.new(*args)) if sgn
140
+ iri = Parts::Resource._abbreviation_to_iri(constant)
141
+ return _const_missing(constant) unless iri
142
+ resource = Parts::Resource._instance(iri)
143
+ return const_get(constant) if const_defined?(constant)
144
+ Parts::Resource.synchronize do
145
+ Parts::Resource::ConstList << constant
146
+ const_set(constant, resource)
147
+ end
148
+ end
149
+ end
150
+
151
+ #
152
+ # when_exe 用 International Resource Identifier
153
+ #
154
+ SourceURI = ENV["WHEN_EXE_BASE_URI"] || "http://hosi.org/When/"
155
+
156
+ #
157
+ # ルートディレクトリ(デフォルトでは lib の親ディレクトリ
158
+ #
159
+ RootDir = ENV["WHEN_EXE_ROOT_DIR"] || File.dirname(__FILE__).sub(/\/[^\/]*\z/,'')
160
+
161
+ require 'when_exe/version'
162
+ require 'when_exe/locales/locale'
163
+ require 'when_exe/locales/autoload'
164
+ require 'when_exe/parts/enumerator'
165
+ require 'when_exe/parts/resource'
166
+ require 'when_exe/parts/geometric_complex'
167
+ require 'when_exe/parts/timezone'
168
+ require 'when_exe/core/compatibility'
169
+ require 'when_exe/basictypes'
170
+ require 'when_exe/ephemeris'
171
+ require 'when_exe/coordinates'
172
+ require 'when_exe/icalendar'
173
+ require 'when_exe/tmobjects'
174
+ require 'when_exe/timestandard'
175
+ require 'when_exe/tmposition'
176
+ require 'when_exe/tmreference'
177
+ require 'when_exe/calendartypes'
178
+ require 'when_exe/calendarnote'
179
+ require 'when_exe/region/m17n'
180
+ require 'when_exe/region/residue'
181
+ require 'when_exe/inspect'
182
+ require 'when_exe/linkeddata'
183
+
184
+ #
185
+ # Module Constants
186
+ #
187
+
188
+ # 1 second period duration
189
+ PT1S = TM::PeriodDuration.new(nil,[0,0,0,1])
190
+
191
+ # 1 minute period duration
192
+ PT1M = TM::PeriodDuration.new(nil,[0,0,1,0])
193
+
194
+ # 1 hour period duration
195
+ PT1H = TM::PeriodDuration.new(nil,[0,1,0,0])
196
+
197
+ # 1 day period duration
198
+ P1D = TM::PeriodDuration.new([0,0,1])
199
+
200
+ # 1 week period duration
201
+ P1W = TM::PeriodDuration.new([0,0,7])
202
+
203
+ # 1 month period duration
204
+ P1M = TM::PeriodDuration.new([0,1,0])
205
+
206
+ # 1 year period duration
207
+ P1Y = TM::PeriodDuration.new([1,0,0])
208
+
209
+ # kind of When::TM::Position or When::TM::TemporalPosition
210
+ TimeValue = TM::IndeterminateValue
211
+
212
+ # 7 days week residue
213
+ Week = When::Parts::Resource._instance('_co:Common::Week')
214
+
215
+ # Gregorian months
216
+ Month = When::Parts::Resource._instance('_m:Calendar::Month')
217
+
218
+ # +
219
+ PlusInfinity = TM::TemporalPosition.new({:indeterminated_position=>TimeValue::Max})
220
+
221
+ # - ∞
222
+ MinusInfinity = TM::TemporalPosition.new({:indeterminated_position=>TimeValue::Min})
223
+
224
+ # UTF-8 encoding
225
+ UTF8 = '.UTF-8'
226
+
227
+ # Windows-31J encoding
228
+ W31J = '.Windows-31J'
229
+
230
+ # eucJP encoding
231
+ EUCJP = '.eucJP'
232
+
233
+ class BasicTypes::M17n
234
+ autoload :Japanese, 'when_exe/region/japanese'
235
+ autoload :Chinese, 'when_exe/region/chinese'
236
+ autoload :Yi, 'when_exe/region/chinese'
237
+ autoload :Tibetan, 'when_exe/region/tibetan'
238
+ autoload :Thai, 'when_exe/region/thai'
239
+ autoload :Balinese, 'when_exe/region/balinese'
240
+ autoload :Javanese, 'when_exe/region/javanese'
241
+ autoload :Indian, 'when_exe/region/indian'
242
+ autoload :Iranian, 'when_exe/region/iranian'
243
+ autoload :Islamic, 'when_exe/region/islamic'
244
+ autoload :Jewish, 'when_exe/region/jewish'
245
+ autoload :AncientOrient, 'when_exe/region/babylonian'
246
+ autoload :Armenian, 'when_exe/region/armenian'
247
+ autoload :Roman, 'when_exe/region/roman'
248
+ autoload :Coptic, 'when_exe/region/coptic'
249
+ autoload :French, 'when_exe/region/french'
250
+ autoload :World, 'when_exe/region/world'
251
+ autoload :Positivist, 'when_exe/region/positivist'
252
+ autoload :InternationalFixed, 'when_exe/region/international_fixed'
253
+ autoload :WorldSeason, 'when_exe/region/world_season'
254
+ autoload :Tranquility, 'when_exe/region/tranquility'
255
+ autoload :Pax, 'when_exe/region/pax'
256
+ autoload :HankeHenry, 'when_exe/region/hanke_henry'
257
+ autoload :Shire, 'when_exe/region/shire'
258
+ autoload :Dee, 'when_exe/region/dee'
259
+ autoload :VanishingLeprechaun, 'when_exe/region/vanishing_leprechaun'
260
+ autoload :Yerm, 'when_exe/region/yerm'
261
+ autoload :Goddess, 'when_exe/region/goddess'
262
+ autoload :Martian, 'when_exe/region/martian'
263
+ autoload :WeekDate, 'when_exe/region/weekdate'
264
+ end
265
+
266
+ module Locale
267
+ autoload :WikipediaLinks, 'when_exe/locales/links'
268
+ autoload :IAST, 'when_exe/locales/iast'
269
+ autoload :IASTR, 'when_exe/locales/iast'
270
+ autoload :AKT, 'when_exe/locales/akt'
271
+ end
272
+
273
+ module CalendarTypes
274
+ autoload :Japanese, 'when_exe/region/japanese/calendars'
275
+ autoload :JapaneseTwin, 'when_exe/region/japanese/twins'
276
+ autoload :ChineseTwin, 'when_exe/region/chinese/twins'
277
+ autoload :ChineseSolar, 'when_exe/region/chinese'
278
+ autoload :ChineseLuniSolar, 'when_exe/region/chinese'
279
+ autoload :Yi, 'when_exe/region/chinese'
280
+ autoload :TenrekiA, 'when_exe/region/chinese'
281
+ autoload :TenrekiB, 'when_exe/region/chinese'
282
+ autoload :Korean, 'when_exe/region/korean'
283
+ autoload :Tibetan, 'when_exe/region/tibetan'
284
+ autoload :Thai, 'when_exe/region/thai'
285
+ autoload :ThaiP, 'when_exe/region/thai'
286
+ autoload :ThaiC, 'when_exe/region/thai'
287
+ autoload :ThaiT, 'when_exe/region/thai'
288
+ autoload :Tenganan, 'when_exe/region/balinese'
289
+ autoload :Pranatamangsa, 'when_exe/region/javanese'
290
+ autoload :IndianNationalSolar, 'when_exe/region/indian'
291
+ autoload :Nanakshahi, 'when_exe/region/indian'
292
+ autoload :RevisedBengali, 'when_exe/region/indian'
293
+ autoload :HinduLuniSolar, 'when_exe/region/indian'
294
+ autoload :HinduSolar, 'when_exe/region/indian'
295
+ autoload :Jalali, 'when_exe/region/iranian'
296
+ autoload :TableBasedJalali, 'when_exe/region/iranian'
297
+ autoload :Borji, 'when_exe/region/iranian'
298
+ autoload :TableBasedBorji, 'when_exe/region/iranian'
299
+ autoload :SolarHijri, 'when_exe/region/iranian'
300
+ autoload :SolarHijriAlgorithmic, 'when_exe/region/iranian'
301
+ autoload :Zoroastrian, 'when_exe/region/zoroastrian'
302
+ autoload :Qadimi, 'when_exe/region/zoroastrian'
303
+ autoload :Shahanshahi, 'when_exe/region/zoroastrian'
304
+ autoload :Fasli, 'when_exe/region/zoroastrian'
305
+ autoload :Bahai, 'when_exe/region/bahai'
306
+ autoload :TabularIslamic, 'when_exe/region/islamic'
307
+ autoload :EphemerisBasedIslamic, 'when_exe/region/islamic'
308
+ autoload :Jewish, 'when_exe/region/jewish'
309
+ autoload :Hebrew, 'when_exe/region/jewish'
310
+ autoload :Armenian, 'when_exe/region/armenian'
311
+ autoload :Babylonian, 'when_exe/region/babylonian'
312
+ autoload :BabylonianPD, 'when_exe/region/babylonian'
313
+ autoload :Seleucid, 'when_exe/region/babylonian'
314
+ autoload :SeleucidPD, 'when_exe/region/babylonian'
315
+ autoload :Ptolemaic, 'when_exe/region/coptic'
316
+ autoload :Coptic, 'when_exe/region/coptic'
317
+ autoload :JulianA, 'when_exe/region/roman'
318
+ autoload :JulianB, 'when_exe/region/roman'
319
+ autoload :JulianC, 'when_exe/region/roman'
320
+ autoload :Roman, 'when_exe/region/roman'
321
+ autoload :Gregorian, 'when_exe/region/christian'
322
+ autoload :FrenchRepublican, 'when_exe/region/french'
323
+ autoload :World, 'when_exe/region/world'
324
+ autoload :LongCount, 'when_exe/region/mayan'
325
+ autoload :Positivist, 'when_exe/region/positivist'
326
+ autoload :InternationalFixed, 'when_exe/region/international_fixed'
327
+ autoload :WorldSeason, 'when_exe/region/world_season'
328
+ autoload :Pax, 'when_exe/region/pax'
329
+ autoload :Tranquility, 'when_exe/region/tranquility'
330
+ autoload :HankeHenry, 'when_exe/region/hanke_henry'
331
+ autoload :Discordian, 'when_exe/region/discordian'
332
+ autoload :Shire, 'when_exe/region/shire'
333
+ autoload :Sym454, 'when_exe/region/symmetry'
334
+ autoload :Sym010, 'when_exe/region/symmetry'
335
+ autoload :Dee, 'when_exe/region/dee'
336
+ autoload :DeeCecil, 'when_exe/region/dee'
337
+ autoload :VanishingLeprechaun, 'when_exe/region/vanishing_leprechaun'
338
+ autoload :Yerm, 'when_exe/region/yerm'
339
+ autoload :Goddess, 'when_exe/region/goddess'
340
+ autoload :Darian, 'when_exe/region/martian'
341
+ autoload :WeekDate, 'when_exe/region/weekdate'
342
+
343
+ _time_systems = {
344
+ 'LMT' => nil, # Local Mean Time
345
+ 'LAT' => nil, # Local Apparent Time
346
+ 'THS' => nil, # Temporal Hour System
347
+ 'MTC' => 'when_exe/region/martian', # Martian Time, Coordinated
348
+ }
349
+ TimeSystems = _time_systems.keys.join('|')
350
+ _time_systems.each_pair do |key, required|
351
+ autoload key.to_sym, required if required
352
+ end
353
+ end
354
+
355
+ class CalendarNote
356
+ autoload :SolarTerms, 'when_exe/ephemeris/notes'
357
+ autoload :LunarPhases, 'when_exe/ephemeris/notes'
358
+ autoload :Ephemeris, 'when_exe/ephemeris/notes'
359
+ autoload :Japanese, 'when_exe/region/japanese/notes'
360
+ autoload :CommonWithRokuyo, 'when_exe/region/japanese/weeks'
361
+ autoload :RokuyoWeek, 'when_exe/region/japanese/weeks'
362
+ autoload :Yis, 'when_exe/region/chinese'
363
+ autoload :Balinese, 'when_exe/region/balinese'
364
+ autoload :Javanese, 'when_exe/region/javanese'
365
+ autoload :Tibetan, 'when_exe/region/tibetan'
366
+ autoload :Bahai, 'when_exe/region/bahai'
367
+ autoload :Roman, 'when_exe/region/roman'
368
+ autoload :Mayan, 'when_exe/region/mayan'
369
+ autoload :DiscordianWeek, 'when_exe/region/discordian'
370
+ autoload :CommonWithSovietFiveDay, 'when_exe/region/soviet'
371
+ autoload :SovietFiveDayWeek, 'when_exe/region/soviet'
372
+ autoload :CommonWithSovietSixDay, 'when_exe/region/soviet'
373
+ autoload :SovietSixDayWeek, 'when_exe/region/soviet'
374
+ # autoload :Yerm, 'when_exe/region/yerm'
375
+ autoload :WorldWeek, 'when_exe/region/world'
376
+ autoload :PositivistWeek, 'when_exe/region/positivist'
377
+ autoload :InternationalFixedWeek, 'when_exe/region/international_fixed'
378
+ autoload :TranquilityWeek, 'when_exe/region/tranquility'
379
+ autoload :WorldSeasonWeek, 'when_exe/region/world_season'
380
+ autoload :ShireWeek, 'when_exe/region/shire'
381
+
382
+ Default = [['_m:Calendar::Month'], ['Common::Week']]
383
+ JulianDay = [['Common::Week', 'Common::干支']]
384
+ Chinese = [['Common::干支'], ['_m:Calendar::Month'], ['Common::Week', 'Common::干支']]
385
+ end
386
+
387
+ module Coordinates
388
+ autoload :Tibetan, 'when_exe/region/tibetan'
389
+ autoload :Yi, 'when_exe/region/chinese'
390
+ autoload :Javanese, 'when_exe/region/javanese'
391
+ autoload :Indian, 'when_exe/region/indian'
392
+ autoload :Iranian, 'when_exe/region/iranian'
393
+ autoload :Bahai, 'when_exe/region/bahai'
394
+ autoload :Roman, 'when_exe/region/roman'
395
+ autoload :Mayan, 'when_exe/region/mayan'
396
+
397
+ # default index for day coordinate
398
+ DefaultDayIndex = Index.new
399
+
400
+ # default indices for date coordinates
401
+ DefaultDateIndices = [
402
+ Index.new(When::Parts::Resource._instance('_m:Calendar::Month'), {:unit =>12}),
403
+ DefaultDayIndex
404
+ ]
405
+
406
+ # default indices for time coordinates
407
+ DefaultTimeIndices = [
408
+ Index.new({:base=>0, :unit=>24}),
409
+ Index.new({:base=>0, :unit=>60}),
410
+ Index.new({:base=>0, :unit=>60})
411
+ ]
412
+ end
413
+
414
+ module TM
415
+ class OrdinalReferenceSystem
416
+ autoload :GeologicalAge, 'when_exe/region/geologicalage'
417
+ end
418
+
419
+ class CalendarEra
420
+ autoload :Japanese, 'when_exe/region/japanese/epochs'
421
+ autoload :JapanesePrimeMinister, 'when_exe/region/japanese/epochs'
422
+ autoload :NihonKoki, 'when_exe/region/japanese/nihon_shoki'
423
+ autoload :NihonShoki, 'when_exe/region/japanese/nihon_shoki'
424
+ autoload :JapaneseSolar, 'when_exe/region/japanese/twins'
425
+ autoload :JapaneseLuniSolar, 'when_exe/region/japanese/twins'
426
+ autoload :Chinese, 'when_exe/region/chinese/epochs'
427
+ autoload :ChineseSolar, 'when_exe/region/chinese/twins'
428
+ autoload :ChineseLuniSolar, 'when_exe/region/chinese/twins'
429
+ autoload :Ryukyu, 'when_exe/region/ryukyu'
430
+ autoload :Korean, 'when_exe/region/korean'
431
+ autoload :Vietnamese, 'when_exe/region/vietnamese'
432
+ autoload :Manchurian, 'when_exe/region/east_asian'
433
+ autoload :Rouran, 'when_exe/region/east_asian'
434
+ autoload :Gaochang, 'when_exe/region/east_asian'
435
+ autoload :Yunnan, 'when_exe/region/east_asian'
436
+ autoload :WesternXia, 'when_exe/region/east_asian'
437
+ autoload :KaraKhitan, 'when_exe/region/east_asian'
438
+ # autoload :Tibetan, 'when_exe/region/tibetan'
439
+ autoload :BalineseLuniSolar, 'when_exe/region/balinese'
440
+ autoload :JavaneseLunar, 'when_exe/region/javanese'
441
+ autoload :Iranian, 'when_exe/region/iranian'
442
+ autoload :Hijra, 'when_exe/region/islamic'
443
+ autoload :Jewish, 'when_exe/region/jewish'
444
+ autoload :AncientOrient, 'when_exe/region/babylonian'
445
+ autoload :Roman, 'when_exe/region/roman'
446
+ autoload :Julian, 'when_exe/region/roman'
447
+ autoload :Pope, 'when_exe/region/pope'
448
+ autoload :Byzantine, 'when_exe/region/christian'
449
+ autoload :LongCount, 'when_exe/region/mayan'
450
+
451
+ # Defualt search path for Epochs and Eras
452
+ DefaultEpochs = ['Common', 'ModernJapanese',
453
+ 'Hijra', 'Jewish', 'Iranian',
454
+ 'Roman', 'Byzantine', 'AncientOrient', 'LongCount',
455
+ 'BalineseLuniSolar', 'JavaneseLunar',
456
+ 'Japanese', 'NihonKoki', 'NihonShoki',
457
+ 'Chinese', 'Ryukyu', 'Vietnamese', 'Korean',
458
+ 'JapaneseLuniSolar', 'JapaneseSolar',
459
+ 'ChineseLuniSolar', 'ChineseSolar',
460
+ 'Manchurian', 'Rouran', 'Gaochang',
461
+ 'Yunnan', 'WesternXia', 'KaraKhitan', # 'Tibetan',
462
+ 'Pope', 'JapanesePrimeMinister']
463
+
464
+ # Defualt events for Epochs and Eras
465
+ DefaultEvents = Hash[*([['@A', 'Accession' ],
466
+ ['@FE', 'FelicitousEvent' ],
467
+ ['@ND', 'NaturalDisaster' ],
468
+ ['@IY', 'InauspiciousYear'],
469
+ ['@F', 'Foundation' ],
470
+ ['@CR', 'CalendarReform' ],
471
+ ['@CE', 'CalendarEpoch' ]].map {|e|
472
+ [e[0], When::Parts::Resource._instance('EpochEvents::'+e[1], '_m:')]
473
+ }.flatten)]
474
+
475
+ # Common Era
476
+ Common = [{}, self, [
477
+ 'area:Common#{?Reform=Reform}',
478
+ ['[BeforeCommonEra=en:BCE_(disambiguation),*alias:BCE]0.1.1'],
479
+ ['[CommonEra=en:Common_Era,*alias:CE]1.1.1', '@CE', '01-01-01^Julian'],
480
+ ['[CommonEra=en:Common_Era,*alias:CE]#{Reform:1582.10.15}', '@CR', '#{Reform:1582.10.15}^Gregorian']
481
+ ]]
482
+
483
+ # Modern Japanese Eras after the calendar reform to the Gregorian Calendar
484
+ ModernJapanese = [self, [
485
+ 'area:[ModernJapanese]',
486
+ ['[M=,alias:明=ja:%%<明治>]6.01.01', '@CR', '1873-01-01^Gregorian?note=Default'],
487
+ ['[T=,alias:大=ja:%%<大正>]1.07.30', '@A', '1912-07-30'],
488
+ ['[S=,alias:昭=ja:%%<昭和>]1.12.25', '@A', '1926-12-25'],
489
+ ['[H=,alias:平=ja:%%<平成>]1.01.08', '@A', '1989-01-08']
490
+ ]]
491
+ end
492
+ end
493
+
494
+ #
495
+ # Module Functions
496
+ #
497
+ module_function
498
+
499
+ # Generation of Temporal Objetct, duration or When::Parts::GeometricComplex
500
+ #
501
+ # @param [String] specification When.exe Standard Representation または ユリウス日JDN として解釈して生成する
502
+ # @param [Numeric] specification ユリウス日として解釈して生成する
503
+ # @param [Array] specification 要素を個別に解釈して生成したオブジェクトのArrayを返す
504
+ # @param [When::TM::TemporalPosition, When::Parts::GeometricComplex] specification specificationをそのまま返す
505
+ # @param [When::TM::TemporalPosition] specification specification.any_otherを返す
506
+ #
507
+ # @param [Hash] options 暦法や時法などの指定 (see {When::TM::TemporalPosition._instance})
508
+ #
509
+ # @return [When::TM::TemporalPosition, When::TM::Duration, When::Parts::GeometricComplex or Array<them>]
510
+ #
511
+ def when?(specification, options={})
512
+
513
+ # フォーマットごとの処理
514
+ case specification
515
+ when TM::TemporalPosition, Parts::GeometricComplex ; specification
516
+ when TM::Position ; specification.any_other
517
+ when Array ; begin options = TM::TemporalPosition._options(options) ; specification.map {|e| when?(e, options)} end
518
+ when /\Atoday(\^{1,2}(.+))?\z/i ; today($2 ? {:frame=>$2}.update(options) : options)
519
+ when /\Anow(\^{1,2}(.+))?\z/i ; now( $2 ? {:frame=>$2}.update(options) : options)
520
+ when /(JDN|MJD|SDN|CEP)(\z|\^)/i; TM::JulianDate.parse(specification, options)
521
+ when /[\n\r]+/ ; when?(specification.split(/[\n\r]+/), options)
522
+ when String ; TM::TemporalPosition._instance(EncodingConversion.to_internal_encoding(specification), options)
523
+ when Numeric ; TM::JulianDate.new(+specification, TM::TemporalPosition._options(options))
524
+ else ; Calendar(options[:frame] || 'Gregorian').jul_trans(specification, options)
525
+ end
526
+ end
527
+
528
+ # When::TM::TemporalPosition の生成
529
+ #
530
+ # @overload TemporalPosition(*args, options={})
531
+ # @param [String or [String, Integer], Numeric, ...] args
532
+ # [String] 年号
533
+ # [Array<String, Integer>] 年号と 0 年の通年
534
+ # [Numeric] 年月日時分秒(途中で打ち切り可)
535
+ # @param [Hash] options 暦法や時法などの指定
536
+ # @option options [Symbol] :invalid
537
+ # [:raise 日時が存在しない場合例外発生 ]
538
+ # [:check 日時が存在しない場合 nil を返す ]
539
+ # [その他/nil 日時が存在することを確認しない(デフォルト)]
540
+ # @see When::TM::TemporalPosition._instance
541
+ #
542
+ # @return [When::TM::TemporalPosition]
543
+ # @raise [ArgumentError]
544
+ # options[ :invalid ] が :raise で、日時が存在しない場合
545
+ #
546
+ def TemporalPosition(*args)
547
+ TM::TemporalPosition._temporal_position(*args)
548
+ end
549
+
550
+ alias :tm_pos :TemporalPosition
551
+ module_function :tm_pos
552
+
553
+ # 指定日時に対応する When::TM::TemporalPosition の生成
554
+ # (When::TM::DateAndTime of specified Time)
555
+ #
556
+ # @param [::Time] time 変換元の日時のTimeオブジェクト
557
+ # @param [Float] time 1970-01-01T00:00:00Z からの経過秒数
558
+ # @param [Hash] options 暦法や時法などの指定
559
+ # @see When::TM::TemporalPosition._instance
560
+ #
561
+ # @return [When::TM::DateAndTime]
562
+ #
563
+ def at(time, options={})
564
+ options = options._attr if options.kind_of?(TM::TemporalPosition)
565
+ options[:frame] ||= 'Gregorian'
566
+ options[:frame] = Resource(options[:frame], '_c:') if options[:frame].kind_of?(String)
567
+ options[:clock] ||= Clock(time.utc_offset) if time.kind_of?(::Time)
568
+ jdt = TM::JulianDate.universal_time(time.to_f * TM::IntervalLength::SECOND, {:frame=>TM::Clock.get_clock(options)})
569
+ options[:clock] = jdt.frame
570
+ date = options[:frame].jul_trans(jdt, options)
571
+ date = TM::CalDate.new(date.cal_date, options) if options[:precision] &&
572
+ options[:precision] <= DAY
573
+ return date
574
+ end
575
+
576
+ # 現在日時に対応する When::TM::TemporalPosition の生成
577
+ # (When::TM::DateAndTime of now)
578
+ # @note メソッド実行時の「現在日時」である。@indeterminated_position は設定しないので自動的に日時が進むことはない
579
+ #
580
+ # @param [Hash] options 暦法や時法などの指定
581
+ # @see When::TM::TemporalPosition._instance
582
+ #
583
+ # @return [When::TM::DateAndTime]
584
+ #
585
+ def now(options={})
586
+ When.at(Time.now, options)
587
+ end
588
+
589
+ # 本日に対応する When::TM::CalDate の生成
590
+ # (When::TM::CalDate of today)
591
+ # @note メソッド実行時の「本日」である。@indeterminated_position は設定しないので自動的に日時が進むことはない
592
+ # @note options で時間帯を指定しても「本日」の決定に使用するのみで、戻り値には反映されない
593
+ #
594
+ # @param [Hash] options 暦法や時法などの指定
595
+ # @see When::TM::TemporalPosition._instance
596
+ #
597
+ # @return [When::TM::CalDate]
598
+ #
599
+ def today(options={})
600
+ now(options.merge({:precision=>DAY}))
601
+ end
602
+
603
+ # When::TM::Duration の生成
604
+ #
605
+ # @param [String] period When.exe Standard Representation として解釈して生成する
606
+ # @param [Numeric] period When::TM::IntervalLength::SYSTEM 単位の値として解釈して生成する
607
+ # @param [Array] period 要素を個別に解釈して生成したオブジェクトのArrayを返す
608
+ # @param [When::TM::Duration] period 処理を行わず、そのまま返す
609
+ # @param [Hash] options 現時点では未使用
610
+ #
611
+ # @return [When::TM::Duration or Array<them>]
612
+ #
613
+ def Duration(period, options={})
614
+ case period
615
+ when Array
616
+ period.map {|e| Duration(e, options)}
617
+
618
+ when TM::Duration
619
+ period
620
+
621
+ when 0
622
+ TM::IntervalLength.new(0, 'day')
623
+
624
+ when Numeric
625
+ [TM::Duration::YEAR, TM::Duration::MONTH, TM::Duration::WEEK, TM::Duration::DAY,
626
+ TM::Duration::HOUR, TM::Duration::MINUTE, TM::Duration::SECOND].each do |unit|
627
+ div, mod = period.divmod(unit)
628
+ return TM::IntervalLength.new(div, TM::Duration::Unit.invert[unit]) if mod == 0
629
+ end
630
+ TM::IntervalLength.new(period, 'system')
631
+
632
+ when String
633
+ # IntervalLength
634
+ args = TM::IntervalLength._to_array(period)
635
+ return TM::IntervalLength.new(*args) if args
636
+
637
+ # PeriodDuration
638
+ sign, *args = TM::PeriodDuration._to_array(period)
639
+ raise TypeError, "Argument 'period' is not a Duration" unless (sign)
640
+ args << options
641
+ duration = TM::PeriodDuration.new(*args)
642
+ return (sign >= 0) ? duration : -duration
643
+
644
+ else
645
+ nil
646
+ end
647
+ end
648
+
649
+ # When::TM::Calendar の生成/参照
650
+ #
651
+ # @param [String] calendar 暦法を表す文字列
652
+ #
653
+ # @return [When::TM::Calendar] calendar に対応する When::TM::Calendar オブジェクト
654
+ #
655
+ def Calendar(calendar)
656
+ Parts::Resource._instance(calendar, '_c:')
657
+ end
658
+
659
+ # When::CalendarNote の生成/参照
660
+ #
661
+ # @param [String] note 暦注リストを表す文字列
662
+ #
663
+ # @return [When::CalendarNote] note に対応する When::CalendarNote オブジェクト
664
+ #
665
+ def CalendarNote(note)
666
+ Parts::Resource._instance(note, '_n:')
667
+ end
668
+
669
+ # When::TM::CalendarEra の生成/参照
670
+ #
671
+ # @param [String] era 暦年代を表す文字列
672
+ #
673
+ # @return [When::TM::CalendarEra] era に対応する When::TM::CalendarEra オブジェクト
674
+ #
675
+ def CalendarEra(era)
676
+ Parts::Resource._instance(era, '_e:') do |iri|
677
+ TM::CalendarEra.send(:_behalf_of, iri)
678
+ end
679
+ end
680
+
681
+ # When::TM::CalendarEra の検索
682
+ #
683
+ # @overload era(key, epoch=nil, reverse=nil, options={})
684
+ # @param [String, Regexp] key 検索する暦年代または、暦年代にマッチする正規表現
685
+ # @param [Integer] epoch 年数を昇順にカウントする方式での暦元(0年)の通年(デフォルトは nil - 指定なし)
686
+ # @param [Integer] reverse 年数を降順にカウントする方式での暦元(0年)の通年(デフォルトは nil - 指定なし)
687
+ # @param [Hash] options 以下の通り
688
+ # @option options [String] :area 暦年代の使用地域の指定(デフォルトは nil - 指定なし)
689
+ # @option options [String] :period 暦年代の使用時代の指定(デフォルトは nil - 指定なし)
690
+ # @option options [Integer] :count 何件ヒットするまで検索するかを指定(デフォルトは 1件)
691
+ # @option options [String] the_others 例えば When::TM::CalendarEra オブジェクトの epoch_of_use に 'name' などの
692
+ # 指定がある場合、:name に指定しておけば、検索での絞り込みに使用できる。
693
+ #
694
+ # @return [Array<When::TM::CalendarEra>] 検索結果を When::TM::CalendarEra オブジェクトの Array で返す
695
+ # @note ヒット数が不足している場合は、_setup_ で指定した順序で When::TM::CalendarEra オブジェクトを生成しつつ読み込んで検索する。
696
+ #
697
+ def era(*args)
698
+ TM::CalendarEra._instance(*args)
699
+ end
700
+
701
+ # When::TM::Clock の生成/参照
702
+ #
703
+ # @param [When::Parts::Timezone::Base] clock なにもせず clock をそのまま返す
704
+ # @param [String] clock 時法を表す文字列
705
+ # @param [Numeric] clock 秒を単位として表した時差(東経側を + とする)
706
+ #
707
+ # @return [When::Parts::Timezone::Base] 生成/参照した When::Parts::Timezone::Base オブジェクト
708
+ #
709
+ def Clock(clock)
710
+ case clock
711
+ when Parts::Timezone::Base ; return clock
712
+ when 'Z', 0 ; return UTC
713
+ when Numeric ; return Parts::Resource._instance("_tm:Clock?label=" + TM::Clock.to_hms(clock))
714
+ when /\A#{CalendarTypes::TimeSystems}/ ; return Parts::Resource._instance('_c:' + clock)
715
+ when String ;
716
+ else ; raise TypeError, "Invalid Type: #{clock.class}"
717
+ end
718
+ c = TM::Clock[clock] || V::Timezone[clock]
719
+ return c if c
720
+ clock, options = clock.split('?')
721
+ hms = TM::Clock.to_hms(clock)
722
+ return Parts::Timezone[clock] unless hms
723
+ iri = "_tm:Clock?label=" + hms
724
+ iri += "&" + options if options
725
+ Parts::Resource._instance(iri)
726
+ end
727
+
728
+ # When::Coordinates::Spatial の生成/参照
729
+ #
730
+ # @overload Location(location)
731
+ # @param [When::Coordinates::Spatial] location なにもせず location をそのまま返す
732
+ # @param [String] location 空間位置の IRI (デフォルトプレフィクス _l:)
733
+ # @param [When::Parts::Timezone] 代表する都市の時間帯
734
+ #
735
+ # @overload Location(longitude, latitide, altitide=0, datum='Earth')
736
+ # @param [Numeric] longitude 経度 / 度 (東経を正とする)
737
+ # @param [Numeric] latitide 緯度 / 度 (北緯を正とする)
738
+ # @param [Numeric] altitide 高度 / m
739
+ # @param [When::Ephemeris::Datum] datum 座標系
740
+ # @param [String] datum 座標系の IRI (デフォルトプレフィクス _ep:)
741
+ #
742
+ # @note longitudeが経度を意味する文字列, latitude が緯度を意味する文字列の場合、
743
+ # 引数の順番によらず、それぞれ経度および緯度と解釈する
744
+ #
745
+ # @return [When::Coordinates::Spatial] 生成/参照した When::Coordinates::Spatial オブジェクト
746
+ #
747
+ def Location(*args)
748
+ case args[0]
749
+ when Coordinates::Spatial ; return args[0]
750
+ when Parts::Timezone ; return args[0].location
751
+ when String ; return Parts::Resource._instance(args[0], '_l:') if args.size == 1
752
+ when Numeric ;
753
+ else ; raise TypeError, "Invalid Type: #{args[0].class}"
754
+ end
755
+ rest = []
756
+ longitude = latitude = nil
757
+ args.each do |arg|
758
+ case arg
759
+ when /\A#{Coordinates::MATCH['EW']}\s*[.@\d]/, /[.@\d]\s*#{Coordinates::MATCH['EW']}\z/; longitude = arg
760
+ when /\A#{Coordinates::MATCH['NS']}\s*[.@\d]/, /[.@\d]\s*#{Coordinates::MATCH['NS']}\z/; latitude = arg
761
+ else ; rest << arg
762
+ end
763
+ end
764
+ longitude ||= rest.shift
765
+ latitude ||= rest.shift
766
+ raise ArgumentError, "too few arguments" unless longitude && latitude
767
+ altitude, datum = rest
768
+ iri = "_l:long=#{longitude}&lat=#{latitude}"
769
+ iri += "&alt=#{altitude}" if altitude
770
+ iri += "&datum=#{datum}" if datum
771
+ Parts::Resource._instance(iri)
772
+ end
773
+
774
+ # When::Coordinates::Border の生成/参照
775
+ #
776
+ # @param [String] border 年/日境界を表す文字列
777
+ #
778
+ # @return [When::Coordinates::Border] border に対応する When::Coordinates::Border オブジェクト
779
+ #
780
+ def Border(border)
781
+ case border
782
+ when Coordinates::Border ; return border
783
+ when /\([-\d]+?\)/ ; border = "_co:MultiBorder?borders=#{border}"
784
+ when /\A[^A-Z_]/i ; border = "_co:Border?border=#{border}"
785
+ end
786
+
787
+ Parts::Resource._instance(border, '_co:') do |iri|
788
+ Coordinates::CalendarBorder.send(:_behalf_of, iri)
789
+ end
790
+ end
791
+
792
+ #
793
+ # 曜日(剰余類)
794
+ #
795
+ # @param [Numeric] day 月曜を 0 とする七曜(剰余類)を返します
796
+ # @param [String] day 最初の3文字から決定した七曜(剰余類)を返します。
797
+ # 一致する七曜(剰余類)がない場合、名前の一致するその他の剰余類を探して返します。
798
+ #
799
+ # @return [When::Coordinates::Residue] 月曜を 0 とする七曜(剰余類) または 名前の一致するその他の剰余類
800
+ #
801
+ def Residue(day)
802
+ When::Coordinates::Residue.to_residue(day)
803
+ end
804
+ alias :day_of_week :Residue
805
+
806
+ #
807
+ # 月名
808
+ #
809
+ # @param [Numeric] name 指定の月番号の月名を返します
810
+ # @param [String] name 最初の3文字から決定した月名を返します。
811
+ # 一致する月名がない場合、名前の一致するその他のM17nを探して返します。
812
+ # (name M17n なら name 自身をそのまま返します)
813
+ #
814
+ # @return [When::BasicTypes::M17n] 月名
815
+ #
816
+ def MonthName(name)
817
+ When::BasicTypes::M17n.month_name(name)
818
+ end
819
+
820
+ # When::BasicTypes::M17n の生成/参照
821
+ #
822
+ # @param [String] source 多言語対応文字列のIRI
823
+ #
824
+ # @return [When::BasicTypes::M17n] source に対応する When::BasicTypes::M17n オブジェクト
825
+ #
826
+ def M17n(source)
827
+ Parts::Resource._instance(source, '_m:')
828
+ end
829
+
830
+ # When::BasicTypes::M17n の生成/参照
831
+ #
832
+ # @param [When::BasicTypes::M17n] source 処理を行わず、そのままsourceを返す
833
+ # @param [String] source locale と 文字列の対応
834
+ # @param [Array] source 要素を個別に解釈して生成したオブジェクトのArrayを返す
835
+ # @param [Hash] namespace prefix の指定
836
+ # @param [Array] locale locale の定義順序の指定
837
+ # @param [Hash] options (see {When::BasicTypes::M17n.new}[link:When/BasicTypes/M17n.html#method-c-new])
838
+ #
839
+ # @return [When::BasicTypes::M17n or Array<them>]
840
+ #
841
+ def m17n(source, namespace=nil, locale=nil, options={})
842
+ case source
843
+ when Array ; BasicTypes::M17n.new(source, namespace, locale, options)
844
+ when BasicTypes::M17n ; source
845
+ when String
846
+ source = EncodingConversion.to_internal_encoding(source)
847
+ return self[$1] if source =~ /\A\s*\[((\.{1,2}|::)+[^\]]+)\]/ && self.kind_of?(When::Parts::Resource)
848
+ return Parts::Resource[$1] if source =~ /\A\s*\[::([^\]]+)\]/
849
+ BasicTypes::M17n.new(source, namespace, locale, options)
850
+ else ; raise TypeError, "Invalid Type: #{source.class}"
851
+ end
852
+ end
853
+
854
+ # Wikipedia を参照して When::BasicTypes::M17n を生成する
855
+ #
856
+ # @param [String] title Wikipedia の項目名
857
+ # @param [Hash] options 以下の通り
858
+ # @option options [String] :locale Wikipedia の言語(デフォルト 'en' - 英語)
859
+ # @option options [Numeric, nil] :interval Wikipedia サイトへのアクセス制御(デフォルト When::Locale.wikipedia_interval)
860
+ # @option options [Object] :その他 キャッシュファイルへの追加書き出し要素
861
+ #
862
+ # @return [When::BasicTypes::M17n] 項目に対応する多言語対応文字列
863
+ #
864
+ # @note 生成した多言語対応文字列の what が nil でない場合、
865
+ # その項目の位置情報を表わす When::Coordinates::Spatial を指す
866
+ #
867
+ def Wikipedia(title, options={})
868
+ locale = options.delete(:locale) || 'en'
869
+ title = EncodingConversion.to_internal_encoding(title)
870
+ entry, query = title.split('?', 2)
871
+ url = "http://#{locale}.wikipedia.org/wiki/#{URI.encode(entry).gsub(' ', '_')}"
872
+ Locale.send(:wikipedia_object, url, options) unless options.empty?
873
+ url += '?' + query if query
874
+ object = Parts::Resource._instance(url)
875
+ object.to_m17n
876
+ end
877
+
878
+ # When::Parts::Resource の生成/参照
879
+ #
880
+ # @param [String] iri IRI を表す文字列
881
+ # @param [String] namespace デフォルトの namespace
882
+ #
883
+ # @return [When::Parts::Resourc] iri (または namespace:iri) に対応する When::Parts::Resource オブジェクト
884
+ #
885
+ def Resource(iri, namespace=nil)
886
+ Parts::Resource._instance(iri, namespace)
887
+ end
888
+ alias :IRI :Resource
889
+
890
+ # When::Coordinates::Index の生成
891
+ #
892
+ # @overload Index(terms=nil, name='Month', options)
893
+ # @param [String] terms trunk の用語空間名
894
+ # @param [String] name trunk の要素配列名
895
+ # @param [Hash] options
896
+ # @option options [Array] :trunk 幹の要素(省略時は使用しない)
897
+ # @option options [Hash] :branch 枝の要素(省略時は使用しない)
898
+ # @option options [Integer] :unit 要素の数(省略時は不定)
899
+ # @option options [Integer] :base 要素の最初の添え字(0 or 1(デフォルト))
900
+ # @option options [Integer] :shift 幹の要素のローテート数(省略時はローテートしない)
901
+ #
902
+ # @return [When::Coordinates::Index]
903
+ #
904
+ def Index(*args)
905
+ Coordinates::Index.new(*args)
906
+ end
907
+
908
+ # When::Coordinates::Pair の生成
909
+ #
910
+ # @param [Numeric, String] trunk 幹の要素
911
+ # @param [Numeric, String] branch 枝の要素
912
+ # @see When::Coordinates::Pair._force_pair
913
+ #
914
+ # @return [When::Coordinates::Pair]
915
+ #
916
+ def Pair(trunk, branch=nil)
917
+ Coordinates::Pair._force_pair(trunk, branch)
918
+ end
919
+
920
+ # When 直下に定数として時法・暦法を定義する
921
+ _define_common_calendar_types
922
+
923
+ end