when_exe 0.3.6 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +171 -0
- data/lib/when_exe.rb +78 -47
- data/lib/when_exe/basictypes.rb +752 -747
- data/lib/when_exe/calendarnote.rb +805 -801
- data/lib/when_exe/calendartypes.rb +1583 -1531
- data/lib/when_exe/coordinates.rb +16 -15
- data/lib/when_exe/core/duration.rb +114 -110
- data/lib/when_exe/core/extension.rb +504 -504
- data/lib/when_exe/ephemeris.rb +1917 -1913
- data/lib/when_exe/ephemeris/moon.rb +333 -333
- data/lib/when_exe/ephemeris/notes.rb +389 -387
- data/lib/when_exe/ephemeris/planets.rb +585 -585
- data/lib/when_exe/ephemeris/sun.rb +214 -214
- data/lib/when_exe/googlecalendar.rb +144 -140
- data/lib/when_exe/icalendar.rb +1636 -1636
- data/lib/when_exe/inspect.rb +46 -22
- data/lib/when_exe/locales/akt.rb +176 -176
- data/lib/when_exe/locales/encoding_conversion.rb +134 -126
- data/lib/when_exe/locales/iast.rb +90 -90
- data/lib/when_exe/locales/locale.rb +750 -746
- data/lib/when_exe/locales/transliteration_table.rb +62 -62
- data/lib/when_exe/mini_application.rb +307 -305
- data/lib/when_exe/parts/enumerator.rb +2 -2
- data/lib/when_exe/parts/geometric_complex.rb +397 -397
- data/lib/when_exe/parts/method_cash.rb +224 -224
- data/lib/when_exe/parts/resource.rb +1069 -1071
- data/lib/when_exe/parts/timezone.rb +240 -230
- data/lib/when_exe/region/armenian.rb +56 -56
- data/lib/when_exe/region/babylonian.rb +405 -0
- data/lib/when_exe/region/bahai.rb +146 -146
- data/lib/when_exe/region/balinese.rb +622 -622
- data/lib/when_exe/region/chinese.rb +95 -25
- data/lib/when_exe/region/chinese/calendars.rb +1016 -1016
- data/lib/when_exe/region/chinese/epochs.rb +1 -1
- data/lib/when_exe/region/chinese/twins.rb +803 -795
- data/lib/when_exe/region/christian.rb +824 -824
- data/lib/when_exe/region/coptic.rb +106 -87
- data/lib/when_exe/region/discordian.rb +225 -225
- data/lib/when_exe/region/far_east.rb +188 -188
- data/lib/when_exe/region/french.rb +56 -56
- data/lib/when_exe/region/geologicalage.rb +639 -639
- data/lib/when_exe/region/goddess.rb +58 -58
- data/lib/when_exe/region/indian.rb +1254 -1251
- data/lib/when_exe/region/iranian.rb +8 -8
- data/lib/when_exe/region/islamic.rb +3 -3
- data/lib/when_exe/region/japanese.rb +93 -99
- data/lib/when_exe/region/japanese/calendars.rb +396 -397
- data/lib/when_exe/region/japanese/epochs.rb +26 -26
- data/lib/when_exe/region/japanese/nihon_shoki.rb +71 -71
- data/lib/when_exe/region/japanese/notes.rb +1383 -1386
- data/lib/when_exe/region/japanese/residues.rb +1306 -1306
- data/lib/when_exe/region/japanese/twins.rb +225 -225
- data/lib/when_exe/region/japanese/weeks.rb +112 -0
- data/lib/when_exe/region/javanese.rb +230 -230
- data/lib/when_exe/region/jewish.rb +126 -126
- data/lib/when_exe/region/korean.rb +378 -378
- data/lib/when_exe/region/m17n.rb +114 -113
- data/lib/when_exe/region/martian.rb +258 -255
- data/lib/when_exe/region/mayan.rb +32 -32
- data/lib/when_exe/region/residue.rb +89 -89
- data/lib/when_exe/region/roman.rb +36 -24
- data/lib/when_exe/region/ryukyu.rb +97 -97
- data/lib/when_exe/region/shire.rb +240 -240
- data/lib/when_exe/region/soviet.rb +209 -0
- data/lib/when_exe/region/symmetry.rb +50 -50
- data/lib/when_exe/region/thai.rb +336 -335
- data/lib/when_exe/region/tibetan.rb +316 -315
- data/lib/when_exe/region/vietnamese.rb +440 -439
- data/lib/when_exe/region/weekdate.rb +80 -80
- data/lib/when_exe/region/world.rb +175 -175
- data/lib/when_exe/region/yerm.rb +14 -14
- data/lib/when_exe/region/zoroastrian.rb +203 -203
- data/lib/when_exe/timestandard.rb +707 -681
- data/lib/when_exe/tmduration.rb +338 -330
- data/lib/when_exe/tmobjects.rb +1346 -1325
- data/lib/when_exe/tmposition.rb +2115 -2072
- data/lib/when_exe/tmreference.rb +1693 -1669
- data/lib/when_exe/version.rb +1 -1
- data/link_to_online_documents +1 -1
- data/test/examples/JapanHolidaysRFC6350.ics +1 -1
- data/test/test.rb +67 -61
- data/test/test/basictypes.rb +409 -409
- data/test/test/calendarnote.rb +86 -69
- data/test/test/calendartypes.rb +97 -97
- data/test/test/coordinates.rb +396 -396
- data/test/test/ephemeris.rb +83 -74
- data/test/test/ephemeris/moon.rb +14 -14
- data/test/test/ephemeris/planets.rb +14 -14
- data/test/test/ephemeris/sun.rb +14 -14
- data/test/test/googlecalendar.rb +194 -176
- data/test/test/icalendar.rb +867 -858
- data/test/test/inspect.rb +117 -117
- data/test/test/parts.rb +487 -487
- data/test/test/region/balinese.rb +34 -0
- data/test/test/region/chinese.rb +218 -206
- data/test/test/region/christian.rb +245 -245
- data/test/test/region/coptic.rb +27 -27
- data/test/test/region/french.rb +33 -33
- data/test/test/region/geologicalage.rb +17 -17
- data/test/test/region/indian.rb +57 -57
- data/test/test/region/iran.rb +54 -54
- data/test/test/region/islamic.rb +18 -18
- data/test/test/region/japanese.rb +237 -219
- data/test/test/region/jewish.rb +61 -61
- data/test/test/region/m17n.rb +184 -184
- data/test/test/region/mayan.rb +195 -195
- data/test/test/region/residue.rb +147 -139
- data/test/test/region/thai.rb +116 -116
- data/test/test/region/tibetan.rb +30 -30
- data/test/test/region/vietnamese.rb +102 -102
- data/test/test/region/yerm.rb +146 -146
- data/test/test/timestandard.rb +81 -81
- data/test/test/tmobjects.rb +328 -328
- data/test/test/tmposition.rb +397 -284
- data/test/test/tmreference.rb +157 -157
- metadata +13 -10
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 61d0b1c1a37dc54c8a87505b8ec22282052f56ee
|
|
4
|
+
data.tar.gz: 88aa53ad73c559c3d40f9992c4bd932f5292a48c
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: c1d4d428fb2704611c027aae6f1d1301da50a69e76e386ed7ed56a2a9079c5f65d89b88b6084848cc9f04ebbfd2c4f5aa22e4bc26499c554179000f70d50cb20
|
|
7
|
+
data.tar.gz: cd39d0b62c40b1628c6ce1a06620064f095bcdd5115bafda9a1d297595c915d44c29b2fe0036ad3b7d582496fbb13e1b8d38d194b80b1bee57e06439a89b98f4
|
data/README.md
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
when_exe - A multicultural and multilingualized calendar library
|
|
2
|
+
================================================================
|
|
3
|
+
|
|
4
|
+
[](http://badge.fury.io/rb/when_exe)
|
|
5
|
+
|
|
6
|
+
[when_exe](http://rubygems.org/gems/when_exe) is a multicultural and multilingualized calendar library based on ISO 8601, ISO 19108, RFC 5545 and RFC6350.
|
|
7
|
+
|
|
8
|
+
Installation
|
|
9
|
+
------------
|
|
10
|
+
|
|
11
|
+
The when_exe gem can be installed by running:
|
|
12
|
+
|
|
13
|
+
gem install when_exe
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
Documentation
|
|
17
|
+
-------------
|
|
18
|
+
|
|
19
|
+
API documentation for when_exe is available on [RubyDoc.info](http://rubydoc.info/gems/when_exe/frames).
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
License
|
|
23
|
+
-------
|
|
24
|
+
|
|
25
|
+
This beta version's license is limited. Please see [LICENSE.txt](https://github.com/suchowan/when_exe/blob/master/LICENSE.txt) for details.
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
Source Code
|
|
29
|
+
-----------
|
|
30
|
+
|
|
31
|
+
Source code for when_exe is available on [GitHub](https://github.com/suchowan/when_exe).
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
Example Usage
|
|
35
|
+
-------------
|
|
36
|
+
|
|
37
|
+
require 'when_exe'
|
|
38
|
+
|
|
39
|
+
# When::TM::CalDate
|
|
40
|
+
|
|
41
|
+
gregorian_date = When.tm_pos(2014, 8, 1)
|
|
42
|
+
p gregorian_date #=> 2014-08-01
|
|
43
|
+
p When.when?('2014-08-01') #=> 2014-08-01, the same date
|
|
44
|
+
p gregorian_date.to_i #=> 2456871, Julian Day Number(Integer)
|
|
45
|
+
p gregorian_date.to_f #=> 2456871.0, at noon for UTC
|
|
46
|
+
p gregorian_date.class #=> When::TM::CalDate
|
|
47
|
+
p gregorian_date.frame.iri #=> "http://hosi.org/When/CalendarTypes/Gregorian"
|
|
48
|
+
puts gregorian_date.name(When::MONTH) / 'en' #=> August
|
|
49
|
+
puts gregorian_date.name(When::MONTH) / 'fr' #=> août
|
|
50
|
+
puts gregorian_date.name(When::MONTH) / 'ar' #=> اغسطس
|
|
51
|
+
p gregorian_date.easter #=> 2014-04-20
|
|
52
|
+
p gregorian_date.is?('Easter') #=> false
|
|
53
|
+
p When.tm_pos(2014, 4, 20).is?('Easter') #=> true
|
|
54
|
+
|
|
55
|
+
islamic_date = When::TabularIslamic ^ gregorian_date
|
|
56
|
+
p islamic_date #=> 1435-10-04
|
|
57
|
+
p islamic_date.frame.iri #=> ""http://hosi.org/When/CalendarTypes/TabularIslamic"
|
|
58
|
+
puts islamic_date.name(When::MONTH) / 'en' #=> Shawwal
|
|
59
|
+
puts islamic_date.name(When::MONTH) / 'ar' #=> شوال
|
|
60
|
+
|
|
61
|
+
# When::TM::DateAndTime
|
|
62
|
+
|
|
63
|
+
gregorian_date = When.tm_pos(2014, 8, 1, 9, 0, 0, :clock=>'+09:00')
|
|
64
|
+
p gregorian_date #=> 2014-08-01T09:00:00+09:00
|
|
65
|
+
p When.when?('2014-08-01T09:00:00+09:00') #=> 2014-08-01T09:00:00+09:00, the same date
|
|
66
|
+
p gregorian_date.to_i #=> 2456871, Julian Day Number(Integer)
|
|
67
|
+
p gregorian_date.to_f #=> 2456870.5 at 09:00:00 of Timezone +09:00
|
|
68
|
+
p gregorian_date.class #=> When::TM::DateAndTime
|
|
69
|
+
p gregorian_date.frame.iri #=> "http://hosi.org/When/CalendarTypes/Gregorian"
|
|
70
|
+
p gregorian_date.clk_time.class #=> When::TM::ClockTime
|
|
71
|
+
p gregorian_date.clk_time.frame.iri #=> "http://hosi.org/When/TM/Clock?label=+09:00"
|
|
72
|
+
|
|
73
|
+
gregorian_date = When.tm_pos(2014, 8, 1, 9, 0, 0, :clock=>'+09:00',
|
|
74
|
+
:long=>'139.413012E', :lat=>'35.412222N')
|
|
75
|
+
p gregorian_date #=> 2014-08-01T09:00:00+09:00
|
|
76
|
+
p gregorian_date.location.iri #=> "http://hosi.org/When/Coordinates/Spatial?long=139.413012E&lat=35.412222N&alt=0"
|
|
77
|
+
p gregorian_date.sunrise.floor(When::MINUTE) #=> 2014-08-01T04:48+09:00
|
|
78
|
+
p gregorian_date.sunset.floor(When::MINUTE) #=> 2014-08-01T18:46+09:00
|
|
79
|
+
|
|
80
|
+
darian_date = When::Darian ^ gregorian_date
|
|
81
|
+
p darian_date #=> 0216-13-23T15:12:11MTC
|
|
82
|
+
p darian_date.to_i #=> 49974, Serial Day Number(Integer)
|
|
83
|
+
p darian_date.to_f #=> 49974.13346485421
|
|
84
|
+
p darian_date.frame.iri #=> "http://hosi.org/When/CalendarTypes/Darian"
|
|
85
|
+
p darian_date.clk_time.frame.iri #=> "http://hosi.org/When/CalendarTypes/MTC"
|
|
86
|
+
p darian_date.time_standard.iri #=> "http://hosi.org/When/TimeStandard/MartianTimeCoordinated?location=(_l:long=0&datum=Mars)"
|
|
87
|
+
|
|
88
|
+
# When::TM::CalendarEra
|
|
89
|
+
|
|
90
|
+
babylonian_date = When.tm_pos('NebuchadnezzarII', 1, 1, 1)
|
|
91
|
+
p babylonian_date #=> NebuchadnezzarII01(-603).01.01
|
|
92
|
+
p When.when?('NebuchadnezzarII1.1.1') #=> NebuchadnezzarII01(-603).01.01, the same date
|
|
93
|
+
p babylonian_date.to_i #=> 1500904, Julian Day Number(Integer)
|
|
94
|
+
p When.era('NebuchadnezzarII') #=> [_e:AncientOrient::Neo-Babylonian::NebuchadnezzarII]
|
|
95
|
+
p When.era('NebuchadnezzarII')[0] ^ 1500904 #=> NebuchadnezzarII01(-603).01.01, the same date
|
|
96
|
+
p babylonian_date.to_f #=> 1500904.0, at noon for UTC
|
|
97
|
+
p babylonian_date.frame.iri #=> "http://hosi.org/When/CalendarTypes/BabylonianPD"
|
|
98
|
+
p babylonian_date.calendar_era.iri #=> "http://hosi.org/When/TM/CalendarEra/AncientOrient::Neo-Babylonian::NebuchadnezzarII"
|
|
99
|
+
|
|
100
|
+
babylonian_date = When.when?('NebuchadnezzarII1.1.1T18:13:00',
|
|
101
|
+
:clock=>'+03:00?long=45&lat=32&border=Sunset')
|
|
102
|
+
4.times do
|
|
103
|
+
p [babylonian_date , babylonian_date .to_i] #=>
|
|
104
|
+
# [NebuchadnezzarII01(-603).01.01T:18:13:00+03:00, 1500904]
|
|
105
|
+
# [NebuchadnezzarII01(-603).01.01T:18:14:00+03:00, 1500904]
|
|
106
|
+
# [NebuchadnezzarII01(-603).01.02T*18:15:00+03:00, 1500905]
|
|
107
|
+
# [NebuchadnezzarII01(-603).01.02T*18:16:00+03:00, 1500905]
|
|
108
|
+
babylonian_date += When::PT1M
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# TZInfo
|
|
112
|
+
# https://rubygems.org/gems/tzinfo is required for this section's operations.
|
|
113
|
+
# Please install tzinfo before operation.
|
|
114
|
+
|
|
115
|
+
gregorian_date = When.tm_pos(2014, 8, 1, 9, 0, 0, :tz=>'Asia/Tokyo')
|
|
116
|
+
p gregorian_date #=> 2014-08-01T09:00:00+09:00
|
|
117
|
+
p gregorian_date.location.iri #=> "http://hosi.org/When/Coordinates/Spatial?long=139.4441E&lat=35.3916N&label=Asia/Tokyo"
|
|
118
|
+
p gregorian_date.sunrise.floor(When::MINUTE) #=> 2014-08-01T04:48+09:00
|
|
119
|
+
p gregorian_date.sunset.floor(When::MINUTE) #=> 2014-08-01T18:45+09:00
|
|
120
|
+
|
|
121
|
+
jst = When.tm_pos(1997, 4, 6, 15, 30, 00, :tz=>'Asia/Tokyo')
|
|
122
|
+
p jst #=> 1997-04-06T15:30:00+09:00
|
|
123
|
+
est = When.Clock('America/New_York') ^ jst
|
|
124
|
+
p est #=> 1997-04-06T01:30:00-05:00
|
|
125
|
+
jst = When.tm_pos(1997, 4, 6, 16, 30, 00, :tz=>'Asia/Tokyo')
|
|
126
|
+
p jst #=> 1997-04-06T16:30:00+09:00
|
|
127
|
+
edt = When.Clock('America/New_York') ^ jst
|
|
128
|
+
p edt #=> 1997-04-06T03:30:00-04:00
|
|
129
|
+
|
|
130
|
+
p When.when?('TZID=America/New_York:1997-10-26T01:30') #=> 1997-10-26T01:30-04:00
|
|
131
|
+
p When.when?('TZID=America/New_York:1997-10-26T01=30') #=> 1997-10-26T01:30-05:00
|
|
132
|
+
p When.when?('TZID=America/New_York:1997-10-26T02:30') #=> 1997-10-26T02:30-05:00
|
|
133
|
+
p When.when?('TZID=America/New_York:1997-10-26T03:30') #=> 1997-10-26T03:30-05:00
|
|
134
|
+
|
|
135
|
+
# Google Calendar
|
|
136
|
+
# https://github.com/suchowan/gcalapi is required for this section's operations.
|
|
137
|
+
# Please install gcalapi before operation.
|
|
138
|
+
# Please replace xxxxxxxx and ******** to valid pair of id and password.
|
|
139
|
+
|
|
140
|
+
service = GoogleCalendar::Service.new('xxxxxxxx@gmail.com', '********')
|
|
141
|
+
feed = "http://www.google.com/calendar/feeds/%s__%s%%40holiday.calendar.google.com/public/full" %
|
|
142
|
+
['japanese', 'ja']
|
|
143
|
+
gcal = GoogleCalendar::Calendar::new(service, feed)
|
|
144
|
+
gcal.enum_for({'start-min'=>'2014-01-01', 'start-max'=>'2015-01-01',
|
|
145
|
+
'orderby'=>'starttime', 'sortorder'=>'a'
|
|
146
|
+
}).each do |range|
|
|
147
|
+
puts '%s - %s' % [range, range.events[0].summary] #=>
|
|
148
|
+
# 2014-01-01T00:00:00.00+09:00...2014-01-02T00:00:00.00+09:00 - 元日
|
|
149
|
+
# 2014-01-02T00:00:00.00+09:00...2014-01-03T00:00:00.00+09:00 - 銀行休業日
|
|
150
|
+
# 2014-01-03T00:00:00.00+09:00...2014-01-04T00:00:00.00+09:00 - 銀行休業日
|
|
151
|
+
# 2014-01-13T00:00:00.00+09:00...2014-01-14T00:00:00.00+09:00 - 成人の日
|
|
152
|
+
# 2014-02-11T00:00:00.00+09:00...2014-02-12T00:00:00.00+09:00 - 建国記念の日
|
|
153
|
+
# 2014-03-21T00:00:00.00+09:00...2014-03-22T00:00:00.00+09:00 - 春分の日
|
|
154
|
+
# 2014-04-29T00:00:00.00+09:00...2014-04-30T00:00:00.00+09:00 - 昭和の日
|
|
155
|
+
# 2014-05-03T00:00:00.00+09:00...2014-05-04T00:00:00.00+09:00 - 憲法記念日
|
|
156
|
+
# 2014-05-04T00:00:00.00+09:00...2014-05-05T00:00:00.00+09:00 - みどりの日
|
|
157
|
+
# 2014-05-05T00:00:00.00+09:00...2014-05-06T00:00:00.00+09:00 - こどもの日
|
|
158
|
+
# 2014-05-06T00:00:00.00+09:00...2014-05-07T00:00:00.00+09:00 - みどりの日 振替休日
|
|
159
|
+
# 2014-07-21T00:00:00.00+09:00...2014-07-22T00:00:00.00+09:00 - 海の日
|
|
160
|
+
# 2014-09-15T00:00:00.00+09:00...2014-09-16T00:00:00.00+09:00 - 敬老の日
|
|
161
|
+
# 2014-09-23T00:00:00.00+09:00...2014-09-24T00:00:00.00+09:00 - 秋分の日
|
|
162
|
+
# 2014-10-13T00:00:00.00+09:00...2014-10-14T00:00:00.00+09:00 - 体育の日
|
|
163
|
+
# 2014-11-03T00:00:00.00+09:00...2014-11-04T00:00:00.00+09:00 - 文化の日
|
|
164
|
+
# 2014-11-23T00:00:00.00+09:00...2014-11-24T00:00:00.00+09:00 - 勤労感謝の日
|
|
165
|
+
# 2014-11-24T00:00:00.00+09:00...2014-11-25T00:00:00.00+09:00 - 勤労感謝の日 振替休日
|
|
166
|
+
# 2014-12-23T00:00:00.00+09:00...2014-12-24T00:00:00.00+09:00 - 天皇誕生日
|
|
167
|
+
# 2014-12-25T00:00:00.00+09:00...2014-12-26T00:00:00.00+09:00 - クリスマス
|
|
168
|
+
# 2014-12-31T00:00:00.00+09:00...2015-01-01T00:00:00.00+09:00 - 大晦日
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
For further detail, please refer to the [when_exe Wiki](http://www2u.biglobe.ne.jp/~suchowan/when_exe_wiki.html) pages.
|
data/lib/when_exe.rb
CHANGED
|
@@ -48,25 +48,35 @@ module When
|
|
|
48
48
|
#
|
|
49
49
|
attr_reader :multi_thread
|
|
50
50
|
|
|
51
|
+
#
|
|
52
|
+
# Logger オブジェクト
|
|
53
|
+
#
|
|
54
|
+
# @return [Logger]
|
|
55
|
+
#
|
|
56
|
+
attr_accessor :logger
|
|
57
|
+
private :logger=
|
|
58
|
+
|
|
51
59
|
# Initializations
|
|
52
60
|
#
|
|
53
61
|
# @param [Hash] options 以下の通り
|
|
54
|
-
# @option options [When::Parts::Timezone::Base] :local
|
|
55
|
-
# @option options [When::Coordinates::Spatial] :location
|
|
56
|
-
# @option options [When::TM::IntervalLength] :until
|
|
57
|
-
# @option options [Hash{String=>String}] :alias
|
|
58
|
-
# @option options [String] :
|
|
59
|
-
# @option options [Hash{String=>String}] :unification
|
|
60
|
-
# @option options [Array<String>] :order
|
|
61
|
-
# @option options [Hash{String=>Array, String}] :format
|
|
62
|
-
# @option options [Array<Array>] :leap_seconds
|
|
63
|
-
# @option options [String] :base_uri
|
|
64
|
-
# @option options [String]
|
|
65
|
-
# @option options [
|
|
66
|
-
# @option options [Boolean] :direct
|
|
67
|
-
# @option options [Hash{Symbol=>boolean}] :escape
|
|
68
|
-
# @option options [false, nil] :escape
|
|
69
|
-
# @option options [true] :escape
|
|
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 オブジェクト
|
|
70
80
|
#
|
|
71
81
|
# @return [void]
|
|
72
82
|
#
|
|
@@ -76,6 +86,7 @@ module When
|
|
|
76
86
|
#
|
|
77
87
|
def _setup_(options={})
|
|
78
88
|
@multi_thread = options[:multi_thread]
|
|
89
|
+
@logger = options[:logger]
|
|
79
90
|
Parts::MethodCash._setup_(options)
|
|
80
91
|
Parts::Resource._setup_(options)
|
|
81
92
|
Locale._setup_(options)
|
|
@@ -127,6 +138,8 @@ module When
|
|
|
127
138
|
# When 直下に定数として定義する時法・暦法など(暗黙的追加)
|
|
128
139
|
#
|
|
129
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
|
|
130
143
|
iri = Parts::Resource._abbreviation_to_iri(constant)
|
|
131
144
|
return _const_missing(constant) unless iri
|
|
132
145
|
resource = Parts::Resource._instance(iri)
|
|
@@ -146,7 +159,7 @@ module When
|
|
|
146
159
|
#
|
|
147
160
|
# ライブラリのあるディレクトリ
|
|
148
161
|
#
|
|
149
|
-
RootDir = File.dirname(__FILE__).sub(/\/[^\/]
|
|
162
|
+
RootDir = File.dirname(__FILE__).sub(/\/[^\/]*\z/,'')
|
|
150
163
|
|
|
151
164
|
require 'when_exe/version'
|
|
152
165
|
require 'when_exe/locales/locale'
|
|
@@ -202,7 +215,8 @@ module When
|
|
|
202
215
|
autoload :Iranian, 'when_exe/region/iranian'
|
|
203
216
|
autoload :Islamic, 'when_exe/region/islamic'
|
|
204
217
|
autoload :Jewish, 'when_exe/region/jewish'
|
|
205
|
-
autoload :
|
|
218
|
+
autoload :AncientOrient, 'when_exe/region/babylonian'
|
|
219
|
+
autoload :Armenian, 'when_exe/region/armenian'
|
|
206
220
|
autoload :Roman, 'when_exe/region/roman'
|
|
207
221
|
autoload :Coptic, 'when_exe/region/coptic'
|
|
208
222
|
autoload :French, 'when_exe/region/french'
|
|
@@ -255,6 +269,11 @@ module When
|
|
|
255
269
|
autoload :EphemerisBasedIslamic, 'when_exe/region/islamic'
|
|
256
270
|
autoload :Jewish, 'when_exe/region/jewish'
|
|
257
271
|
autoload :Armenian, 'when_exe/region/armenian'
|
|
272
|
+
autoload :Babylonian, 'when_exe/region/babylonian'
|
|
273
|
+
autoload :BabylonianPD, 'when_exe/region/babylonian'
|
|
274
|
+
autoload :Seleucid, 'when_exe/region/babylonian'
|
|
275
|
+
autoload :SeleucidPD, 'when_exe/region/babylonian'
|
|
276
|
+
autoload :Ptolemaic, 'when_exe/region/coptic'
|
|
258
277
|
autoload :Coptic, 'when_exe/region/coptic'
|
|
259
278
|
autoload :JulianA, 'when_exe/region/roman'
|
|
260
279
|
autoload :JulianB, 'when_exe/region/roman'
|
|
@@ -293,6 +312,8 @@ module When
|
|
|
293
312
|
autoload :LunarPhases, 'when_exe/ephemeris/notes'
|
|
294
313
|
autoload :Ephemeris, 'when_exe/ephemeris/notes'
|
|
295
314
|
autoload :Japanese, 'when_exe/region/japanese/notes'
|
|
315
|
+
autoload :CommonWithRokuyo, 'when_exe/region/japanese/weeks'
|
|
316
|
+
autoload :RokuyoWeek, 'when_exe/region/japanese/weeks'
|
|
296
317
|
autoload :Yis, 'when_exe/region/chinese'
|
|
297
318
|
autoload :Balinese, 'when_exe/region/balinese'
|
|
298
319
|
autoload :Javanese, 'when_exe/region/javanese'
|
|
@@ -301,6 +322,10 @@ module When
|
|
|
301
322
|
autoload :Roman, 'when_exe/region/roman'
|
|
302
323
|
autoload :Mayan, 'when_exe/region/mayan'
|
|
303
324
|
autoload :Discordian, 'when_exe/region/discordian'
|
|
325
|
+
autoload :CommonWithSovietFiveDay, 'when_exe/region/soviet'
|
|
326
|
+
autoload :SovietFiveDayWeek, 'when_exe/region/soviet'
|
|
327
|
+
autoload :CommonWithSovietSixDay, 'when_exe/region/soviet'
|
|
328
|
+
autoload :SovietSixDayWeek, 'when_exe/region/soviet'
|
|
304
329
|
# autoload :Yerm, 'when_exe/region/yerm'
|
|
305
330
|
autoload :WorldWeek, 'when_exe/region/world'
|
|
306
331
|
autoload :ShireWeek, 'when_exe/region/shire'
|
|
@@ -365,6 +390,7 @@ module When
|
|
|
365
390
|
autoload :Iranian, 'when_exe/region/iranian'
|
|
366
391
|
autoload :Hijra, 'when_exe/region/islamic'
|
|
367
392
|
autoload :Jewish, 'when_exe/region/jewish'
|
|
393
|
+
autoload :AncientOrient, 'when_exe/region/babylonian'
|
|
368
394
|
autoload :Roman, 'when_exe/region/roman'
|
|
369
395
|
autoload :Julian, 'when_exe/region/roman'
|
|
370
396
|
autoload :Pope, 'when_exe/region/pope'
|
|
@@ -373,8 +399,8 @@ module When
|
|
|
373
399
|
|
|
374
400
|
# Defualt search path for Epochs and Eras
|
|
375
401
|
DefaultEpochs = ['Common', 'ModernJapanese',
|
|
376
|
-
'Hijra', 'Jewish',
|
|
377
|
-
'Roman', 'Byzantine', 'LongCount',
|
|
402
|
+
'Hijra', 'Jewish', 'Iranian',
|
|
403
|
+
'Roman', 'Byzantine', 'AncientOrient', 'LongCount',
|
|
378
404
|
'BalineseLuniSolar', 'JavaneseLunar',
|
|
379
405
|
'Japanese', 'JapanesePrimeMinister', 'NihonKoki', 'NihonShoki',
|
|
380
406
|
'Chinese', 'Ryukyu', 'Vietnamese', 'Korean',
|
|
@@ -389,7 +415,8 @@ module When
|
|
|
389
415
|
['@ND', 'NaturalDisaster' ],
|
|
390
416
|
['@IY', 'InauspiciousYear'],
|
|
391
417
|
['@F', 'Foundation' ],
|
|
392
|
-
['@CR', 'CalendarReform' ]
|
|
418
|
+
['@CR', 'CalendarReform' ],
|
|
419
|
+
['@CE', 'CalendarEpoch' ]].map {|e|
|
|
393
420
|
[e[0], When::Parts::Resource._instance('EpochEvents::'+e[1], '_m:')]
|
|
394
421
|
}.flatten)]
|
|
395
422
|
|
|
@@ -397,17 +424,17 @@ module When
|
|
|
397
424
|
Common = [{}, self, [
|
|
398
425
|
'area:Common#{?Reform=Reform}',
|
|
399
426
|
['[BeforeCommonEra=en:BCE_(disambiguation),*alias:BCE]0.1.1'],
|
|
400
|
-
['[CommonEra=en:Common_Era,*alias:CE]1.1.1', '
|
|
401
|
-
['[CommonEra=en:Common_Era,*alias:CE]#{Reform:1582.10.15}', '
|
|
427
|
+
['[CommonEra=en:Common_Era,*alias:CE]1.1.1', '@CE', '01-01-01^Julian'],
|
|
428
|
+
['[CommonEra=en:Common_Era,*alias:CE]#{Reform:1582.10.15}', '@CR', '#{Reform:1582.10.15}^Gregorian']
|
|
402
429
|
]]
|
|
403
430
|
|
|
404
431
|
# Modern Japanese Eras after the calendar reform to the Gregorian Calendar
|
|
405
432
|
ModernJapanese = [self, [
|
|
406
433
|
'area:[ModernJapanese]',
|
|
407
|
-
['[M=,alias:明=ja
|
|
408
|
-
['[T=,alias:大=ja
|
|
409
|
-
['[S=,alias:昭=ja
|
|
410
|
-
['[H=,alias:平=ja
|
|
434
|
+
['[M=,alias:明=ja:%%<明治>]6.01.01', '@CR', '1873-01-01^Gregorian?note=Default'],
|
|
435
|
+
['[T=,alias:大=ja:%%<大正>]1.07.30', '@A', '1912-07-30'],
|
|
436
|
+
['[S=,alias:昭=ja:%%<昭和>]1.12.25', '@A', '1926-12-25'],
|
|
437
|
+
['[H=,alias:平=ja:%%<平成>]1.01.08', '@A', '1989-01-08']
|
|
411
438
|
]]
|
|
412
439
|
end
|
|
413
440
|
end
|
|
@@ -419,7 +446,7 @@ module When
|
|
|
419
446
|
|
|
420
447
|
# Generation of Temporal Objetct, duration or When::Parts::GeometricComplex
|
|
421
448
|
#
|
|
422
|
-
# @param [String] specification When.exe Standard Representation として解釈して生成する
|
|
449
|
+
# @param [String] specification When.exe Standard Representation または ユリウス日JDN として解釈して生成する
|
|
423
450
|
# @param [Numeric] specification ユリウス日として解釈して生成する
|
|
424
451
|
# @param [Array] specification 要素を個別に解釈して生成したオブジェクトのArrayを返す
|
|
425
452
|
# @param [When::TM::TemporalPosition, When::Parts::GeometricComplex] specification specificationをそのまま返す
|
|
@@ -434,14 +461,15 @@ module When
|
|
|
434
461
|
# フォーマットごとの処理
|
|
435
462
|
case specification
|
|
436
463
|
when TM::TemporalPosition, Parts::GeometricComplex ; specification
|
|
437
|
-
when TM::Position
|
|
438
|
-
when Array
|
|
439
|
-
when
|
|
440
|
-
when
|
|
441
|
-
when /[\
|
|
442
|
-
when
|
|
443
|
-
when
|
|
444
|
-
|
|
464
|
+
when TM::Position ; specification.any_other
|
|
465
|
+
when Array ; begin options = TM::TemporalPosition._options(options) ; specification.map {|e| when?(e, options)} end
|
|
466
|
+
when /\Atoday\z/i ; today(options)
|
|
467
|
+
when /\Anow\z/i ; now(options)
|
|
468
|
+
when /[JS]DN(\z|\^)/i; TM::JulianDate.parse(specification, options)
|
|
469
|
+
when /[\n\r]+/ ; when?(specification.split(/[\n\r]+/), options)
|
|
470
|
+
when String ; TM::TemporalPosition._instance(EncodingConversion.to_internal_encoding(specification), options)
|
|
471
|
+
when Numeric ; TM::JulianDate.new(+specification, TM::TemporalPosition._options(options))
|
|
472
|
+
else ; Calendar(options[:frame] || 'Gregorian').jul_trans(specification, options)
|
|
445
473
|
end
|
|
446
474
|
end
|
|
447
475
|
|
|
@@ -482,6 +510,7 @@ module When
|
|
|
482
510
|
date = Array.new(options[:frame].indices.length+1) {args.shift}
|
|
483
511
|
if (args.length > 0)
|
|
484
512
|
options[:clock] ||= TM::Clock.local_time
|
|
513
|
+
options[:clock] = Clock(options[:clock])
|
|
485
514
|
time = Array.new(options[:clock].indices.length) {args.shift}
|
|
486
515
|
position = TM::DateAndTime.new(date, time.unshift(0), options)
|
|
487
516
|
else
|
|
@@ -633,7 +662,9 @@ module When
|
|
|
633
662
|
# @return [When::TM::CalendarEra] era に対応する When::TM::CalendarEra オブジェクト
|
|
634
663
|
#
|
|
635
664
|
def CalendarEra(era)
|
|
636
|
-
Parts::Resource._instance(era, '_e:')
|
|
665
|
+
Parts::Resource._instance(era, '_e:') do |iri|
|
|
666
|
+
TM::CalendarEra.send(:_behalf_of, iri)
|
|
667
|
+
end
|
|
637
668
|
end
|
|
638
669
|
|
|
639
670
|
# When::TM::CalendarEra の検索
|
|
@@ -666,12 +697,12 @@ module When
|
|
|
666
697
|
#
|
|
667
698
|
def Clock(clock)
|
|
668
699
|
case clock
|
|
669
|
-
when Parts::Timezone::Base
|
|
670
|
-
when 'Z', 0
|
|
671
|
-
when Numeric
|
|
672
|
-
when
|
|
673
|
-
when String
|
|
674
|
-
else
|
|
700
|
+
when Parts::Timezone::Base ; return clock
|
|
701
|
+
when 'Z', 0 ; return UTC
|
|
702
|
+
when Numeric ; return Parts::Resource._instance("_tm:Clock?label=" + TM::Clock.to_hms(clock))
|
|
703
|
+
when /\A#{CalendarTypes::TimeSystems}/ ; return Parts::Resource._instance('_c:' + clock)
|
|
704
|
+
when String ;
|
|
705
|
+
else ; raise TypeError, "Invalid Type: #{clock.class}"
|
|
675
706
|
end
|
|
676
707
|
c = TM::Clock[clock] || V::Timezone[clock]
|
|
677
708
|
return c if c
|
|
@@ -714,8 +745,8 @@ module When
|
|
|
714
745
|
longitude = latitude = nil
|
|
715
746
|
args.each do |arg|
|
|
716
747
|
case arg
|
|
717
|
-
when
|
|
718
|
-
when
|
|
748
|
+
when /\A#{Coordinates::MATCH['EW']}\s*[.@\d]/, /[.@\d]\s*#{Coordinates::MATCH['EW']}\z/; longitude = arg
|
|
749
|
+
when /\A#{Coordinates::MATCH['NS']}\s*[.@\d]/, /[.@\d]\s*#{Coordinates::MATCH['NS']}\z/; latitude = arg
|
|
719
750
|
else ; rest << arg
|
|
720
751
|
end
|
|
721
752
|
end
|
|
@@ -784,8 +815,8 @@ module When
|
|
|
784
815
|
when BasicTypes::M17n ; source
|
|
785
816
|
when String
|
|
786
817
|
source = EncodingConversion.to_internal_encoding(source)
|
|
787
|
-
return self[$1] if source =~
|
|
788
|
-
return Parts::Resource[$1] if source =~
|
|
818
|
+
return self[$1] if source =~ /\A\s*\[((\.{1,2}|::)+[^\]]+)\]/ && self.kind_of?(When::Parts::Resource)
|
|
819
|
+
return Parts::Resource[$1] if source =~ /\A\s*\[::([^\]]+)\]/
|
|
789
820
|
BasicTypes::M17n.new(source, namespace, locale, options)
|
|
790
821
|
else ; raise TypeError, "Invalid Type: #{source.class}"
|
|
791
822
|
end
|
data/lib/when_exe/basictypes.rb
CHANGED
|
@@ -1,747 +1,752 @@
|
|
|
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
|
-
module When
|
|
9
|
-
|
|
10
|
-
# ISO 19108 以外の ISO に規定のある基本的なデータ型
|
|
11
|
-
# およびその subclass
|
|
12
|
-
module BasicTypes
|
|
13
|
-
|
|
14
|
-
#
|
|
15
|
-
# ISO 8601 Date and Time Representation
|
|
16
|
-
#
|
|
17
|
-
# see {xml schema}[link:http://www.w3.org/2001/XMLSchema-datatypes#date_time]
|
|
18
|
-
#
|
|
19
|
-
class DateTime < String
|
|
20
|
-
|
|
21
|
-
class << self
|
|
22
|
-
|
|
23
|
-
# When.exe Standard Representation 形式の表現を分解してArray化する
|
|
24
|
-
#
|
|
25
|
-
# @param [String] date_time 日時を表現する When.exe Standard Representation 形式の文字列
|
|
26
|
-
# @param [Hash] options 以下の通り
|
|
27
|
-
# @option options [String, Array<String, Integer>] :era_name デフォルトの年号(Integerは0年に対応する通年)
|
|
28
|
-
# @option options [Array<Numeric>] :abbr 上位省略形式で使用する上位部分
|
|
29
|
-
# @option options [Integer] :extra_year_digits ISO8601拡大表記のための年の構成要素拡大桁数(省略時 1桁)
|
|
30
|
-
# @option options [Integer] :ordinal_date_digits ISO8601拡大表記の年内通日の桁数(省略時 3桁)
|
|
31
|
-
#
|
|
32
|
-
# @return [Array] format, date, time, clock, era
|
|
33
|
-
#
|
|
34
|
-
# format (Symbol, nil)
|
|
35
|
-
# nil 通常形式
|
|
36
|
-
# :century 世紀指定形式 ('CC', '+CCCC', '-CCCC')
|
|
37
|
-
# :day 年間通算日形式 ('YYDDD'など)
|
|
38
|
-
# :week 暦週形式 ('YYWNN'など)
|
|
39
|
-
#
|
|
40
|
-
# date (Array<Numeric>) 日付部分
|
|
41
|
-
#
|
|
42
|
-
# time (Array<Numeric>) 時刻部分
|
|
43
|
-
#
|
|
44
|
-
# clock (String) 時間帯
|
|
45
|
-
#
|
|
46
|
-
# era (String, Array<String, Integer>) 年号(Integerは0年に対応する通年)
|
|
47
|
-
#
|
|
48
|
-
def _to_array(date_time, options={})
|
|
49
|
-
raise TypeError, "Argument is not ISO 8601 String" unless date_time.kind_of?(String)
|
|
50
|
-
if options[:abbr].kind_of?(When::TimeValue)
|
|
51
|
-
options[:abbr] = ((options[:frame]||When::Gregorian) ^ options[:abbr]).cal_date
|
|
52
|
-
end
|
|
53
|
-
date_time = date_time.gsub(/_([\d])/, '\1')
|
|
54
|
-
begin
|
|
55
|
-
return _to_array_basic(date_time, options)
|
|
56
|
-
rescue ArgumentError
|
|
57
|
-
return _to_array_extended(date_time, options)
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
private
|
|
62
|
-
|
|
63
|
-
# ISO 8601 基本形式の表現を分解して配列化する
|
|
64
|
-
def _to_array_basic(date_time, options={})
|
|
65
|
-
|
|
66
|
-
case date_time
|
|
67
|
-
# basic date & time format (ISO 8601)
|
|
68
|
-
when
|
|
69
|
-
d, t, time, clock = $~[1..4]
|
|
70
|
-
format, date = Date._to_array_basic_ISO8601(d, options)
|
|
71
|
-
|
|
72
|
-
# basic date & time format (JIS X0301)
|
|
73
|
-
when
|
|
74
|
-
raise ArgumentError, "Wrong date format" unless options[:era_name]
|
|
75
|
-
d, t, time, clock = $~[1..4]
|
|
76
|
-
format, date = Date._to_array_basic_X0301(d, options)
|
|
77
|
-
era = options[:era_name]
|
|
78
|
-
|
|
79
|
-
# basic time format (ISO 8601)
|
|
80
|
-
when
|
|
81
|
-
t, time, clock = $~[1..3]
|
|
82
|
-
|
|
83
|
-
# not supported
|
|
84
|
-
else
|
|
85
|
-
raise ArgumentError, "Wrong date format: #{date_time}"
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
return [format, date, Time._to_array_basic(time, t, options),
|
|
89
|
-
Time._to_string_clock(clock), era]
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
# ISO 8601 拡張形式の表現を分解して配列化する
|
|
93
|
-
def _to_array_extended(date_time, options={})
|
|
94
|
-
|
|
95
|
-
case date_time
|
|
96
|
-
# extended date & time format (ISO 8601)
|
|
97
|
-
when
|
|
98
|
-
d, t, time, clock = $~[1..4]
|
|
99
|
-
if d =~ /[\(\)]/
|
|
100
|
-
d = When::CalendarTypes::Yerm.parse(d, options[:abbr])
|
|
101
|
-
options[:frame] ||= 'Yerm'
|
|
102
|
-
end
|
|
103
|
-
format, date = Date._to_array_extended_ISO8601(d, options)
|
|
104
|
-
|
|
105
|
-
# extended date & time format (JIS X0301)
|
|
106
|
-
when
|
|
107
|
-
era, parent, child, d, t, time, clock = $~[1..7]
|
|
108
|
-
format, date, era = Date._to_array_extended_X0301(d, era, options)
|
|
109
|
-
era ||= options[:era_name] if (d =~ /\./)
|
|
110
|
-
|
|
111
|
-
# extended time format (ISO 8601)
|
|
112
|
-
when
|
|
113
|
-
t, time, clock = $~[1..3]
|
|
114
|
-
|
|
115
|
-
# not supported
|
|
116
|
-
else
|
|
117
|
-
raise ArgumentError, "Wrong date format: #{date_time}"
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
return [format, date, Time._to_array_extended(time, t, options),
|
|
121
|
-
Time._to_string_clock(clock), era]
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
#
|
|
127
|
-
# ISO 8601 Date Representation
|
|
128
|
-
#
|
|
129
|
-
# see {xml schema}[link:http://www.w3.org/2001/XMLSchema-datatypes#date]
|
|
130
|
-
#
|
|
131
|
-
class Date < DateTime
|
|
132
|
-
|
|
133
|
-
# @private
|
|
134
|
-
Extra_Year_Digits = Hash.new {|hash, key|
|
|
135
|
-
ex = (key || 1).to_i
|
|
136
|
-
hash[key] =
|
|
137
|
-
if ex > 0
|
|
138
|
-
[
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
]
|
|
148
|
-
elsif ex == 0
|
|
149
|
-
[
|
|
150
|
-
else
|
|
151
|
-
[
|
|
152
|
-
end
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
# @private
|
|
156
|
-
Ordinal_Date_Digits = Hash.new {|hash, key|
|
|
157
|
-
hash[key] =
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
class << self
|
|
161
|
-
# ISO 8601 基本形式の表現を分解して配列化する
|
|
162
|
-
def _to_array_basic_ISO8601(date, options={})
|
|
163
|
-
by, bm, bd = options[:abbr]
|
|
164
|
-
extra_reg = Extra_Year_Digits[options[:extra_year_digits]]
|
|
165
|
-
case date
|
|
166
|
-
when nil
|
|
167
|
-
when
|
|
168
|
-
when
|
|
169
|
-
when
|
|
170
|
-
when extra_reg[0]
|
|
171
|
-
when
|
|
172
|
-
when
|
|
173
|
-
when extra_reg[1]
|
|
174
|
-
when extra_reg[2]
|
|
175
|
-
when extra_reg[3]
|
|
176
|
-
when extra_reg[4]
|
|
177
|
-
when extra_reg[5]
|
|
178
|
-
when extra_reg[6]
|
|
179
|
-
when extra_reg[7]
|
|
180
|
-
else
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
by = by.to_i
|
|
184
|
-
case date
|
|
185
|
-
when
|
|
186
|
-
when
|
|
187
|
-
when
|
|
188
|
-
when
|
|
189
|
-
when
|
|
190
|
-
when
|
|
191
|
-
when
|
|
192
|
-
when
|
|
193
|
-
else
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
bm = bm.to_i
|
|
197
|
-
case date
|
|
198
|
-
when
|
|
199
|
-
when
|
|
200
|
-
when
|
|
201
|
-
end
|
|
202
|
-
|
|
203
|
-
raise ArgumentError, "Wrong date format: #{date}"
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
# JIS X0301 基本形式の表現を分解して配列化する
|
|
207
|
-
def _to_array_basic_X0301(date, options={})
|
|
208
|
-
raise ArgumentError, "Wrong date format" unless date =~ /\./
|
|
209
|
-
date.scan(/\d+\./) do |part|
|
|
210
|
-
raise ArgumentError, "Wrong date format" unless part.length == 3
|
|
211
|
-
end
|
|
212
|
-
_to_array_basic_ISO8601(date.gsub(/\./, ''), {:abbr=>options[:abbr]||1})
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
# ISO 8601 拡張形式の表現を分解して配列化する
|
|
216
|
-
def _to_array_extended_ISO8601(date, options={})
|
|
217
|
-
return nil unless date
|
|
218
|
-
abbr = Array(options[:abbr]).dup
|
|
219
|
-
unless date =~
|
|
220
|
-
raise ArgumentError, "Wrong date format: #{date}"
|
|
221
|
-
end
|
|
222
|
-
date = $3
|
|
223
|
-
dd = [Coordinates::Pair._en_pair(_completion($1, abbr.shift), $2)]
|
|
224
|
-
while date =~
|
|
225
|
-
date = $3
|
|
226
|
-
dd << Coordinates::Pair._en_pair(_completion($1, abbr.shift), $2)
|
|
227
|
-
end
|
|
228
|
-
case date
|
|
229
|
-
when
|
|
230
|
-
dd << Coordinates::Pair._en_pair(_completion($1, abbr.shift), $2)
|
|
231
|
-
dd << Coordinates::Pair._en_pair($3, $4)
|
|
232
|
-
return :week, dd
|
|
233
|
-
when Ordinal_Date_Digits[options[:ordinal_date_digits]]
|
|
234
|
-
dd << $1.to_i
|
|
235
|
-
return :day, dd
|
|
236
|
-
when
|
|
237
|
-
dd << Coordinates::Pair._en_pair(_completion($1, abbr.shift), $2)
|
|
238
|
-
return nil, dd
|
|
239
|
-
when ''
|
|
240
|
-
return nil, dd
|
|
241
|
-
else
|
|
242
|
-
raise ArgumentError, "Wrong date format: #{date}"
|
|
243
|
-
end
|
|
244
|
-
end
|
|
245
|
-
|
|
246
|
-
# JIS X0301 拡張形式の表現を分解して配列化する
|
|
247
|
-
def _to_array_extended_X0301(date, era, options={})
|
|
248
|
-
if (date =~
|
|
249
|
-
year = $2
|
|
250
|
-
date = $1 + $3
|
|
251
|
-
end
|
|
252
|
-
format, date = _to_array_extended_ISO8601(date, options)
|
|
253
|
-
if (year)
|
|
254
|
-
yy = year.to_i
|
|
255
|
-
ee = date[0] * 1
|
|
256
|
-
era = [era, yy-ee, yy+ee]
|
|
257
|
-
end
|
|
258
|
-
return format, date, era
|
|
259
|
-
end
|
|
260
|
-
|
|
261
|
-
private
|
|
262
|
-
|
|
263
|
-
def _completion(digits, base)
|
|
264
|
-
case digits
|
|
265
|
-
when nil
|
|
266
|
-
when
|
|
267
|
-
else
|
|
268
|
-
end
|
|
269
|
-
|
|
270
|
-
base = base.to_i
|
|
271
|
-
case digits
|
|
272
|
-
when '-'
|
|
273
|
-
when
|
|
274
|
-
when
|
|
275
|
-
else
|
|
276
|
-
end
|
|
277
|
-
end
|
|
278
|
-
|
|
279
|
-
def _century(year, base)
|
|
280
|
-
quotient, remainder = base.divmod(100)
|
|
281
|
-
year = year.to_i
|
|
282
|
-
quotient += 1 if year < remainder
|
|
283
|
-
return quotient * 100 + year
|
|
284
|
-
end
|
|
285
|
-
|
|
286
|
-
def _decade(year, base)
|
|
287
|
-
quotient, remainder = base.divmod(10)
|
|
288
|
-
year = year.to_i
|
|
289
|
-
quotient += 1 if year < remainder
|
|
290
|
-
return quotient * 10 + year
|
|
291
|
-
end
|
|
292
|
-
|
|
293
|
-
def _int(digits)
|
|
294
|
-
return digits ? digits.to_i : nil
|
|
295
|
-
end
|
|
296
|
-
end
|
|
297
|
-
end
|
|
298
|
-
|
|
299
|
-
#
|
|
300
|
-
# ISO 8601 Time Representation
|
|
301
|
-
#
|
|
302
|
-
# see {xml schema}[link:http://www.w3.org/2001/XMLSchema-datatypes#time]
|
|
303
|
-
#
|
|
304
|
-
class Time < DateTime
|
|
305
|
-
|
|
306
|
-
class << self
|
|
307
|
-
# 基本形式の表現を分解して配列化する
|
|
308
|
-
def _to_array_basic(time, t, options={})
|
|
309
|
-
return nil unless t
|
|
310
|
-
return [0] unless time
|
|
311
|
-
time.sub!(/,/, '.')
|
|
312
|
-
unless (time =~
|
|
313
|
-
raise ArgumentError, "Wrong time format: #{time}"
|
|
314
|
-
end
|
|
315
|
-
indices = options[:frame] ? options[:frame].indices : Coordinates::DefaultDateIndices
|
|
316
|
-
abbr = Array(options[:abbr]).dup
|
|
317
|
-
abbr[0..indices.length] = []
|
|
318
|
-
return [0, Coordinates::Pair._en_number($1=='-' ? abbr[0] : $1, nil),
|
|
319
|
-
Coordinates::Pair._en_number($2=='-' ? abbr[1] : $2, nil),
|
|
320
|
-
Coordinates::Pair._en_number($3, nil)]
|
|
321
|
-
end
|
|
322
|
-
|
|
323
|
-
# 拡張形式の表現を分解して配列化する
|
|
324
|
-
def _to_array_extended(time, t, options={})
|
|
325
|
-
return nil unless t
|
|
326
|
-
return [0] unless time
|
|
327
|
-
indices = options[:frame] ? options[:frame].indices : Coordinates::DefaultDateIndices
|
|
328
|
-
abbr = Array(options[:abbr]).dup
|
|
329
|
-
abbr[0..indices.length] = []
|
|
330
|
-
time.sub!(/,/, '.')
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
return
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
return
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
#
|
|
365
|
-
#
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
#
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
#
|
|
392
|
-
# ==
|
|
393
|
-
#
|
|
394
|
-
#
|
|
395
|
-
#
|
|
396
|
-
#
|
|
397
|
-
#
|
|
398
|
-
#
|
|
399
|
-
#
|
|
400
|
-
#
|
|
401
|
-
#
|
|
402
|
-
#
|
|
403
|
-
#
|
|
404
|
-
#
|
|
405
|
-
#
|
|
406
|
-
#
|
|
407
|
-
#
|
|
408
|
-
#
|
|
409
|
-
#
|
|
410
|
-
#
|
|
411
|
-
#
|
|
412
|
-
#
|
|
413
|
-
#
|
|
414
|
-
#
|
|
415
|
-
#
|
|
416
|
-
#
|
|
417
|
-
#
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
#
|
|
441
|
-
#
|
|
442
|
-
#
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
#
|
|
458
|
-
#
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
#
|
|
475
|
-
#
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
#
|
|
501
|
-
#
|
|
502
|
-
#
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
#
|
|
508
|
-
# When::BasicTypes::
|
|
509
|
-
#
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
#
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
#
|
|
546
|
-
#
|
|
547
|
-
#
|
|
548
|
-
#
|
|
549
|
-
#
|
|
550
|
-
#
|
|
551
|
-
#
|
|
552
|
-
#
|
|
553
|
-
#
|
|
554
|
-
#
|
|
555
|
-
#
|
|
556
|
-
#
|
|
557
|
-
#
|
|
558
|
-
#
|
|
559
|
-
#
|
|
560
|
-
#
|
|
561
|
-
#
|
|
562
|
-
#
|
|
563
|
-
#
|
|
564
|
-
#
|
|
565
|
-
#
|
|
566
|
-
#
|
|
567
|
-
#
|
|
568
|
-
#
|
|
569
|
-
#
|
|
570
|
-
#
|
|
571
|
-
#
|
|
572
|
-
#
|
|
573
|
-
#
|
|
574
|
-
#
|
|
575
|
-
#
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
names
|
|
604
|
-
@
|
|
605
|
-
@
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
#
|
|
622
|
-
class
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
#
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
#
|
|
661
|
-
#
|
|
662
|
-
#
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
#
|
|
667
|
-
#
|
|
668
|
-
#
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
#
|
|
673
|
-
#
|
|
674
|
-
#
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
#
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
#
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
#
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
#
|
|
723
|
-
#
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
#
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
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
|
+
module When
|
|
9
|
+
|
|
10
|
+
# ISO 19108 以外の ISO に規定のある基本的なデータ型
|
|
11
|
+
# およびその subclass
|
|
12
|
+
module BasicTypes
|
|
13
|
+
|
|
14
|
+
#
|
|
15
|
+
# ISO 8601 Date and Time Representation
|
|
16
|
+
#
|
|
17
|
+
# see {xml schema}[link:http://www.w3.org/2001/XMLSchema-datatypes#date_time]
|
|
18
|
+
#
|
|
19
|
+
class DateTime < String
|
|
20
|
+
|
|
21
|
+
class << self
|
|
22
|
+
|
|
23
|
+
# When.exe Standard Representation 形式の表現を分解してArray化する
|
|
24
|
+
#
|
|
25
|
+
# @param [String] date_time 日時を表現する When.exe Standard Representation 形式の文字列
|
|
26
|
+
# @param [Hash] options 以下の通り
|
|
27
|
+
# @option options [String, Array<String, Integer>] :era_name デフォルトの年号(Integerは0年に対応する通年)
|
|
28
|
+
# @option options [Array<Numeric>] :abbr 上位省略形式で使用する上位部分
|
|
29
|
+
# @option options [Integer] :extra_year_digits ISO8601拡大表記のための年の構成要素拡大桁数(省略時 1桁)
|
|
30
|
+
# @option options [Integer] :ordinal_date_digits ISO8601拡大表記の年内通日の桁数(省略時 3桁)
|
|
31
|
+
#
|
|
32
|
+
# @return [Array] format, date, time, clock, era
|
|
33
|
+
#
|
|
34
|
+
# format (Symbol, nil)
|
|
35
|
+
# nil 通常形式
|
|
36
|
+
# :century 世紀指定形式 ('CC', '+CCCC', '-CCCC')
|
|
37
|
+
# :day 年間通算日形式 ('YYDDD'など)
|
|
38
|
+
# :week 暦週形式 ('YYWNN'など)
|
|
39
|
+
#
|
|
40
|
+
# date (Array<Numeric>) 日付部分
|
|
41
|
+
#
|
|
42
|
+
# time (Array<Numeric>) 時刻部分
|
|
43
|
+
#
|
|
44
|
+
# clock (String) 時間帯
|
|
45
|
+
#
|
|
46
|
+
# era (String, Array<String, Integer>) 年号(Integerは0年に対応する通年)
|
|
47
|
+
#
|
|
48
|
+
def _to_array(date_time, options={})
|
|
49
|
+
raise TypeError, "Argument is not ISO 8601 String" unless date_time.kind_of?(String)
|
|
50
|
+
if options[:abbr].kind_of?(When::TimeValue)
|
|
51
|
+
options[:abbr] = ((options[:frame]||When::Gregorian) ^ options[:abbr]).cal_date
|
|
52
|
+
end
|
|
53
|
+
date_time = date_time.gsub(/_([\d])/, '\1')
|
|
54
|
+
begin
|
|
55
|
+
return _to_array_basic(date_time, options)
|
|
56
|
+
rescue ArgumentError
|
|
57
|
+
return _to_array_extended(date_time, options)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
private
|
|
62
|
+
|
|
63
|
+
# ISO 8601 基本形式の表現を分解して配列化する
|
|
64
|
+
def _to_array_basic(date_time, options={})
|
|
65
|
+
|
|
66
|
+
case date_time
|
|
67
|
+
# basic date & time format (ISO 8601)
|
|
68
|
+
when /\A([-+W\d]+)(?:(T([.,\d]+)?)([A-Z]+(\?.+)?|[-+]\d+)?)?\z/
|
|
69
|
+
d, t, time, clock = $~[1..4]
|
|
70
|
+
format, date = Date._to_array_basic_ISO8601(d, options)
|
|
71
|
+
|
|
72
|
+
# basic date & time format (JIS X0301)
|
|
73
|
+
when /\A([.\d]+)(?:(T([.,\d]+)?)([A-Z]+(\?.+)?|[-+]\d+)?)?\z/
|
|
74
|
+
raise ArgumentError, "Wrong date format" unless options[:era_name]
|
|
75
|
+
d, t, time, clock = $~[1..4]
|
|
76
|
+
format, date = Date._to_array_basic_X0301(d, options)
|
|
77
|
+
era = options[:era_name]
|
|
78
|
+
|
|
79
|
+
# basic time format (ISO 8601)
|
|
80
|
+
when /\A(T(-{0,2}[.,\d]+)?)([A-Z]+(\?.+)?|[-+]\d+)?\z/
|
|
81
|
+
t, time, clock = $~[1..3]
|
|
82
|
+
|
|
83
|
+
# not supported
|
|
84
|
+
else
|
|
85
|
+
raise ArgumentError, "Wrong date format: #{date_time}"
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
return [format, date, Time._to_array_basic(time, t, options),
|
|
89
|
+
Time._to_string_clock(clock), era]
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# ISO 8601 拡張形式の表現を分解して配列化する
|
|
93
|
+
def _to_array_extended(date_time, options={})
|
|
94
|
+
|
|
95
|
+
case date_time
|
|
96
|
+
# extended date & time format (ISO 8601)
|
|
97
|
+
when /\A([-+*&%@!>=<?\dW.\(\)]+)(?:(T([:*=.,\d]+)?)([A-Z]+(\?.+)?|[-+][:\d]+)?)?\z/
|
|
98
|
+
d, t, time, clock = $~[1..4]
|
|
99
|
+
if d =~ /[\(\)]/
|
|
100
|
+
d = When::CalendarTypes::Yerm.parse(d, options[:abbr])
|
|
101
|
+
options[:frame] ||= 'Yerm'
|
|
102
|
+
end
|
|
103
|
+
format, date = Date._to_array_extended_ISO8601(d, options)
|
|
104
|
+
|
|
105
|
+
# extended date & time format (JIS X0301)
|
|
106
|
+
when /\A((.+::)?(\[[^\]]+\]|[^-+\d]+))([-+*&%@!>=<?\dW.\(\)]+)?(?:(T([:*=.,\d]+)?)([A-Z]+(\?.+)?|[-+][:\d]+)?)?\z/
|
|
107
|
+
era, parent, child, d, t, time, clock = $~[1..7]
|
|
108
|
+
format, date, era = Date._to_array_extended_X0301(d, era, options)
|
|
109
|
+
era ||= options[:era_name] if (d =~ /\./)
|
|
110
|
+
|
|
111
|
+
# extended time format (ISO 8601)
|
|
112
|
+
when /\A(T(-{0,2}[:*=.,\d]+)?)([A-Z]+(\?.+)?|[-+][:\d]+)?\z/
|
|
113
|
+
t, time, clock = $~[1..3]
|
|
114
|
+
|
|
115
|
+
# not supported
|
|
116
|
+
else
|
|
117
|
+
raise ArgumentError, "Wrong date format: #{date_time}"
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
return [format, date, Time._to_array_extended(time, t, options),
|
|
121
|
+
Time._to_string_clock(clock), era]
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
#
|
|
127
|
+
# ISO 8601 Date Representation
|
|
128
|
+
#
|
|
129
|
+
# see {xml schema}[link:http://www.w3.org/2001/XMLSchema-datatypes#date]
|
|
130
|
+
#
|
|
131
|
+
class Date < DateTime
|
|
132
|
+
|
|
133
|
+
# @private
|
|
134
|
+
Extra_Year_Digits = Hash.new {|hash, key|
|
|
135
|
+
ex = (key || 1).to_i
|
|
136
|
+
hash[key] =
|
|
137
|
+
if ex > 0
|
|
138
|
+
[
|
|
139
|
+
/\A(\d{2})\z/,
|
|
140
|
+
/\A([-+]\d{#{4+ex}})(\d{2})(\d{2})\z/,
|
|
141
|
+
/\A([-+]\d{#{4+ex}})-(\d{2})\z/,
|
|
142
|
+
/\A([-+]\d{#{4+ex}})\z/,
|
|
143
|
+
/\A([-+]\d{#{4+ex}})W(\d{2})(\d{1})?\z/,
|
|
144
|
+
/\A([+]\d{#{2+ex}})\z/,
|
|
145
|
+
/\A([-]\d{#{2+ex}})\z/,
|
|
146
|
+
/\A([-+]\d{#{4+ex}})(\d{3})\z/
|
|
147
|
+
]
|
|
148
|
+
elsif ex == 0
|
|
149
|
+
[/\A(\d{2})\z/] + [/\A(\d{4})\z/] * 6
|
|
150
|
+
else
|
|
151
|
+
[/\A(\d{4})\z/] * 7
|
|
152
|
+
end
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
# @private
|
|
156
|
+
Ordinal_Date_Digits = Hash.new {|hash, key|
|
|
157
|
+
hash[key] = /\A(\d{#{(key || 3).to_i}})\z/
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
class << self
|
|
161
|
+
# ISO 8601 基本形式の表現を分解して配列化する
|
|
162
|
+
def _to_array_basic_ISO8601(date, options={})
|
|
163
|
+
by, bm, bd = options[:abbr]
|
|
164
|
+
extra_reg = Extra_Year_Digits[options[:extra_year_digits]]
|
|
165
|
+
case date
|
|
166
|
+
when nil ; return nil
|
|
167
|
+
when /\A(\d{4})(\d{2})(\d{2})\z/ ; return nil, [$1.to_i, $2.to_i, $3.to_i] # 5.2.1.1
|
|
168
|
+
when /\A(\d{4})-(\d{2})\z/ ; return nil, [$1.to_i, $2.to_i] # 5.2.1.2
|
|
169
|
+
when /\A(\d{4})\z/ ; return nil, [$1.to_i] # 5.2.1.2
|
|
170
|
+
when extra_reg[0] ; return :century,[$1.to_i * 100] # 5.2.1.2
|
|
171
|
+
when /\A(\d{4})(\d{3})\z/ ; return :day, [$1.to_i, $2.to_i] # 5.2.2.1
|
|
172
|
+
when /\A(\d{4})W(\d{2})(\d{1})?\z/ ; return :week, [$1.to_i, $2.to_i, _int($3)] # 5.2.3.1-2
|
|
173
|
+
when extra_reg[1] ; return nil, [$1.to_i, $2.to_i, $3.to_i] # 5.2.1.4 a)
|
|
174
|
+
when extra_reg[2] ; return nil, [$1.to_i, $2.to_i] # 5.2.1.4 b)
|
|
175
|
+
when extra_reg[3] ; return nil, [$1.to_i] # 5.2.1.4 c)
|
|
176
|
+
when extra_reg[4] ; return :week, [$1.to_i, $2.to_i, _int($3)] # 5.2.3.4 a-b)
|
|
177
|
+
when extra_reg[5] ; return :century,[$1.to_i * 100] # 5.2.1.4 d)
|
|
178
|
+
when extra_reg[6] ; return :century,[$1.to_i * 100] unless by # 5.2.1.4 d)
|
|
179
|
+
when extra_reg[7] ; return :day, [$1.to_i, $2.to_i] # 5.2.2.3 a)
|
|
180
|
+
else ; raise ArgumentError, "Wrong date format" unless by
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
by = by.to_i
|
|
184
|
+
case date
|
|
185
|
+
when /\A(\d{2})(\d{2})(\d{2})\z/ ; return nil, [_century($1,by), $2.to_i, $3.to_i] # 5.2.1.3 a)
|
|
186
|
+
when /\A-(\d{2})(\d{2})?\z/ ; return nil, [_century($1,by), _int($2)] # 5.2.1.3 b-c)
|
|
187
|
+
when /\A--(\d{2})(\d{2})?\z/ ; return nil, [by, $1.to_i, _int($2)] # 5.2.1.3 d-e)
|
|
188
|
+
when /\A(\d{2})(\d{3})\z/ ; return :day, [_century($1,by), $2.to_i] # 5.2.2.2 a)
|
|
189
|
+
when /\A-(\d{3})\z/ ; return :day, [by, $1.to_i] # 5.2.2.2 b)
|
|
190
|
+
when /\A(\d{2})W(\d{2})(\d{1})?\z/ ; return :week, [_century($1,by), $2.to_i, _int($3)] # 5.2.3.3 a-b)
|
|
191
|
+
when /\A-(\d{1})W(\d{2})(\d{1})?\z/ ; return :week, [_decade($1,by), $2.to_i, _int($3)] # 5.2.3.3 c-d)
|
|
192
|
+
when /\A-W(\d{2})(\d{1})?\z/ ; return :week, [by, $1.to_i, _int($2)] # 5.2.3.3 e-f)
|
|
193
|
+
else ; raise ArgumentError, "Wrong date format" unless bm
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
bm = bm.to_i
|
|
197
|
+
case date
|
|
198
|
+
when /\A---(\d{2})\z/ ; return nil, [by, bm, $1.to_i] # 5.2.1.3 f)
|
|
199
|
+
when /\A-W-(\d{1})\z/ ; return :week, [by, bm, $1.to_i] # 5.2.3.3 g)
|
|
200
|
+
when /\A----\z/ ; return nil, [by, bm, bd.to_i] if bd # extension
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
raise ArgumentError, "Wrong date format: #{date}"
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
# JIS X0301 基本形式の表現を分解して配列化する
|
|
207
|
+
def _to_array_basic_X0301(date, options={})
|
|
208
|
+
raise ArgumentError, "Wrong date format" unless date =~ /\./
|
|
209
|
+
date.scan(/\d+\./) do |part|
|
|
210
|
+
raise ArgumentError, "Wrong date format" unless part.length == 3
|
|
211
|
+
end
|
|
212
|
+
_to_array_basic_ISO8601(date.gsub(/\./, ''), {:abbr=>options[:abbr]||1})
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
# ISO 8601 拡張形式の表現を分解して配列化する
|
|
216
|
+
def _to_array_extended_ISO8601(date, options={})
|
|
217
|
+
return nil unless date
|
|
218
|
+
abbr = Array(options[:abbr]).dup
|
|
219
|
+
unless date =~ /\A([-+]?\d+#{abbr[0] ? '|-' : ''})([-*=.])?(.*)/
|
|
220
|
+
raise ArgumentError, "Wrong date format: #{date}"
|
|
221
|
+
end
|
|
222
|
+
date = $3
|
|
223
|
+
dd = [Coordinates::Pair._en_pair(_completion($1, abbr.shift), $2)]
|
|
224
|
+
while date =~ /\A(\d+#{abbr[0] ? '|-' : ''})([-+*&%@!>=<?.])(.+)/
|
|
225
|
+
date = $3
|
|
226
|
+
dd << Coordinates::Pair._en_pair(_completion($1, abbr.shift), $2)
|
|
227
|
+
end
|
|
228
|
+
case date
|
|
229
|
+
when /\AW(\d+#{abbr[0] ? '|-' : ''})([-+*&%@!>=<?.])?(\d+)?([-*=?%@])?\z/
|
|
230
|
+
dd << Coordinates::Pair._en_pair(_completion($1, abbr.shift), $2)
|
|
231
|
+
dd << Coordinates::Pair._en_pair($3, $4)
|
|
232
|
+
return :week, dd
|
|
233
|
+
when Ordinal_Date_Digits[options[:ordinal_date_digits]]
|
|
234
|
+
dd << $1.to_i
|
|
235
|
+
return :day, dd
|
|
236
|
+
when /\A(\d+#{abbr[0] ? '|-' : ''})([-+*&%@!>=<?.])?\z/
|
|
237
|
+
dd << Coordinates::Pair._en_pair(_completion($1, abbr.shift), $2)
|
|
238
|
+
return nil, dd
|
|
239
|
+
when ''
|
|
240
|
+
return nil, dd
|
|
241
|
+
else
|
|
242
|
+
raise ArgumentError, "Wrong date format: #{date}"
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
# JIS X0301 拡張形式の表現を分解して配列化する
|
|
247
|
+
def _to_array_extended_X0301(date, era, options={})
|
|
248
|
+
if (date =~ /\A([-+\d]+)\(([-+\d]+)\)(.*)\z/)
|
|
249
|
+
year = $2
|
|
250
|
+
date = $1 + $3
|
|
251
|
+
end
|
|
252
|
+
format, date = _to_array_extended_ISO8601(date, options)
|
|
253
|
+
if (year)
|
|
254
|
+
yy = year.to_i
|
|
255
|
+
ee = date[0] * 1
|
|
256
|
+
era = [era, yy-ee, yy+ee]
|
|
257
|
+
end
|
|
258
|
+
return format, date, era
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
private
|
|
262
|
+
|
|
263
|
+
def _completion(digits, base)
|
|
264
|
+
case digits
|
|
265
|
+
when nil ; return nil
|
|
266
|
+
when /\A\d{5}/ ; raise ArgumentError, "Wrong date format: #{digits}"
|
|
267
|
+
else ; return digits.to_i unless base
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
base = base.to_i
|
|
271
|
+
case digits
|
|
272
|
+
when '-' ; return base
|
|
273
|
+
when /\A-?(\d{1})\z/ ; return _decade( $1, base)
|
|
274
|
+
when /\A-?(\d{2})\z/ ; return _century($1, base)
|
|
275
|
+
else ; return digits.to_i
|
|
276
|
+
end
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
def _century(year, base)
|
|
280
|
+
quotient, remainder = base.divmod(100)
|
|
281
|
+
year = year.to_i
|
|
282
|
+
quotient += 1 if year < remainder
|
|
283
|
+
return quotient * 100 + year
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
def _decade(year, base)
|
|
287
|
+
quotient, remainder = base.divmod(10)
|
|
288
|
+
year = year.to_i
|
|
289
|
+
quotient += 1 if year < remainder
|
|
290
|
+
return quotient * 10 + year
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
def _int(digits)
|
|
294
|
+
return digits ? digits.to_i : nil
|
|
295
|
+
end
|
|
296
|
+
end
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
#
|
|
300
|
+
# ISO 8601 Time Representation
|
|
301
|
+
#
|
|
302
|
+
# see {xml schema}[link:http://www.w3.org/2001/XMLSchema-datatypes#time]
|
|
303
|
+
#
|
|
304
|
+
class Time < DateTime
|
|
305
|
+
|
|
306
|
+
class << self
|
|
307
|
+
# 基本形式の表現を分解して配列化する
|
|
308
|
+
def _to_array_basic(time, t, options={})
|
|
309
|
+
return nil unless t
|
|
310
|
+
return [0] unless time
|
|
311
|
+
time.sub!(/,/, '.')
|
|
312
|
+
unless (time =~ /\A(\d{2}(?:\.\d+)?|-)(\d{2}(?:\.\d+)?|-)?(\d{2}(\.\d+)?)?\z/)
|
|
313
|
+
raise ArgumentError, "Wrong time format: #{time}"
|
|
314
|
+
end
|
|
315
|
+
indices = options[:frame] ? options[:frame].indices : Coordinates::DefaultDateIndices
|
|
316
|
+
abbr = Array(options[:abbr]).dup
|
|
317
|
+
abbr[0..indices.length] = []
|
|
318
|
+
return [0, Coordinates::Pair._en_number($1=='-' ? abbr[0] : $1, nil),
|
|
319
|
+
Coordinates::Pair._en_number($2=='-' ? abbr[1] : $2, nil),
|
|
320
|
+
Coordinates::Pair._en_number($3, nil)]
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
# 拡張形式の表現を分解して配列化する
|
|
324
|
+
def _to_array_extended(time, t, options={})
|
|
325
|
+
return nil unless t
|
|
326
|
+
return [0] unless time
|
|
327
|
+
indices = options[:frame] ? options[:frame].indices : Coordinates::DefaultDateIndices
|
|
328
|
+
abbr = Array(options[:abbr]).dup
|
|
329
|
+
abbr[0..indices.length] = []
|
|
330
|
+
time.sub!(/,/, '.')
|
|
331
|
+
if time =~ /\A([:*=])(.+)/
|
|
332
|
+
time = $2
|
|
333
|
+
tt = [Coordinates::Pair._en_pair(0, $1)]
|
|
334
|
+
else
|
|
335
|
+
tt = [0]
|
|
336
|
+
end
|
|
337
|
+
while time =~ /\A(\d{2}(?:\.\d+)?|-)([:*=])(.+)/
|
|
338
|
+
time = $3
|
|
339
|
+
tt << Coordinates::Pair._en_pair($1=='-' ? abbr.shift : $1, $2)
|
|
340
|
+
end
|
|
341
|
+
case time
|
|
342
|
+
when /\A(\d{2}(\.\d+)?)\z/
|
|
343
|
+
tt << Coordinates::Pair._en_number($1, nil)
|
|
344
|
+
when ''
|
|
345
|
+
else
|
|
346
|
+
raise ArgumentError, "Wrong time format: #{time}"
|
|
347
|
+
end
|
|
348
|
+
return tt
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
# 時間帯の表現を正規化する
|
|
352
|
+
def _to_string_clock(clock)
|
|
353
|
+
return nil unless clock
|
|
354
|
+
return clock if (clock =~ /\A[A-Z]+(\?.+)?\z/)
|
|
355
|
+
raise ArgumentError, "Wrong clock format: #{clock}" unless clock =~ /\A([-+])(\d{2})(?::?(\d{2}))?(?::?(\d{2}))?\z/
|
|
356
|
+
sgn, h, m, s = $~[1..4]
|
|
357
|
+
zone = sgn + h + ':' + (m||'00')
|
|
358
|
+
zone += s if s
|
|
359
|
+
return zone
|
|
360
|
+
end
|
|
361
|
+
end
|
|
362
|
+
end
|
|
363
|
+
|
|
364
|
+
# コード
|
|
365
|
+
#
|
|
366
|
+
# 当該コードを定義している辞書, シソーラスまたは機関への参照を
|
|
367
|
+
# オプショナルな codeSpace 属性に保持することができる文字列
|
|
368
|
+
#
|
|
369
|
+
# see {http://schemas.opengis.net/gml/3.1.1/base/basicTypes.xsd#CodeType gml schema}
|
|
370
|
+
#
|
|
371
|
+
class Code < String
|
|
372
|
+
|
|
373
|
+
# an optional codeSpace
|
|
374
|
+
#
|
|
375
|
+
# @return [String] anyURI (Optional)
|
|
376
|
+
attr_accessor :code_space
|
|
377
|
+
alias :codeSpace :code_space
|
|
378
|
+
private :code_space=
|
|
379
|
+
|
|
380
|
+
# オブジェクトの生成
|
|
381
|
+
#
|
|
382
|
+
# @param [String] code Text token
|
|
383
|
+
# @param [String] namespace code を定義している authority の URI
|
|
384
|
+
#
|
|
385
|
+
def initialize(code, namespace=nil)
|
|
386
|
+
@code_space = namespace
|
|
387
|
+
self[0..-1] = code
|
|
388
|
+
end
|
|
389
|
+
end
|
|
390
|
+
|
|
391
|
+
#
|
|
392
|
+
# == 多言語対応文字列
|
|
393
|
+
#
|
|
394
|
+
# 本ライブラリで用いる諸々の用語を多言語対応で曖昧性なく管理するため
|
|
395
|
+
# Code の subclass として定義する
|
|
396
|
+
#
|
|
397
|
+
# == 内部変数
|
|
398
|
+
# === self[ 0..-1 ] : String
|
|
399
|
+
# インスタンスを代表する文字列
|
|
400
|
+
# 通常の String として振舞う場合は、この文字列として振舞う
|
|
401
|
+
#
|
|
402
|
+
# === @locale : Hash
|
|
403
|
+
# インスタンスがさす言葉の諸言語での表現を文字列として保持する
|
|
404
|
+
# locale指定('lang_country.encoding') => その locale での文字列
|
|
405
|
+
# locale指定の要素に省略がある場合、残った共通の要素によって文字列を特定する
|
|
406
|
+
# Ex. @locale = {'en'=>'March', 'ja'=>'三月'} ならば、locale が
|
|
407
|
+
# 'en_US', 'en_GB' のいずれでもlocale での文字列は 'March'
|
|
408
|
+
#
|
|
409
|
+
# === @namespace : Hash
|
|
410
|
+
# インスタンスがさす言葉の意味を特定するための authority の URI を保持する
|
|
411
|
+
# locale指定('lang_country.encoding') => その locale での authority の URI
|
|
412
|
+
# locale指定の要素に省略がある場合、残った共通の要素によってURIを特定する
|
|
413
|
+
# Ex. @locale = {'en'=>'en:March', 'ja'=>'ja:3%E6%9C%88'} ならば、locale が
|
|
414
|
+
# 'en_US', 'en_GB' のいずれでもlocale での authority の URIは 'en:March'
|
|
415
|
+
# 当該用語が標準管理機関で管理されていない場合、wikipedia の当該項目の URI を用いる
|
|
416
|
+
#
|
|
417
|
+
# === @code_space : String
|
|
418
|
+
# 代表的な authority の URI
|
|
419
|
+
# @namespace[''] である
|
|
420
|
+
#
|
|
421
|
+
# see {When::Locale}, {When::Parts::Resource}
|
|
422
|
+
#
|
|
423
|
+
class M17n < Code
|
|
424
|
+
include When::Locale
|
|
425
|
+
include Parts::Resource
|
|
426
|
+
|
|
427
|
+
# @private
|
|
428
|
+
HashProperty = [:label, :names, :link, :access_key, :code_space]
|
|
429
|
+
|
|
430
|
+
# @private
|
|
431
|
+
LabelTypes = {
|
|
432
|
+
'Residue' => ['Coordinates', '%s', '_co:%s%s' ],
|
|
433
|
+
'Week' => ['CalendarNote', '%sWeek', '_n:%sWeek%s' ],
|
|
434
|
+
'Notes' => ['CalendarNote', '%s', '_n:%s/Notes%s'],
|
|
435
|
+
nil => ['BasicTypes::M17n', '%s', '_m:%s%s' ]
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
class << self
|
|
439
|
+
|
|
440
|
+
#
|
|
441
|
+
# resource の取得
|
|
442
|
+
#
|
|
443
|
+
# @param [When::Parts::Resource, String] source
|
|
444
|
+
#
|
|
445
|
+
# @return [When::Parts::Resource]
|
|
446
|
+
#
|
|
447
|
+
# @private
|
|
448
|
+
def _label(source)
|
|
449
|
+
case source
|
|
450
|
+
when Parts::Resource, nil ; return source
|
|
451
|
+
when Parts::Resource::IRIHeader ; return Parts::Resource._instance(source)
|
|
452
|
+
end
|
|
453
|
+
iri = Parts::Resource._abbreviation_to_iri(source, LabelTypes)
|
|
454
|
+
iri ? Parts::Resource._instance(iri) : nil
|
|
455
|
+
end
|
|
456
|
+
|
|
457
|
+
#
|
|
458
|
+
# label の取得
|
|
459
|
+
#
|
|
460
|
+
# @param [When::Parts::Resource, String] source
|
|
461
|
+
#
|
|
462
|
+
# @return [When::BasicTypes::M17n, String]
|
|
463
|
+
#
|
|
464
|
+
def label(source)
|
|
465
|
+
resource = _label(source)
|
|
466
|
+
case resource
|
|
467
|
+
when nil ; return source
|
|
468
|
+
when M17n ; return resource
|
|
469
|
+
when Parts::Resource ; return resource.label
|
|
470
|
+
else ; return resource
|
|
471
|
+
end
|
|
472
|
+
end
|
|
473
|
+
|
|
474
|
+
#
|
|
475
|
+
# label の Array の取得
|
|
476
|
+
#
|
|
477
|
+
# @param [When::Parts::Resource, Array] source
|
|
478
|
+
#
|
|
479
|
+
# @return [Array]
|
|
480
|
+
#
|
|
481
|
+
def labels(source)
|
|
482
|
+
array =
|
|
483
|
+
if source.kind_of?(Array)
|
|
484
|
+
source
|
|
485
|
+
else
|
|
486
|
+
resource = _label(source)
|
|
487
|
+
return nil unless resource
|
|
488
|
+
resource.child
|
|
489
|
+
end
|
|
490
|
+
case array[0]
|
|
491
|
+
when M17n ; return array
|
|
492
|
+
when Parts::Resource ; return array.map {|v| v.label}
|
|
493
|
+
else ; return array
|
|
494
|
+
end
|
|
495
|
+
end
|
|
496
|
+
end
|
|
497
|
+
|
|
498
|
+
#
|
|
499
|
+
# 代表名
|
|
500
|
+
#
|
|
501
|
+
# @return [String]
|
|
502
|
+
#
|
|
503
|
+
attr_reader :label
|
|
504
|
+
|
|
505
|
+
#
|
|
506
|
+
# 名前が意味するもの自体のオブジェクト
|
|
507
|
+
#
|
|
508
|
+
# @return [When::BasicTypes::Object]
|
|
509
|
+
#
|
|
510
|
+
alias :what :parent
|
|
511
|
+
|
|
512
|
+
#
|
|
513
|
+
# When::BasicTypes::M17n に変換する - 何もしないで自身を返す
|
|
514
|
+
#
|
|
515
|
+
# @return [When::BasicTypes::M17n]
|
|
516
|
+
#
|
|
517
|
+
def to_m17n
|
|
518
|
+
self
|
|
519
|
+
end
|
|
520
|
+
|
|
521
|
+
#
|
|
522
|
+
# 内部エンコーディング文字列化
|
|
523
|
+
#
|
|
524
|
+
def to_internal_encoding
|
|
525
|
+
_copy({:label => When::EncodingConversion.to_internal_encoding(to_s),
|
|
526
|
+
:names => Hash[*(names.keys.map {|name| [name, When::EncodingConversion.to_internal_encoding(names[name])]}).flatten],
|
|
527
|
+
:link => link,
|
|
528
|
+
:access_key => access_key,
|
|
529
|
+
:code_space => code_space
|
|
530
|
+
})
|
|
531
|
+
end
|
|
532
|
+
|
|
533
|
+
#
|
|
534
|
+
# 外部エンコーディング文字列化
|
|
535
|
+
#
|
|
536
|
+
def to_external_encoding
|
|
537
|
+
_copy({:label => When::EncodingConversion.to_external_encoding(to_s),
|
|
538
|
+
:names => Hash[*(names.keys.map {|name| [name, When::EncodingConversion.to_external_encoding(names[name])]}).flatten],
|
|
539
|
+
:link => link,
|
|
540
|
+
:access_key => access_key,
|
|
541
|
+
:code_space => code_space
|
|
542
|
+
})
|
|
543
|
+
end
|
|
544
|
+
|
|
545
|
+
# オブジェクトの生成
|
|
546
|
+
#
|
|
547
|
+
# @overload initialize(names, namespace={}, locale=[])
|
|
548
|
+
# @param [Array<String>] names
|
|
549
|
+
#
|
|
550
|
+
# [String] '*locale:label=prefix:link'
|
|
551
|
+
# * - 存在すれば、label をインスタンスを代表する文字列とする
|
|
552
|
+
# locale - label に対応する locale指定(なければ、locale 引数の指定を用いる)
|
|
553
|
+
# label - locale 指定に対応する label
|
|
554
|
+
# prefix:link - その locale での authority の URI
|
|
555
|
+
# prefix: - namespace 引数の指定により URI に展開する
|
|
556
|
+
# link - なければ labelをURI encodeして用いる
|
|
557
|
+
#
|
|
558
|
+
# @param [Hash] namespace { prefix=>uri }
|
|
559
|
+
#
|
|
560
|
+
# lables, locale 引数の prefix の展開に用いる
|
|
561
|
+
#
|
|
562
|
+
# @param [Array<String>] locale
|
|
563
|
+
#
|
|
564
|
+
# [String] '*locale=prefix:link'
|
|
565
|
+
# * - 存在すれば、label をインスタンスを代表する文字列とする
|
|
566
|
+
# locale - locale指定
|
|
567
|
+
# prefix:link - authority の URI
|
|
568
|
+
# prefix: - namespace 引数の指定により URI に展開する
|
|
569
|
+
#
|
|
570
|
+
# @example
|
|
571
|
+
# M17n.new(['3月', 'fr:Mars=http://fr.wikipedia.org/wiki/Mars_(mois)', 'March'],
|
|
572
|
+
# {'en_wikipedia'=>'http://en.wikipedia.org/wiki/',
|
|
573
|
+
# 'ja_wikipedia'=>'http://ja.wikipedia.org/wiki/'},
|
|
574
|
+
# ['=ja_wikipedia:', '*en=en_wikipedia:']) を行うと、生成された M17n では、
|
|
575
|
+
# @names = {'' =>'3月', 'fr'=>'Mars', 'en'=>'March'}
|
|
576
|
+
# @namespace = {'' =>'http://ja.wikipedia.org/wiki/3%E6%9C%88',
|
|
577
|
+
# 'fr'=>'http://fr.wikipedia.org/wiki/Mars_(mois)',
|
|
578
|
+
# 'en'=>'http://en.wikipedia.org/wiki/March'}
|
|
579
|
+
# となり、通常の String として振舞う場合は 'March' として振舞う
|
|
580
|
+
#
|
|
581
|
+
def initialize(*args)
|
|
582
|
+
rest, options = _attributes(args)
|
|
583
|
+
_sequence
|
|
584
|
+
|
|
585
|
+
return _pool[@label.to_s] ?
|
|
586
|
+
_copy_all(_pool[@label.to_s]) : # 階層になった Resource の代表ラベルのための生成
|
|
587
|
+
_copy(options) if @label # M17n#to_h の出力と書式互換の入力による生成
|
|
588
|
+
|
|
589
|
+
case rest[0]
|
|
590
|
+
when When::Parts::Resource::ContentLine
|
|
591
|
+
content, namespace = rest
|
|
592
|
+
namespace ||= {}
|
|
593
|
+
names = []
|
|
594
|
+
locale = []
|
|
595
|
+
begin
|
|
596
|
+
loc = content.attribute['language'].object
|
|
597
|
+
locale << [nil, loc, namespace[loc]]
|
|
598
|
+
name = content.object
|
|
599
|
+
ref = content.attribute['reference'] || content.attribute['url']
|
|
600
|
+
name += '=' + (/\ANUL\z/i =~ ref.object ? '' : ref.object) if ref
|
|
601
|
+
names << name
|
|
602
|
+
end while (content = content.same_altid)
|
|
603
|
+
@names ||= names.reverse
|
|
604
|
+
@namespace ||= namespace if namespace.kind_of?(Hash)
|
|
605
|
+
@locale ||= locale.reverse
|
|
606
|
+
when nil ;
|
|
607
|
+
else
|
|
608
|
+
names, namespace, locale = rest
|
|
609
|
+
@names = names if names
|
|
610
|
+
@namespace ||= When::Locale._namespace(namespace) if namespace
|
|
611
|
+
@locale ||= When::Locale._locale(locale) if locale
|
|
612
|
+
end
|
|
613
|
+
@namespace ||= {}
|
|
614
|
+
@locale ||= []
|
|
615
|
+
|
|
616
|
+
@code_space = @namespace['']
|
|
617
|
+
self[0..-1] = @label = _names(@names, @namespace, @locale)
|
|
618
|
+
end
|
|
619
|
+
end
|
|
620
|
+
|
|
621
|
+
#
|
|
622
|
+
# Abstract class for instance having permanent life with IRI
|
|
623
|
+
#
|
|
624
|
+
# see {When::Parts::Resource}
|
|
625
|
+
# see {http://schemas.opengis.net/gml/3.1.1/base/basicTypes.xsd#ObjectType gml schema}
|
|
626
|
+
#
|
|
627
|
+
class Object
|
|
628
|
+
|
|
629
|
+
include Parts::Resource
|
|
630
|
+
|
|
631
|
+
# 名前
|
|
632
|
+
#
|
|
633
|
+
# @return [String, When::BasicTypes::M17n]
|
|
634
|
+
#
|
|
635
|
+
attr_reader :label
|
|
636
|
+
|
|
637
|
+
private
|
|
638
|
+
|
|
639
|
+
# オブジェクトの初期化
|
|
640
|
+
def initialize(*args)
|
|
641
|
+
@_lock_ = Mutex.new if When.multi_thread
|
|
642
|
+
_normalize(*_attributes(args))
|
|
643
|
+
_sequence
|
|
644
|
+
end
|
|
645
|
+
end
|
|
646
|
+
end
|
|
647
|
+
|
|
648
|
+
#
|
|
649
|
+
# RS::Identifier を提供する
|
|
650
|
+
#
|
|
651
|
+
module RS
|
|
652
|
+
|
|
653
|
+
# 参照系の識別子
|
|
654
|
+
#
|
|
655
|
+
# see {http://schemas.opengis.net/gml/3.1.1/base/referenceSystems.xsd#IdentifierType gml schema}
|
|
656
|
+
#
|
|
657
|
+
class Identifier
|
|
658
|
+
|
|
659
|
+
# The code or name for this Identifier
|
|
660
|
+
#
|
|
661
|
+
# @return [When::BasicTypes::Code]
|
|
662
|
+
#
|
|
663
|
+
attr_reader :name
|
|
664
|
+
|
|
665
|
+
# Identifier of the version of the associated codeSpace or code
|
|
666
|
+
#
|
|
667
|
+
# @return [Array<String>]
|
|
668
|
+
#
|
|
669
|
+
attr_reader :version
|
|
670
|
+
|
|
671
|
+
# Remarks about this code or alias
|
|
672
|
+
#
|
|
673
|
+
# @return [Array<String>] String は URI/IRI文字列の場合あり
|
|
674
|
+
#
|
|
675
|
+
attr_reader :remarks
|
|
676
|
+
|
|
677
|
+
# オブジェクトの生成
|
|
678
|
+
#
|
|
679
|
+
# @param [When::BasicTypes::Code] name
|
|
680
|
+
# @param [Array<String>] version
|
|
681
|
+
# @param [Array<String>] remarks String は URI/IRI文字列の場合あり
|
|
682
|
+
#
|
|
683
|
+
def initialize(name, version=nil, remarks=nil)
|
|
684
|
+
@name = name
|
|
685
|
+
@version = version
|
|
686
|
+
@remarks = remarks
|
|
687
|
+
end
|
|
688
|
+
|
|
689
|
+
# その他のメソッド
|
|
690
|
+
#
|
|
691
|
+
# @note When::RS::Identifier で定義されていないメソッドは
|
|
692
|
+
# 処理を @name (type: When::BasicTypes::Code) に委譲する
|
|
693
|
+
#
|
|
694
|
+
def method_missing(name, *args, &block)
|
|
695
|
+
self.class.module_eval %Q{
|
|
696
|
+
def #{name}(*args, &block)
|
|
697
|
+
@name.send("#{name}", *args, &block)
|
|
698
|
+
end
|
|
699
|
+
} unless When::Parts::MethodCash.escape(name)
|
|
700
|
+
@name.send(name, *args, &block)
|
|
701
|
+
end
|
|
702
|
+
end
|
|
703
|
+
end
|
|
704
|
+
|
|
705
|
+
#
|
|
706
|
+
# EX::Extent を提供する
|
|
707
|
+
#
|
|
708
|
+
module EX
|
|
709
|
+
|
|
710
|
+
# 参照系の時間的および空間的な使用範囲を記述する
|
|
711
|
+
#
|
|
712
|
+
# 本ライブラリでは、時間的使用範囲を記述ためにのみ使用している
|
|
713
|
+
#
|
|
714
|
+
# see {http://schemas.opengis.net/gml/3.1.1/base/referenceSystems.xsd#ExtentType gml schema}
|
|
715
|
+
#
|
|
716
|
+
class Extent
|
|
717
|
+
|
|
718
|
+
# time periods
|
|
719
|
+
#
|
|
720
|
+
# 時間的使用範囲の上限と下限を示す
|
|
721
|
+
#
|
|
722
|
+
# @return [When::TM::Period]
|
|
723
|
+
#
|
|
724
|
+
attr_reader :temporal_extent
|
|
725
|
+
alias :temporalExtent :temporal_extent
|
|
726
|
+
|
|
727
|
+
# オブジェクトの生成
|
|
728
|
+
#
|
|
729
|
+
# @param [When::TM::Period] extent
|
|
730
|
+
#
|
|
731
|
+
def initialize(extent)
|
|
732
|
+
@temporal_extent = extent
|
|
733
|
+
end
|
|
734
|
+
|
|
735
|
+
# その他のメソッド
|
|
736
|
+
#
|
|
737
|
+
# @note When::EX::Extent で定義されていないメソッドは
|
|
738
|
+
# 処理を @temporal_extent (type: When::TM::Period) に委譲する
|
|
739
|
+
#
|
|
740
|
+
def method_missing(name, *args, &block)
|
|
741
|
+
self.class.module_eval %Q{
|
|
742
|
+
def #{name}(*args, &block)
|
|
743
|
+
list = args.map {|arg| arg.kind_of?(self.class) ? arg.temporal_extent : arg}
|
|
744
|
+
@temporal_extent.send("#{name}", *list, &block)
|
|
745
|
+
end
|
|
746
|
+
} unless When::Parts::MethodCash.escape(name)
|
|
747
|
+
list = args.map {|arg| arg.kind_of?(self.class) ? arg.temporal_extent : arg}
|
|
748
|
+
@temporal_extent.send(name, *list, &block)
|
|
749
|
+
end
|
|
750
|
+
end
|
|
751
|
+
end
|
|
752
|
+
end
|