when_exe 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.ja.txt +25 -25
- data/LICENSE.txt +31 -31
- data/bin/locales.rb +2 -1
- data/bin/when.rb.config +1 -1
- data/lib/when_exe.rb +70 -48
- data/lib/when_exe/basictypes.rb +99 -65
- data/lib/when_exe/calendartypes.rb +40 -178
- data/lib/when_exe/coordinates.rb +156 -62
- data/lib/when_exe/core/compatibility.rb +10 -0
- data/lib/when_exe/core/extension.rb +40 -0
- data/lib/when_exe/ephemeris.rb +112 -50
- data/lib/when_exe/icalendar.rb +125 -91
- data/lib/when_exe/inspect.rb +100 -48
- data/lib/when_exe/locales/ar.rb +48 -48
- data/lib/when_exe/locales/bg.rb +1 -1
- data/lib/when_exe/locales/bs.rb +4 -2
- data/lib/when_exe/locales/ca.rb +1 -1
- data/lib/when_exe/locales/en_CA.rb +3 -4
- data/lib/when_exe/locales/en_IE.rb +88 -0
- data/lib/when_exe/locales/en_US.rb +87 -0
- data/lib/when_exe/locales/es_CR.rb +84 -0
- data/lib/when_exe/locales/es_EC.rb +85 -0
- data/lib/when_exe/locales/es_PA.rb +85 -0
- data/lib/when_exe/locales/fr.rb +39 -39
- data/lib/when_exe/locales/hu.rb +15 -14
- data/lib/when_exe/locales/it.rb +1 -1
- data/lib/when_exe/locales/ja.rb +2 -2
- data/lib/when_exe/locales/locales.rb +7 -0
- data/lib/when_exe/locales/lt.rb +21 -19
- data/lib/when_exe/locales/ms.rb +84 -0
- data/lib/when_exe/locales/nl.rb +2 -2
- data/lib/when_exe/locales/ru.rb +1 -1
- data/lib/when_exe/locales/uk.rb +1 -1
- data/lib/when_exe/locales/ur.rb +84 -0
- data/lib/when_exe/mini_application.rb +44 -43
- data/lib/when_exe/parts/enumerator.rb +3 -3
- data/lib/when_exe/parts/geometric_complex.rb +6 -1
- data/lib/when_exe/parts/locale.rb +49 -18
- data/lib/when_exe/parts/method_cash.rb +61 -0
- data/lib/when_exe/parts/resource.rb +221 -106
- data/lib/when_exe/parts/timezone.rb +70 -33
- data/lib/when_exe/region/bahai.rb +2 -2
- data/lib/when_exe/region/balinese.rb +40 -43
- data/lib/when_exe/region/chinese.rb +93 -33
- data/lib/when_exe/region/chinese_calendar.rb +117 -1
- data/lib/when_exe/region/chinese_epoch.rb +65 -10
- data/lib/when_exe/region/christian.rb +97 -2
- data/lib/when_exe/region/ephemeric_notes.rb +353 -0
- data/lib/when_exe/region/french.rb +1 -1
- data/lib/when_exe/region/geologicalage.rb +171 -171
- data/lib/when_exe/region/indian.rb +18 -14
- data/lib/when_exe/region/iranian.rb +1 -1
- data/lib/when_exe/region/japanese.rb +49 -12
- data/lib/when_exe/region/japanese_notes.rb +838 -507
- data/lib/when_exe/region/japanese_residues.rb +724 -662
- data/lib/when_exe/region/javanese.rb +7 -7
- data/lib/when_exe/region/mayan.rb +19 -17
- data/lib/when_exe/region/nihon_shoki.rb +3 -3
- data/lib/when_exe/region/residue.rb +29 -28
- data/lib/when_exe/region/shire.rb +2 -2
- data/lib/when_exe/region/tibetan.rb +87 -5
- data/lib/when_exe/region/world.rb +1 -1
- data/lib/when_exe/timestandard.rb +85 -7
- data/lib/when_exe/tmobjects.rb +32 -4
- data/lib/when_exe/tmposition.rb +104 -55
- data/lib/when_exe/tmreference.rb +157 -60
- data/lib/when_exe/version.rb +2 -2
- data/test/examples/JapanHolidays.ics +3 -3
- data/test/examples/JapanHolidaysRFC6350.ics +499 -0
- data/test/examples/Residue.m17n +3 -2
- data/test/examples/Spatial.m17n +3 -3
- data/test/examples/USA-DST.ics +27 -27
- data/test/examples/today.rb +1 -1
- data/test/test.rb +4 -2
- data/test/test/basictypes.rb +40 -15
- data/test/test/coordinates.rb +9 -4
- data/test/test/icalendar.rb +24 -14
- data/test/test/inspect.rb +5 -3
- data/test/test/parts.rb +11 -2
- data/test/test/region/chinese.rb +4 -4
- data/test/test/region/civil.rb +124 -0
- data/test/test/region/geologicalage.rb +5 -2
- data/test/test/region/indian.rb +2 -0
- data/test/test/region/japanese.rb +156 -1
- data/test/test/region/jewish.rb +3 -3
- data/test/test/region/m17n.rb +9 -9
- data/test/test/region/mayan.rb +122 -5
- data/test/test/region/residue.rb +1 -1
- data/test/test/tmobjects.rb +27 -64
- data/test/test/tmposition.rb +48 -1
- data/test/test/tmreference.rb +66 -4
- data/when_exe.gemspec +1 -1
- metadata +15 -6
data/LICENSE.ja.txt
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
When.exe: A multicultural and multilingualized calendar library
|
2
|
-
|
3
|
-
本プログラムの著作権は須賀隆 <suchowan@box.email.ne.jp> にあります。
|
4
|
-
|
5
|
-
本プログラムは,下記の条件で使用できます.
|
6
|
-
|
7
|
-
1. 必ず、著作権表示や免責事項を含めて、制限なく自由に複製できます.
|
8
|
-
|
9
|
-
2. 以下の条件のいずれかを満たす時に本プログラムを自由に変更できます.
|
10
|
-
|
11
|
-
(a) 変更した本プログラムを自分だけで使う.
|
12
|
-
|
13
|
-
(b) その他の変更条件を作者と書面により合意する.
|
14
|
-
|
15
|
-
3. 本プログラム,変更した本プログラム及び本プログラムから生成した実行形式は,
|
16
|
-
作者との書面による合意がなければ配布できません.
|
17
|
-
|
18
|
-
4. 他のプログラムとの併合はいかなる目的であれ自由です.
|
19
|
-
|
20
|
-
5. 本プログラムへの入力となるデータおよび本プログラムからの出力の権利は
|
21
|
-
本プログラムの作者ではなく,それぞれの入出力を生成した人に属します.
|
22
|
-
|
23
|
-
6. 本プログラムは無保証です.作者は本プログラムをサポートする意志はありますが,
|
24
|
-
プログラム自身のバグあるいは本プログラムの実行などから発生するいかなる損害に
|
25
|
-
対しても責任を持ちません.
|
1
|
+
When.exe: A multicultural and multilingualized calendar library
|
2
|
+
|
3
|
+
本プログラムの著作権は須賀隆 <suchowan@box.email.ne.jp> にあります。
|
4
|
+
|
5
|
+
本プログラムは,下記の条件で使用できます.
|
6
|
+
|
7
|
+
1. 必ず、著作権表示や免責事項を含めて、制限なく自由に複製できます.
|
8
|
+
|
9
|
+
2. 以下の条件のいずれかを満たす時に本プログラムを自由に変更できます.
|
10
|
+
|
11
|
+
(a) 変更した本プログラムを自分だけで使う.
|
12
|
+
|
13
|
+
(b) その他の変更条件を作者と書面により合意する.
|
14
|
+
|
15
|
+
3. 本プログラム,変更した本プログラム及び本プログラムから生成した実行形式は,
|
16
|
+
作者との書面による合意がなければ配布できません.
|
17
|
+
|
18
|
+
4. 他のプログラムとの併合はいかなる目的であれ自由です.
|
19
|
+
|
20
|
+
5. 本プログラムへの入力となるデータおよび本プログラムからの出力の権利は
|
21
|
+
本プログラムの作者ではなく,それぞれの入出力を生成した人に属します.
|
22
|
+
|
23
|
+
6. 本プログラムは無保証です.作者は本プログラムをサポートする意志はありますが,
|
24
|
+
プログラム自身のバグあるいは本プログラムの実行などから発生するいかなる損害に
|
25
|
+
対しても責任を持ちません.
|
data/LICENSE.txt
CHANGED
@@ -1,31 +1,31 @@
|
|
1
|
-
When.exe: A multicultural and multilingualized calendar library
|
2
|
-
|
3
|
-
This library is copyrighted free software by Takashi SUGA <suchowan@box.email.ne.jp>.
|
4
|
-
|
5
|
-
You can use and/or modify the software under the conditions below:
|
6
|
-
|
7
|
-
1. You may make verbatim copies of the software without restriction, provided
|
8
|
-
that you duplicate all of the original copyright notices and associated
|
9
|
-
disclaimers.
|
10
|
-
|
11
|
-
2. You may modify your copy of the software in any way, provided that
|
12
|
-
you do at least ONE of the following:
|
13
|
-
|
14
|
-
a) place your modifications in your private domain.
|
15
|
-
|
16
|
-
b) make other written arrangements with the author.
|
17
|
-
|
18
|
-
3. You cannot distribute the software with/without modification or
|
19
|
-
derived executable binary form without written arrangements with the author.
|
20
|
-
|
21
|
-
4. You may modify and include the part of the software into any other
|
22
|
-
software.
|
23
|
-
|
24
|
-
5. The data supplied as input to or produced as output from the software
|
25
|
-
do not automatically fall under the copyright of the software,
|
26
|
-
but belong to whomever generated them.
|
27
|
-
|
28
|
-
6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
29
|
-
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
30
|
-
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
31
|
-
PURPOSE.
|
1
|
+
When.exe: A multicultural and multilingualized calendar library
|
2
|
+
|
3
|
+
This library is copyrighted free software by Takashi SUGA <suchowan@box.email.ne.jp>.
|
4
|
+
|
5
|
+
You can use and/or modify the software under the conditions below:
|
6
|
+
|
7
|
+
1. You may make verbatim copies of the software without restriction, provided
|
8
|
+
that you duplicate all of the original copyright notices and associated
|
9
|
+
disclaimers.
|
10
|
+
|
11
|
+
2. You may modify your copy of the software in any way, provided that
|
12
|
+
you do at least ONE of the following:
|
13
|
+
|
14
|
+
a) place your modifications in your private domain.
|
15
|
+
|
16
|
+
b) make other written arrangements with the author.
|
17
|
+
|
18
|
+
3. You cannot distribute the software with/without modification or
|
19
|
+
derived executable binary form without written arrangements with the author.
|
20
|
+
|
21
|
+
4. You may modify and include the part of the software into any other
|
22
|
+
software.
|
23
|
+
|
24
|
+
5. The data supplied as input to or produced as output from the software
|
25
|
+
do not automatically fall under the copyright of the software,
|
26
|
+
but belong to whomever generated them.
|
27
|
+
|
28
|
+
6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
29
|
+
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
30
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
31
|
+
PURPOSE.
|
data/bin/locales.rb
CHANGED
@@ -54,7 +54,8 @@ site.get('/svenfuchs/rails-i18n/tree/master/rails/locale').body.scan(/>([^> ]+?)
|
|
54
54
|
end
|
55
55
|
yaml = YAML.load(locale)
|
56
56
|
next unless yaml
|
57
|
-
|
57
|
+
time_format = yaml[code]['time']['formats']['default'][/%H.*$/]
|
58
|
+
yaml[code]['time']['formats']['time'] ||= time_format.sub(/\s*%Y.*$/,'') if time_format
|
58
59
|
yamls[code.sub(/-/,'_')] = {'date'=>yaml[code]['date'], 'time'=>yaml[code]['time'], 'datetime'=>yaml[code]['datetime']}
|
59
60
|
end
|
60
61
|
|
data/bin/when.rb.config
CHANGED
data/lib/when_exe.rb
CHANGED
@@ -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
|
@@ -22,6 +22,7 @@ end
|
|
22
22
|
|
23
23
|
autoload :URI, 'uri'
|
24
24
|
autoload :OpenURI, 'open-uri'
|
25
|
+
autoload :OpenSSL, 'openssl'
|
25
26
|
autoload :JSON, 'json'
|
26
27
|
autoload :REXML, 'rexml/document'
|
27
28
|
autoload :Mutex, 'thread' unless Object.const_defined?(:Mutex)
|
@@ -47,6 +48,7 @@ module When
|
|
47
48
|
#
|
48
49
|
# @param [Hash] options
|
49
50
|
# @option options [When::TM::Clock, When::V::Timezone, When::Parts::Timezone] :local デフォルトの地方時
|
51
|
+
# @option options [When::Coordinates::Spatial] :location デフォルトの空間位置
|
50
52
|
# @option options [When::TM::IntervalLength] :until V::Event::Enumerator の until
|
51
53
|
# @option options [Hash{String=>String}] :alias Locale の読替パターン ({ 読替前のlocale=>読替後のlocale })
|
52
54
|
# @option options [Hash{String=>String}] :unification 漢字の包摂パターン ({ 包摂前の文字列=>包摂後の文字列 })
|
@@ -54,6 +56,8 @@ module When
|
|
54
56
|
# @option options [Hash{String=>Array, String}] :format strftime で用いる記号の定義 ({ 記号=>[ 書式,項目名 ] or 記号列 })
|
55
57
|
# @option options [Array<Array>] :leap_seconds 閏秒の挿入記録 ([ [JD, TAI-UTC, (MJD, OFFSET)] ])
|
56
58
|
# @option options [Boolean] :multi_thread マルチスレッド対応 (true: 対応, false/nil: 非対応)
|
59
|
+
# @option options [Boolean] :direct '_' で終わるメソッドをキャッシュせずに毎回計算するか否か
|
60
|
+
# @option options [Hash{Symbol=>boolean}] :escape 毎回 method_missing を発生させるメソッドを true にする
|
57
61
|
#
|
58
62
|
# @return [void]
|
59
63
|
#
|
@@ -63,8 +67,10 @@ module When
|
|
63
67
|
#
|
64
68
|
def _setup_(options={})
|
65
69
|
@multi_thread = options[:multi_thread]
|
70
|
+
Parts::MethodCash._setup_(options[:direct], options[:escape])
|
66
71
|
Parts::Resource._setup_
|
67
72
|
Parts::Locale._setup_(options)
|
73
|
+
Coordinates::Spatial._setup_(options[:location])
|
68
74
|
TM::CalendarEra._setup_(options[:order])
|
69
75
|
TM::Calendar._setup_
|
70
76
|
TM::Clock._setup_(options[:local])
|
@@ -182,6 +188,9 @@ module When
|
|
182
188
|
end
|
183
189
|
|
184
190
|
class CalendarNote
|
191
|
+
autoload :SolarTerms, 'when_exe/region/ephemeric_notes'
|
192
|
+
autoload :LunarPhases, 'when_exe/region/ephemeric_notes'
|
193
|
+
autoload :EphemericNote, 'when_exe/region/ephemeric_notes'
|
185
194
|
autoload :JapaneseNote, 'when_exe/region/japanese_notes'
|
186
195
|
autoload :BalineseNote, 'when_exe/region/balinese'
|
187
196
|
autoload :RomanNote, 'when_exe/region/roman'
|
@@ -194,12 +203,15 @@ module When
|
|
194
203
|
JavaneseNotes = [['Javanese::Windu'], ['_m:CalendarTerms::Month'],
|
195
204
|
['Javanese::Pasaran', 'Javanese::Paringkelan', 'Javanese::Week', 'Javanese::Wuku']]
|
196
205
|
ChineseNotes = [['CommonResidue::干支'], ['_m:CalendarTerms::Month'], ['CommonResidue::干支']]
|
206
|
+
TibetanNotes = [['Tibetan::干支'], ['_m:CalendarTerms::Month'], []]
|
197
207
|
YiNotes = [['Yi::YearName'], ['_m:CalendarTerms::Month'], []]
|
198
|
-
MayanNotes = [
|
208
|
+
MayanNotes = [{'0B'=>{'Base'=>'?Epoch=0D'}, '2B'=>{'Base'=>'?Epoch=2D'}},
|
209
|
+
['Mayan#{Base:}::Trecena', 'Mayan#{Base:}::Tzolk\'in', 'Mayan#{Base:}::Lords_of_the_Night', 'Mayan#{Base:}::Haab\'']]
|
199
210
|
end
|
200
211
|
end
|
201
212
|
|
202
213
|
module Coordinates
|
214
|
+
autoload :Tibetan, 'when_exe/region/tibetan'
|
203
215
|
autoload :Yi, 'when_exe/region/chinese'
|
204
216
|
autoload :Javanese, 'when_exe/region/javanese'
|
205
217
|
autoload :IndianCities, 'when_exe/region/indian'
|
@@ -225,42 +237,52 @@ module When
|
|
225
237
|
end
|
226
238
|
|
227
239
|
module TM
|
228
|
-
|
240
|
+
class OrdinalReferenceSystem
|
241
|
+
autoload :GeologicalAge, 'when_exe/region/geologicalage'
|
242
|
+
end
|
243
|
+
|
229
244
|
class CalendarEra
|
230
|
-
autoload :Japanese,
|
231
|
-
autoload :JapanesePrimeMinister,
|
232
|
-
autoload :NihonKoki,
|
233
|
-
autoload :NihonShoki,
|
234
|
-
autoload :
|
235
|
-
autoload :
|
236
|
-
autoload :
|
237
|
-
autoload :
|
238
|
-
autoload :
|
239
|
-
autoload :
|
240
|
-
autoload :
|
241
|
-
autoload :
|
242
|
-
|
243
|
-
autoload :
|
244
|
-
autoload :
|
245
|
-
autoload :
|
246
|
-
|
247
|
-
autoload :
|
248
|
-
autoload :
|
249
|
-
autoload :
|
250
|
-
autoload :
|
251
|
-
autoload :
|
252
|
-
autoload :
|
253
|
-
autoload :
|
254
|
-
autoload :
|
255
|
-
autoload :
|
245
|
+
autoload :Japanese, 'when_exe/region/japanese'
|
246
|
+
autoload :JapanesePrimeMinister, 'when_exe/region/japanese'
|
247
|
+
autoload :NihonKoki, 'when_exe/region/nihon_shoki'
|
248
|
+
autoload :NihonShoki, 'when_exe/region/nihon_shoki'
|
249
|
+
autoload :JapaneseSolarSeries, 'when_exe/region/japanese_notes'
|
250
|
+
autoload :JapaneseLuniSolarSeries, 'when_exe/region/japanese_notes'
|
251
|
+
autoload :Chinese, 'when_exe/region/chinese_epoch'
|
252
|
+
autoload :ChineseSolarSeries, 'when_exe/region/chinese_epoch'
|
253
|
+
autoload :ChineseLuniSolarSeries, 'when_exe/region/chinese_epoch'
|
254
|
+
autoload :Ryukyu, 'when_exe/region/ryukyu'
|
255
|
+
autoload :Korean, 'when_exe/region/korean'
|
256
|
+
autoload :Vietnamese, 'when_exe/region/vietnamese'
|
257
|
+
autoload :Manchurian, 'when_exe/region/far_east'
|
258
|
+
autoload :Rouran, 'when_exe/region/far_east'
|
259
|
+
autoload :Gaochang, 'when_exe/region/far_east'
|
260
|
+
autoload :Yunnan, 'when_exe/region/far_east'
|
261
|
+
# autoload :Tibetan, 'when_exe/region/tibetan'
|
262
|
+
autoload :BalineseLuniSolar, 'when_exe/region/balinese'
|
263
|
+
autoload :JavaneseLunar, 'when_exe/region/javanese'
|
264
|
+
autoload :IndianNationalSolar, 'when_exe/region/indian'
|
265
|
+
autoload :Iranian, 'when_exe/region/iranian'
|
266
|
+
autoload :Hijra, 'when_exe/region/islamic'
|
267
|
+
autoload :Jewish, 'when_exe/region/jewish'
|
268
|
+
autoload :Roman, 'when_exe/region/roman'
|
269
|
+
autoload :Julian, 'when_exe/region/roman'
|
270
|
+
autoload :Pope, 'when_exe/region/pope'
|
271
|
+
autoload :Byzantine, 'when_exe/region/christian'
|
272
|
+
autoload :French, 'when_exe/region/french'
|
273
|
+
autoload :World, 'when_exe/region/world'
|
274
|
+
autoload :LongCount, 'when_exe/region/mayan'
|
256
275
|
|
257
276
|
# Defualt search path for Epochs and Eras
|
258
|
-
DefaultEpochs = ['Common', 'ModernJapanese',
|
259
|
-
'
|
260
|
-
|
261
|
-
'
|
277
|
+
DefaultEpochs = ['Common', 'Common?Reform=1752.09.14', 'ModernJapanese',
|
278
|
+
'IndianNationalSolar', 'Iranian', 'Hijra', 'Jewish',
|
279
|
+
'Roman', 'Byzantine', 'French', 'World',
|
280
|
+
'LongCount', 'LongCount?Epoch=0D', 'LongCount?Epoch=2D',
|
281
|
+
'BalineseLuniSolar', 'JavaneseLunar',
|
262
282
|
'Japanese', 'JapanesePrimeMinister', 'NihonKoki', 'NihonShoki',
|
263
283
|
'Chinese', 'Ryukyu', 'Vietnamese', 'Korean',
|
284
|
+
'JapaneseSolarSeries', 'JapaneseLuniSolarSeries',
|
285
|
+
'ChineseSolarSeries', 'ChineseLuniSolarSeries',
|
264
286
|
'Manchurian', 'Rouran', 'Gaochang', 'Yunnan', # 'Tibetan',
|
265
287
|
'Pope' ]
|
266
288
|
|
@@ -275,22 +297,22 @@ module When
|
|
275
297
|
}.flatten)]
|
276
298
|
|
277
299
|
# Common Era
|
278
|
-
Common = [self, [
|
279
|
-
|
280
|
-
|
281
|
-
[
|
282
|
-
[
|
283
|
-
[
|
300
|
+
Common = [{}, self, [
|
301
|
+
'namespace:[en=http://en.wikipedia.org/wiki/]',
|
302
|
+
'area:Common#{?Reform=Reform}',
|
303
|
+
['[BeforeCommonEra=en:BCE_(disambiguation),*alias:BCE]0.1.1'],
|
304
|
+
['[CommonEra=en:Common_Era,*alias:CE]1.1.1', 'Calendar Epoch', '01-01-01^Julian'],
|
305
|
+
['[CommonEra=en:Common_Era,*alias:CE]#{Reform:1582.10.15}', 'Calendar Reform', '#{Reform:1582.10.15}^Gregorian']
|
284
306
|
]]
|
285
307
|
|
286
308
|
# Modern Japanese Eras after the calendar reform to the Gregorian Calendar
|
287
309
|
ModernJapanese = [self, [
|
288
|
-
|
289
|
-
|
290
|
-
[
|
291
|
-
[
|
292
|
-
[
|
293
|
-
[
|
310
|
+
'namespace:[en=http://en.wikipedia.org/wiki/, ja=http://ja.wikipedia.org/wiki/]',
|
311
|
+
'area:[ModernJapanese]',
|
312
|
+
['[M=,alias:明=ja:明治]6.01.01', '@CR', '1873-01-01^Gregorian?note=DefaultNotes'],
|
313
|
+
['[T=,alias:大=ja:大正]1.07.30', '@A', '1912-07-30'],
|
314
|
+
['[S=,alias:昭=ja:昭和]1.12.25', '@A', '1926-12-25'],
|
315
|
+
['[H=,alias:平=ja:平成]1.01.08', '@A', '1989-01-08']
|
294
316
|
]]
|
295
317
|
end
|
296
318
|
end
|
@@ -358,7 +380,7 @@ module When
|
|
358
380
|
# 時間位置の生成
|
359
381
|
date = Array.new(options[:frame].indices.length+1) {args.shift}
|
360
382
|
if (args.length > 0)
|
361
|
-
options[:clock] ||= TM::Clock.local_time
|
383
|
+
options[:clock] ||= TM::Clock.local_time
|
362
384
|
time = Array.new(options[:clock].indices.length) {args.shift}
|
363
385
|
position = TM::DateAndTime.new(date, time.unshift(0), options)
|
364
386
|
else
|
@@ -398,8 +420,8 @@ module When
|
|
398
420
|
options = options._attr if options.kind_of?(TM::TemporalPosition)
|
399
421
|
options[:frame] ||= 'Gregorian'
|
400
422
|
options[:frame] = Resource(options[:frame], '_c:') if options[:frame].kind_of?(String)
|
401
|
-
clock
|
402
|
-
jdt = TM::JulianDate.universal_time(time.to_f * TM::IntervalLength::SECOND, {:frame=>
|
423
|
+
options[:clock] ||= Clock(time.utc_offset) if time.kind_of?(::Time)
|
424
|
+
jdt = TM::JulianDate.universal_time(time.to_f * TM::IntervalLength::SECOND, {:frame=>TM::Clock.get_clock(options)})
|
403
425
|
options[:clock] = jdt.frame
|
404
426
|
date = options[:frame].jul_trans(jdt, options)
|
405
427
|
date = TM::CalDate.new(date.cal_date, options) if options[:precision] &&
|
data/lib/when_exe/basictypes.rb
CHANGED
@@ -26,6 +26,7 @@ module When
|
|
26
26
|
# @param [Hash] options
|
27
27
|
# @option options [String, Array<String, Integer>] :era_name デフォルトの年号(Integerは0年に対応する通年)
|
28
28
|
# @option options [Array<Numeric>] :abbr 上位省略形式で使用する上位部分
|
29
|
+
# @option options [Integer] :extra_year_digits ISO8601拡大表記のための年の構成要素拡大桁数(省略時 1桁)
|
29
30
|
#
|
30
31
|
# @return [Array] format, date, time, clock, era
|
31
32
|
#
|
@@ -48,7 +49,7 @@ module When
|
|
48
49
|
if options[:abbr].kind_of?(When::TimeValue)
|
49
50
|
options[:abbr] = ((options[:frame]||When.Calendar('Gregorian')) ^ options[:abbr]).cal_date
|
50
51
|
end
|
51
|
-
date_time = date_time.gsub(/_
|
52
|
+
date_time = date_time.gsub(/_([\d])/, '\1')
|
52
53
|
begin
|
53
54
|
return _to_array_basic(date_time, options)
|
54
55
|
rescue ArgumentError
|
@@ -97,8 +98,8 @@ module When
|
|
97
98
|
format, date = Date._to_array_extended_ISO8601(d, options)
|
98
99
|
|
99
100
|
# extended date & time format (JIS X0301)
|
100
|
-
when /^(\[[^\]]+\]|[^-+\d]+)([-+*&%@!>=<?\dW.\(\)]+)?(?:(T([:*=.,\d]+)?)([A-Z]+|[-+][:\d]+)?)?$/
|
101
|
-
era, d, t, time, clock = $~[1..
|
101
|
+
when /^((.+::)?(\[[^\]]+\]|[^-+\d]+))([-+*&%@!>=<?\dW.\(\)]+)?(?:(T([:*=.,\d]+)?)([A-Z]+|[-+][:\d]+)?)?$/
|
102
|
+
era, parent, child, d, t, time, clock = $~[1..7]
|
102
103
|
format, date, era = Date._to_array_extended_X0301(d, era, options)
|
103
104
|
era ||= options[:era_name] if (d =~ /\./)
|
104
105
|
|
@@ -124,46 +125,69 @@ module When
|
|
124
125
|
#
|
125
126
|
class Date < DateTime
|
126
127
|
|
128
|
+
# @private
|
129
|
+
Extra_Year_Digits = Hash.new {|hash, key|
|
130
|
+
ex = (key || 1).to_i
|
131
|
+
hash[key] =
|
132
|
+
if ex > 0
|
133
|
+
[
|
134
|
+
/^(\d{2})$/,
|
135
|
+
/^([-+]\d{#{4+ex}})(\d{2})(\d{2})$/,
|
136
|
+
/^([-+]\d{#{4+ex}})-(\d{2})$/,
|
137
|
+
/^([-+]\d{#{4+ex}})$/,
|
138
|
+
/^([-+]\d{#{4+ex}})W(\d{2})(\d{1})?$/,
|
139
|
+
/^([+]\d{#{2+ex}})$/,
|
140
|
+
/^([-]\d{#{2+ex}})$/,
|
141
|
+
/^([-+]\d{#{4+ex}})(\d{3})$/
|
142
|
+
]
|
143
|
+
elsif ex == 0
|
144
|
+
[/^(\d{2})$/] + [/^(\d{4})$/] * 6
|
145
|
+
else
|
146
|
+
[/^(\d{4})$/] * 7
|
147
|
+
end
|
148
|
+
}
|
149
|
+
|
127
150
|
class << self
|
128
151
|
# ISO 8601 基本形式の表現を分解して配列化する
|
129
152
|
def _to_array_basic_ISO8601(date, options={})
|
130
153
|
by, bm, bd = options[:abbr]
|
154
|
+
extra_reg = Extra_Year_Digits[options[:extra_year_digits]]
|
131
155
|
case date
|
132
|
-
when nil
|
133
|
-
when /^(\d{4})(\d{2})(\d{2})$/
|
134
|
-
when /^(\d{4})-(\d{2})$/
|
135
|
-
when /^(\d{4})$/
|
136
|
-
when
|
137
|
-
when /^(\d{4})(\d{3})$/
|
138
|
-
when /^(\d{4})W(\d{2})(\d{1})?$/
|
139
|
-
when
|
140
|
-
when
|
141
|
-
when
|
142
|
-
when
|
143
|
-
when
|
144
|
-
when
|
145
|
-
when
|
146
|
-
else
|
156
|
+
when nil ; return nil
|
157
|
+
when /^(\d{4})(\d{2})(\d{2})$/ ; return nil, [$1.to_i, $2.to_i, $3.to_i] # 5.2.1.1
|
158
|
+
when /^(\d{4})-(\d{2})$/ ; return nil, [$1.to_i, $2.to_i] # 5.2.1.2
|
159
|
+
when /^(\d{4})$/ ; return nil, [$1.to_i] # 5.2.1.2
|
160
|
+
when extra_reg[0] ; return :century,[$1.to_i * 100] # 5.2.1.2
|
161
|
+
when /^(\d{4})(\d{3})$/ ; return :day, [$1.to_i, $2.to_i] # 5.2.2.1
|
162
|
+
when /^(\d{4})W(\d{2})(\d{1})?$/ ; return :week, [$1.to_i, $2.to_i, _int($3)] # 5.2.3.1-2
|
163
|
+
when extra_reg[1] ; return nil, [$1.to_i, $2.to_i, $3.to_i] # 5.2.1.4 a)
|
164
|
+
when extra_reg[2] ; return nil, [$1.to_i, $2.to_i] # 5.2.1.4 b)
|
165
|
+
when extra_reg[3] ; return nil, [$1.to_i] # 5.2.1.4 c)
|
166
|
+
when extra_reg[4] ; return :week, [$1.to_i, $2.to_i, _int($3)] # 5.2.3.4 a-b)
|
167
|
+
when extra_reg[5] ; return :century,[$1.to_i * 100] # 5.2.1.4 d)
|
168
|
+
when extra_reg[6] ; return :century,[$1.to_i * 100] unless by # 5.2.1.4 d)
|
169
|
+
when extra_reg[7] ; return :day, [$1.to_i, $2.to_i] # 5.2.2.3 a)
|
170
|
+
else ; raise ArgumentError, "Wrong date format" unless by
|
147
171
|
end
|
148
172
|
|
149
173
|
by = by.to_i
|
150
174
|
case date
|
151
|
-
when /^(\d{2})(\d{2})(\d{2})$/
|
152
|
-
when /^-(\d{2})(\d{2})?$/
|
153
|
-
when /^--(\d{2})(\d{2})?$/
|
154
|
-
when /^(\d{2})(\d{3})$/
|
155
|
-
when /^-(\d{3})$/
|
156
|
-
when /^(\d{2})W(\d{2})(\d{1})?$/
|
157
|
-
when /^-(\d{1})W(\d{2})(\d{1})?$/
|
158
|
-
when /^-W(\d{2})(\d{1})?$/
|
159
|
-
else
|
175
|
+
when /^(\d{2})(\d{2})(\d{2})$/ ; return nil, [_century($1,by), $2.to_i, $3.to_i] # 5.2.1.3 a)
|
176
|
+
when /^-(\d{2})(\d{2})?$/ ; return nil, [_century($1,by), _int($2)] # 5.2.1.3 b-c)
|
177
|
+
when /^--(\d{2})(\d{2})?$/ ; return nil, [by, $1.to_i, _int($2)] # 5.2.1.3 d-e)
|
178
|
+
when /^(\d{2})(\d{3})$/ ; return :day, [_century($1,by), $2.to_i] # 5.2.2.2 a)
|
179
|
+
when /^-(\d{3})$/ ; return :day, [by, $1.to_i] # 5.2.2.2 b)
|
180
|
+
when /^(\d{2})W(\d{2})(\d{1})?$/ ; return :week, [_century($1,by), $2.to_i, _int($3)] # 5.2.3.3 a-b)
|
181
|
+
when /^-(\d{1})W(\d{2})(\d{1})?$/ ; return :week, [_decade($1,by), $2.to_i, _int($3)] # 5.2.3.3 c-d)
|
182
|
+
when /^-W(\d{2})(\d{1})?$/ ; return :week, [by, $1.to_i, _int($2)] # 5.2.3.3 e-f)
|
183
|
+
else ; raise ArgumentError, "Wrong date format" unless bm
|
160
184
|
end
|
161
185
|
|
162
186
|
bm = bm.to_i
|
163
187
|
case date
|
164
|
-
when /^---(\d{2})$/
|
165
|
-
when /^-W-(\d{1})$/
|
166
|
-
when /^----$/
|
188
|
+
when /^---(\d{2})$/ ; return nil, [by, bm, $1.to_i] # 5.2.1.3 f)
|
189
|
+
when /^-W-(\d{1})$/ ; return :week, [by, bm, $1.to_i] # 5.2.3.3 g)
|
190
|
+
when /^----$/ ; return nil, [by, bm, bd.to_i] if bd # extension
|
167
191
|
end
|
168
192
|
|
169
193
|
raise ArgumentError, "Wrong date format: #{date}"
|
@@ -402,15 +426,7 @@ module When
|
|
402
426
|
def to_m17n
|
403
427
|
self
|
404
428
|
end
|
405
|
-
|
406
|
-
#
|
407
|
-
# 識別文字列
|
408
|
-
#
|
409
|
-
# @return [String]
|
410
|
-
#
|
411
|
-
def label
|
412
|
-
@label || to_s
|
413
|
-
end
|
429
|
+
alias :label :to_m17n
|
414
430
|
|
415
431
|
#
|
416
432
|
# _m17n_form のための要素生成 - 何もしないで自身を返す
|
@@ -463,22 +479,39 @@ module When
|
|
463
479
|
rest, options = _attributes(args)
|
464
480
|
_sequence
|
465
481
|
|
466
|
-
|
467
|
-
_copy_all(_pool[@label])
|
482
|
+
return _copy_all(_pool[@label.to_s]) if _pool[@label.to_s]
|
468
483
|
|
484
|
+
case rest[0]
|
485
|
+
when When::Parts::Resource::ContentLine
|
486
|
+
content, namespace = rest
|
487
|
+
namespace ||= {}
|
488
|
+
names = []
|
489
|
+
locale = []
|
490
|
+
begin
|
491
|
+
loc = content.attribute['language'].object
|
492
|
+
locale << [nil, loc, namespace[loc]]
|
493
|
+
name = content.object
|
494
|
+
ref = content.attribute['reference'] || content.attribute['url']
|
495
|
+
name += '=' + (/^NUL$/i =~ ref.object ? '' : ref.object) if ref
|
496
|
+
names << name
|
497
|
+
end while (content = content.same_altid)
|
498
|
+
@names ||= names.reverse
|
499
|
+
@namespace ||= namespace if namespace.kind_of?(Hash)
|
500
|
+
@locale ||= locale.reverse
|
501
|
+
@label = self
|
502
|
+
when nil ;
|
469
503
|
else
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
end
|
476
|
-
@namespace ||= {}
|
477
|
-
@locale ||= []
|
478
|
-
|
479
|
-
@code_space = @namespace['']
|
480
|
-
self[0..-1] = _names(@names, @namespace, @locale)
|
504
|
+
names, namespace, locale = rest
|
505
|
+
@names = names if names
|
506
|
+
@namespace ||= Parts::Locale._namespace(namespace) if namespace
|
507
|
+
@locale ||= Parts::Locale._locale(locale) if locale
|
508
|
+
@label = self
|
481
509
|
end
|
510
|
+
@namespace ||= {}
|
511
|
+
@locale ||= []
|
512
|
+
|
513
|
+
@code_space = @namespace['']
|
514
|
+
self[0..-1] = _names(@names, @namespace, @locale)
|
482
515
|
end
|
483
516
|
end
|
484
517
|
|
@@ -498,17 +531,6 @@ module When
|
|
498
531
|
#
|
499
532
|
attr_reader :label
|
500
533
|
|
501
|
-
# オブジェクトのtap
|
502
|
-
unless method_defined?(:tap)
|
503
|
-
#
|
504
|
-
# tap - yield による処理のチェーン化
|
505
|
-
#
|
506
|
-
def tap
|
507
|
-
yield(self)
|
508
|
-
self
|
509
|
-
end
|
510
|
-
end
|
511
|
-
|
512
534
|
private
|
513
535
|
|
514
536
|
# オブジェクトの初期化
|
@@ -567,7 +589,12 @@ module When
|
|
567
589
|
# 処理を @name (type: When::BasicTypes::Code) に委譲する
|
568
590
|
#
|
569
591
|
def method_missing(name, *args, &block)
|
570
|
-
|
592
|
+
self.class.module_eval %Q{
|
593
|
+
def #{name}(*args, &block)
|
594
|
+
@name.send("#{name}", *args, &block)
|
595
|
+
end
|
596
|
+
} unless When::Parts::MethodCash.escape(name)
|
597
|
+
@name.send(name, *args, &block)
|
571
598
|
end
|
572
599
|
end
|
573
600
|
end
|
@@ -608,7 +635,14 @@ module When
|
|
608
635
|
# 処理を @temporal_extent (type: When::TM::Period) に委譲する
|
609
636
|
#
|
610
637
|
def method_missing(name, *args, &block)
|
611
|
-
|
638
|
+
self.class.module_eval %Q{
|
639
|
+
def #{name}(*args, &block)
|
640
|
+
list = args.map {|arg| arg.kind_of?(self.class) ? arg.temporal_extent : arg}
|
641
|
+
@temporal_extent.send("#{name}", *list, &block)
|
642
|
+
end
|
643
|
+
} unless When::Parts::MethodCash.escape(name)
|
644
|
+
list = args.map {|arg| arg.kind_of?(self.class) ? arg.temporal_extent : arg}
|
645
|
+
@temporal_extent.send(name, *list, &block)
|
612
646
|
end
|
613
647
|
end
|
614
648
|
end
|