when_exe 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 61a3f8c00d80359403cc75825c11f1945bce2c28
4
- data.tar.gz: ebe31639b5e037a4ffba17a75005e7136b0827b5
3
+ metadata.gz: 21ef2902a6f6e66f6b217b300ec63d0cfe4b3ec1
4
+ data.tar.gz: e132d01708f7eaac9e2246faeec19b5843551422
5
5
  SHA512:
6
- metadata.gz: fe803b369afa1fd2ab944705c2ad4a766b687491759dd18474cfd0239f344a8d30bb8fdff2207881d5f04762d2c02d73d0615fbdc8eb549cd27c0bb200ef1929
7
- data.tar.gz: 67420672b88943d9247dba224d996eca6474220bf6f508b60ed9449f9164407a09e37f97596ac305873085e5c4a13a0d261acb8e4a2740bd706c00450f128154
6
+ metadata.gz: 1622bb678b6adfce5e1c54a91889ede8bb675fa3add66a01eba031910bbc3f11e45c2cbb5c4b24ac46bd22a9d3984d30f621f6e5c1e67d5430ca7d7cd4b142c3
7
+ data.tar.gz: 09f2ceda494e0e731593468051147ec22845827847a0f35f75ab9ca8b3969a6ea3154d8b5becc01ff80e302a30649b29a424cd34b86d804a2646a3b807f0dd36
data/README.md CHANGED
@@ -1,212 +1,333 @@
1
- when_exe - A multicultural and multilingualized calendar library
2
- ================================================================
3
-
4
- [![Gem Version](https://badge.fury.io/rb/when_exe.svg)](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](http://en.wikipedia.org/wiki/ISO_8601), [ISO 19108](http://www.iso.org/iso/home/store/catalogue_tc/catalogue_detail.htm?csnumber=26013), [RFC 5545(iCalendar)](http://tools.ietf.org/html/rfc5545) and [RFC6350](http://tools.ietf.org/html/rfc6350).
7
-
8
- [<img alt='Architecture' title='display this figure at actual size' src='https://raw.githubusercontent.com/suchowan/when_exe/f7bb8b51259f0c1653c6c37b3ce20bd2a6ab7914/architecture.png' width='637' height='408'/>](https://raw.githubusercontent.com/suchowan/when_exe/f7bb8b51259f0c1653c6c37b3ce20bd2a6ab7914/architecture.png)
9
-
10
- Installation
11
- ------------
12
-
13
- The when_exe gem can be installed by running:
14
-
15
- gem install when_exe
16
-
17
-
18
- Web Server
19
- ----------
20
-
21
- Web server for when_exe demonstration is available on [hosi.org](http://hosi.org).
22
-
23
- You can see examples of [When.exe Standard Representation](http://www.asahi-net.or.jp/~dd6t-sg/when_rdoc/when_en.html#label-8) and Reference System IRI at the top-left corner of Date frame.
24
-
25
- Preferences are changeable on [hosi.org/cookies](http://hosi.org/cookies).
26
-
27
-
28
- Documentation
29
- -------------
30
-
31
- API documentation for when_exe is available on [RubyDoc.info](http://rubydoc.info/gems/when_exe).
32
-
33
- Available calendars and clocks are defined as subclasses of TM_Calendar and TM_Clock or using definition tables in [CalendarTypes namespace](http://rubydoc.info/gems/when_exe/When/CalendarTypes).
34
-
35
- Available calendar eras are defined using definition tables in [CalendarEra namespace](http://rubydoc.info/gems/when_exe/When/TM/CalendarEra).
36
-
37
- Whole TemporalReferenceSystem resources are listed in the [Resource Dictionary](http://www2u.biglobe.ne.jp/~suchowan/ResourceDictionary.html).
38
-
39
- License
40
- -------
41
-
42
- This beta version's license is limited. Please see [LICENSE.txt](https://github.com/suchowan/when_exe/blob/master/LICENSE.txt) for details.
43
-
44
-
45
- Source Code
46
- -----------
47
-
48
- Source code for when_exe is available on [GitHub](https://github.com/suchowan/when_exe).
49
-
50
-
51
- Example Usage
52
- -------------
53
-
54
- require 'when_exe'
55
-
56
- # When::TM::CalDate ---------------------------
57
-
58
- gregorian_date = When.tm_pos(2014, 8, 1)
59
- p gregorian_date #=> 2014-08-01
60
- p When.when?('2014-08-01') #=> 2014-08-01, the same date
61
- p gregorian_date.to_i #=> 2456871, Julian Day Number(Integer)
62
- p gregorian_date.to_f #=> 2456871.0, at noon for UTC
63
- p gregorian_date.class #=> When::TM::CalDate
64
- p gregorian_date.frame.iri #=> "http://hosi.org/When/CalendarTypes/Gregorian"
65
- puts gregorian_date.name(When::MONTH).class #=> When::BasicTypes::M17n
66
- puts gregorian_date.name(When::MONTH).iri #=> http://hosi.org/When/BasicTypes/M17n/Calendar::Month::August
67
- puts gregorian_date.name(When::MONTH) / 'en' #=> August
68
- puts gregorian_date.name(When::MONTH) / 'fr' #=> août
69
- puts gregorian_date.name(When::MONTH) / 'ar' #=> اغسطس
70
- p gregorian_date.easter #=> 2014-04-20
71
- p gregorian_date.is?('Easter') #=> false
72
- p When.tm_pos(2014, 4, 20).is?('Easter') #=> true
73
-
74
- islamic_date = When::TabularIslamic ^ gregorian_date
75
- p islamic_date #=> 1435-10-04
76
- p When.tm_pos(1435, 10, 4, :frame=>'TabularIslamic')
77
- #=> 1435-10-04, the same date
78
- p When.when?('1435-10-4^TabularIslamic') #=> 1435-10-04, the same date
79
- p islamic_date.frame.iri #=> "http://hosi.org/When/CalendarTypes/TabularIslamic"
80
- puts islamic_date.name(When::MONTH) / 'en' #=> Shawwal
81
- puts islamic_date.name(When::MONTH) / 'ar' #=> شوال
82
-
83
- # When::TM::DateAndTime ------------------------
84
-
85
- gregorian_date = When.tm_pos(2014, 8, 1, 9, 0, 0, :clock=>'+09:00')
86
- p gregorian_date #=> 2014-08-01T09:00:00+09:00
87
- p When.when?('2014-08-01T09:00:00+09:00') #=> 2014-08-01T09:00:00+09:00, the same date
88
- p gregorian_date.to_i #=> 2456871, Julian Day Number(Integer)
89
- p gregorian_date.to_f #=> 2456870.5 at 09:00:00 of Timezone +09:00
90
- p gregorian_date.class #=> When::TM::DateAndTime
91
- p gregorian_date.frame.iri #=> "http://hosi.org/When/CalendarTypes/Gregorian"
92
- p gregorian_date.clk_time.class #=> When::TM::ClockTime
93
- p gregorian_date.clk_time.frame.iri #=> "http://hosi.org/When/TM/Clock?label=+09:00"
94
-
95
- gregorian_date = When.tm_pos(2014, 8, 1, 9, 0, 0, :clock=>'+09:00',
96
- :long=>'139.413012E', :lat=>'35.412222N')
97
- p gregorian_date #=> 2014-08-01T09:00:00+09:00
98
- p gregorian_date.location.iri #=> "http://hosi.org/When/Coordinates/Spatial?long=139.413012E&lat=35.412222N&alt=0"
99
- p gregorian_date.sunrise.floor(When::MINUTE) #=> 2014-08-01T04:48+09:00
100
- p gregorian_date.sunset.floor(When::MINUTE) #=> 2014-08-01T18:46+09:00
101
-
102
- darian_date = When::Darian ^ gregorian_date
103
- p darian_date #=> 0216-13-23T15:12:11MTC
104
- p darian_date.to_i #=> 49974, Serial Day Number(Integer)
105
- p darian_date.to_f #=> 49974.13346485421
106
- p darian_date.frame.iri #=> "http://hosi.org/When/CalendarTypes/Darian"
107
- p darian_date.clk_time.frame.iri #=> "http://hosi.org/When/CalendarTypes/MTC"
108
- p darian_date.time_standard.iri #=> "http://hosi.org/When/TimeStandard/MartianTimeCoordinated?location=(_l:long=0&datum=Mars)"
109
-
110
- # When::TM::CalendarEra ------------------------
111
-
112
- babylonian_date = When.tm_pos('NebuchadnezzarII', 1, 1, 1)
113
- p babylonian_date #=> NebuchadnezzarII01(-603).01.01
114
- p When.when?('NebuchadnezzarII1.1.1') #=> NebuchadnezzarII01(-603).01.01, the same date
115
- p babylonian_date.to_i #=> 1500904, Julian Day Number(Integer)
116
- p When.era('NebuchadnezzarII') #=> [_e:AncientOrient::Neo-Babylonian::NebuchadnezzarII]
117
- p When.era('NebuchadnezzarII')[0] ^ 1500904 #=> NebuchadnezzarII01(-603).01.01, the same date
118
- p babylonian_date.to_f #=> 1500904.0, at noon for UTC
119
- p babylonian_date.frame.iri #=> "http://hosi.org/When/CalendarTypes/BabylonianPD"
120
- p babylonian_date.calendar_era.iri #=> "http://hosi.org/When/TM/CalendarEra/AncientOrient::Neo-Babylonian::NebuchadnezzarII"
121
-
122
- babylonian_date = When.when?('NebuchadnezzarII1.1.1T18:13:00',
123
- :clock=>'+03:00?long=45&lat=32&border=Sunset')
124
- 4.times do
125
- p [babylonian_date, babylonian_date.to_i] #=>
126
- # [NebuchadnezzarII01(-603).01.01T:18:13:00+03:00, 1500904]
127
- # [NebuchadnezzarII01(-603).01.01T:18:14:00+03:00, 1500904]
128
- # [NebuchadnezzarII01(-603).01.02T*18:15:00+03:00, 1500905]
129
- # [NebuchadnezzarII01(-603).01.02T*18:16:00+03:00, 1500905]
130
- babylonian_date += When::PT1M
131
- end
132
-
133
- # Web service ----------------------------------
134
- # retrieve JSON response from http://hosi.org:3000 (when_exe demonstration web server)
135
- require 'open-uri'
136
- open('http://hosi.org:3000/Date/2014-04-20.json') do |json|
137
- puts json.read #=> newlines and blanks are inserted for readability.
138
- # {"frame" : "http://hosi.org/When/CalendarTypes/Gregorian",
139
- # "precision": 0,
140
- # "location" : "http://hosi.org/When/Coordinates/Spatial?long=139.4441E&lat=35.3916N&alt=0.0",
141
- # "sdn" : 2456768,
142
- # "calendar" : ["http://hosi.org/When/CalendarTypes/Gregorian"],
143
- # "notes" : [[{"note":"Month","value":"April"}],
144
- # [{"note":"Week","value":"Sunday(6)"}]],
145
- # "clock" : "Asia/Tokyo+09:00",
146
- # "clk_time" : [2456768,0,0,0],
147
- # "dynamical": 1397919667.184082,
148
- # "universal": 1397919600.0,
149
- # "cal_date" : [2014,4,20]}
150
- end
151
-
152
- # TZInfo --------------------------------------
153
- # https://rubygems.org/gems/tzinfo is required for this section's operations.
154
- # Please install tzinfo before operation.
155
-
156
- gregorian_date = When.tm_pos(2014, 8, 1, 9, 0, 0, :tz=>'Asia/Tokyo')
157
- p gregorian_date #=> 2014-08-01T09:00:00+09:00
158
- p gregorian_date.location.iri #=> "http://hosi.org/When/Coordinates/Spatial?long=139.4441E&lat=35.3916N&label=Asia/Tokyo"
159
- p gregorian_date.sunrise.floor(When::MINUTE) #=> 2014-08-01T04:48+09:00
160
- p gregorian_date.sunset.floor(When::MINUTE) #=> 2014-08-01T18:45+09:00
161
-
162
- jst = When.tm_pos(1997, 4, 6, 15, 30, 00, :tz=>'Asia/Tokyo')
163
- p jst #=> 1997-04-06T15:30:00+09:00
164
- est = When.Clock('America/New_York') ^ jst
165
- p est #=> 1997-04-06T01:30:00-05:00
166
- jst = When.tm_pos(1997, 4, 6, 16, 30, 00, :tz=>'Asia/Tokyo')
167
- p jst #=> 1997-04-06T16:30:00+09:00
168
- edt = When.Clock('America/New_York') ^ jst
169
- p edt #=> 1997-04-06T03:30:00-04:00
170
-
171
- p When.when?('TZID=America/New_York:1997-10-26T01:30') #=> 1997-10-26T01:30-04:00
172
- p When.when?('TZID=America/New_York:1997-10-26T01=30') #=> 1997-10-26T01:30-05:00, '=' indicates "leap hour"
173
- p When.when?('TZID=America/New_York:1997-10-26T02:30') #=> 1997-10-26T02:30-05:00
174
- p When.when?('TZID=America/New_York:1997-10-26T03:30') #=> 1997-10-26T03:30-05:00
175
-
176
- # Google Calendar ------------------------------
177
- # https://github.com/suchowan/gcalapi is required for this section's operations.
178
- # Please install gcalapi before operation.
179
- # Please replace xxxxxxxx and ******** to valid id/password pair and access Google Calendar.
180
-
181
- service = GoogleCalendar::Service.new('xxxxxxxx@gmail.com', '********')
182
- feed = "http://www.google.com/calendar/feeds/%s__%s%%40holiday.calendar.google.com/public/full" %
183
- ['japanese', 'ja']
184
- gcal = GoogleCalendar::Calendar::new(service, feed)
185
- gcal.enum_for({'start-min'=>'2014-01-01', 'start-max'=>'2015-01-01',
186
- 'orderby'=>'starttime', 'sortorder'=>'a'
187
- }).each do |range|
188
- puts '%s - %s' % [range, range.events[0].summary] #=>
189
- # 2014-01-01T00:00:00.00+09:00...2014-01-02T00:00:00.00+09:00 - 元日
190
- # 2014-01-02T00:00:00.00+09:00...2014-01-03T00:00:00.00+09:00 - 銀行休業日
191
- # 2014-01-03T00:00:00.00+09:00...2014-01-04T00:00:00.00+09:00 - 銀行休業日
192
- # 2014-01-13T00:00:00.00+09:00...2014-01-14T00:00:00.00+09:00 - 成人の日
193
- # 2014-02-11T00:00:00.00+09:00...2014-02-12T00:00:00.00+09:00 - 建国記念の日
194
- # 2014-03-21T00:00:00.00+09:00...2014-03-22T00:00:00.00+09:00 - 春分の日
195
- # 2014-04-29T00:00:00.00+09:00...2014-04-30T00:00:00.00+09:00 - 昭和の日
196
- # 2014-05-03T00:00:00.00+09:00...2014-05-04T00:00:00.00+09:00 - 憲法記念日
197
- # 2014-05-04T00:00:00.00+09:00...2014-05-05T00:00:00.00+09:00 - みどりの日
198
- # 2014-05-05T00:00:00.00+09:00...2014-05-06T00:00:00.00+09:00 - こどもの日
199
- # 2014-05-06T00:00:00.00+09:00...2014-05-07T00:00:00.00+09:00 - みどりの日 振替休日
200
- # 2014-07-21T00:00:00.00+09:00...2014-07-22T00:00:00.00+09:00 - 海の日
201
- # 2014-09-15T00:00:00.00+09:00...2014-09-16T00:00:00.00+09:00 - 敬老の日
202
- # 2014-09-23T00:00:00.00+09:00...2014-09-24T00:00:00.00+09:00 - 秋分の日
203
- # 2014-10-13T00:00:00.00+09:00...2014-10-14T00:00:00.00+09:00 - 体育の日
204
- # 2014-11-03T00:00:00.00+09:00...2014-11-04T00:00:00.00+09:00 - 文化の日
205
- # 2014-11-23T00:00:00.00+09:00...2014-11-24T00:00:00.00+09:00 - 勤労感謝の日
206
- # 2014-11-24T00:00:00.00+09:00...2014-11-25T00:00:00.00+09:00 - 勤労感謝の日 振替休日
207
- # 2014-12-23T00:00:00.00+09:00...2014-12-24T00:00:00.00+09:00 - 天皇誕生日
208
- # 2014-12-25T00:00:00.00+09:00...2014-12-26T00:00:00.00+09:00 - クリスマス
209
- # 2014-12-31T00:00:00.00+09:00...2015-01-01T00:00:00.00+09:00 - 大晦日
210
- end
211
-
212
- For further detail, please refer to the [when_exe Wiki](http://www2u.biglobe.ne.jp/~suchowan/when_exe_wiki.html) pages.
1
+ when_exe - A multicultural and multilingualized calendar library
2
+ ================================================================
3
+
4
+ [![Gem Version](https://badge.fury.io/rb/when_exe.svg)](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](http://en.wikipedia.org/wiki/ISO_8601), [ISO 19108](http://www.iso.org/iso/home/store/catalogue_tc/catalogue_detail.htm?csnumber=26013), [RFC 5545(iCalendar)](http://tools.ietf.org/html/rfc5545) and [RFC6350](http://tools.ietf.org/html/rfc6350). JSON-LD format for TemporalPosition and TemporalReferenceSystem are available.
7
+
8
+ [<img alt='Architecture' title='display this figure at actual size' src='https://raw.githubusercontent.com/suchowan/when_exe/f7bb8b51259f0c1653c6c37b3ce20bd2a6ab7914/architecture.png' width='637' height='408'/>](https://raw.githubusercontent.com/suchowan/when_exe/f7bb8b51259f0c1653c6c37b3ce20bd2a6ab7914/architecture.png)
9
+
10
+ Installation
11
+ ------------
12
+
13
+ The when_exe gem can be installed by running:
14
+
15
+ gem install when_exe
16
+
17
+
18
+ Web Server
19
+ ----------
20
+
21
+ Web server for when_exe demonstration is available on [hosi.org](http://hosi.org) ( or mirror site [hosi-org.herokuapp.com](http://hosi-org.herokuapp.com) ).
22
+
23
+ You can see examples of [When.exe Standard Representation](http://www.asahi-net.or.jp/~dd6t-sg/when_rdoc/when_en.html#label-8) and Reference System IRI at the top-left corner of Date frame.
24
+
25
+ Preferences are changeable on [hosi.org/cookies](http://hosi.org/cookies).
26
+
27
+ SPARQL endpoint is [hosi.org/japan/sparql](http://hosi.org/japan/sparql).
28
+
29
+
30
+ Documentation
31
+ -------------
32
+
33
+ API documentation for when_exe is available on [RubyDoc.info](http://rubydoc.info/gems/when_exe) or [here](http://www2u.biglobe.ne.jp/~suchowan/when_exe/frames.html).
34
+
35
+ Available calendars and clocks are defined as subclasses of TM_Calendar and TM_Clock or using definition tables in [CalendarTypes namespace](http://rubydoc.info/gems/when_exe/When/CalendarTypes).
36
+
37
+ Available calendar eras are defined using definition tables in [CalendarEra namespace](http://rubydoc.info/gems/when_exe/When/TM/CalendarEra).
38
+
39
+ Whole TemporalReferenceSystem resources are listed in the [Resource Dictionary](http://www2u.biglobe.ne.jp/~suchowan/ResourceDictionary.html).
40
+
41
+ For further detail, please refer to the [when_exe Wiki](http://www2u.biglobe.ne.jp/~suchowan/when_exe_wiki.html) pages.
42
+
43
+
44
+ License
45
+ -------
46
+
47
+ This beta version's license is limited. Please see [LICENSE.txt](https://github.com/suchowan/when_exe/blob/master/LICENSE.txt) for details.
48
+
49
+ Data sets [TemporalPositionDataSet](http://hosi.org/tp.rdf) and [TemporalReferenceSystemDataSet](http://hosi.org/When.rdf) should be used according to [CC-BY-ND](http://creativecommons.org/licenses/by-nd/4.0/) license.
50
+
51
+
52
+ Source Code
53
+ -----------
54
+
55
+ Source code for when_exe is available on [GitHub](https://github.com/suchowan/when_exe).
56
+
57
+
58
+ Example Usage
59
+ -------------
60
+
61
+ require 'when_exe'
62
+ # include When
63
+
64
+ # When::TM::CalDate ---------------------------
65
+
66
+ gregorian_date = When.tm_pos(2014, 8, 1)
67
+ p gregorian_date #=> 2014-08-01
68
+ p When.when?('2014-08-01') #=> 2014-08-01, the same date
69
+ p gregorian_date.to_i #=> 2456871, Julian Day Number(Integer)
70
+ p gregorian_date.to_f #=> 2456871.0, at noon for UTC
71
+ p gregorian_date.class #=> When::TM::CalDate
72
+ p gregorian_date.frame.iri #=> "http://hosi.org/When/CalendarTypes/Gregorian"
73
+ puts gregorian_date.name(When::MONTH).class #=> When::BasicTypes::M17n
74
+ puts gregorian_date.name(When::MONTH).iri #=> http://hosi.org/When/BasicTypes/M17n/Calendar::Month::August
75
+ puts gregorian_date.name(When::MONTH) / 'en' #=> August
76
+ puts gregorian_date.name(When::MONTH) / 'fr' #=> août
77
+ puts gregorian_date.name(When::MONTH) / 'ar' #=> اغسطس
78
+ p gregorian_date.easter #=> 2014-04-20
79
+ p gregorian_date.is?('Easter') #=> false
80
+ p When.tm_pos(2014, 4, 20).is?('Easter') #=> true
81
+
82
+ islamic_date = When::TabularIslamic ^ gregorian_date
83
+ p islamic_date #=> 1435-10-04
84
+ p When.tm_pos(1435, 10, 4, :frame=>'TabularIslamic')
85
+ #=> 1435-10-04, the same date
86
+ p When.when?('1435-10-4^TabularIslamic') #=> 1435-10-04, the same date
87
+ p islamic_date.frame.iri #=> "http://hosi.org/When/CalendarTypes/TabularIslamic"
88
+ puts islamic_date.name(When::MONTH) / 'en' #=> Shawwal
89
+ puts islamic_date.name(When::MONTH) / 'ar' #=> شوال
90
+
91
+ # When::TM::DateAndTime ------------------------
92
+
93
+ gregorian_date = When.tm_pos(2014, 8, 1, 9, 0, 0, :clock=>'+09:00')
94
+ p gregorian_date #=> 2014-08-01T09:00:00+09:00
95
+ p When.when?('2014-08-01T09:00:00+09:00') #=> 2014-08-01T09:00:00+09:00, the same date
96
+ p gregorian_date.to_i #=> 2456871, Julian Day Number(Integer)
97
+ p gregorian_date.to_f #=> 2456870.5 at 09:00:00 of Timezone +09:00
98
+ p gregorian_date.class #=> When::TM::DateAndTime
99
+ p gregorian_date.frame.iri #=> "http://hosi.org/When/CalendarTypes/Gregorian"
100
+ p gregorian_date.clk_time.class #=> When::TM::ClockTime
101
+ p gregorian_date.clk_time.frame.iri #=> "http://hosi.org/When/TM/Clock?label=+09:00"
102
+
103
+ gregorian_date = When.tm_pos(2014, 8, 1, 9, 0, 0, :clock=>'+09:00',
104
+ :long=>'139.413012E', :lat=>'35.412222N')
105
+ p gregorian_date #=> 2014-08-01T09:00:00+09:00
106
+ p gregorian_date.location.iri #=> "http://hosi.org/When/Coordinates/Spatial?long=139.413012E&lat=35.412222N&alt=0"
107
+ p gregorian_date.sunrise.floor(When::MINUTE) #=> 2014-08-01T04:48+09:00
108
+ p gregorian_date.sunset.floor(When::MINUTE) #=> 2014-08-01T18:46+09:00
109
+
110
+ darian_date = When::Darian ^ gregorian_date
111
+ p darian_date #=> 0216-13-23T15:12:11MTC
112
+ p darian_date.to_i #=> 49974, Serial Day Number(Integer)
113
+ p darian_date.to_f #=> 49974.13346485421
114
+ p darian_date.frame.iri #=> "http://hosi.org/When/CalendarTypes/Darian"
115
+ p darian_date.clk_time.frame.iri #=> "http://hosi.org/When/CalendarTypes/MTC"
116
+ p darian_date.time_standard.iri #=> "http://hosi.org/When/TimeStandard/MartianTimeCoordinated?location=(_l:long=0&datum=Mars)"
117
+
118
+ # When::TM::CalendarEra ------------------------
119
+
120
+ babylonian_date = When.tm_pos('NebuchadnezzarII', 1, 1, 1)
121
+ p babylonian_date #=> NebuchadnezzarII01(-603).01.01
122
+ p When.when?('NebuchadnezzarII1.1.1') #=> NebuchadnezzarII01(-603).01.01, the same date
123
+ p babylonian_date.to_i #=> 1500904, Julian Day Number(Integer)
124
+ p When.era('NebuchadnezzarII') #=> [_e:AncientOrient::Neo-Babylonian::NebuchadnezzarII]
125
+ p When.era('NebuchadnezzarII')[0] ^ 1500904 #=> NebuchadnezzarII01(-603).01.01, the same date
126
+ p babylonian_date.to_f #=> 1500904.0, at noon for UTC
127
+ p babylonian_date.frame.iri #=> "http://hosi.org/When/CalendarTypes/BabylonianPD"
128
+ p babylonian_date.calendar_era.iri #=> "http://hosi.org/When/TM/CalendarEra/AncientOrient::Neo-Babylonian::NebuchadnezzarII"
129
+
130
+ babylonian_date = When.when?('NebuchadnezzarII1.1.1T18:13:00',
131
+ :clock=>'+03:00?long=45&lat=32&border=Sunset')
132
+ 4.times do
133
+ p [babylonian_date, babylonian_date.to_i] #=>
134
+ # [NebuchadnezzarII01(-603).01.01T:18:13:00+03:00, 1500904]
135
+ # [NebuchadnezzarII01(-603).01.01T:18:14:00+03:00, 1500904]
136
+ # [NebuchadnezzarII01(-603).01.02T*18:15:00+03:00, 1500905]
137
+ # [NebuchadnezzarII01(-603).01.02T*18:16:00+03:00, 1500905]
138
+ babylonian_date += When::PT1M
139
+ end
140
+
141
+ # Web service ----------------------------------
142
+ # retrieve JSON, JSON-LD, Turtle response from http://hosi.org:3000 (when_exe demonstration web server)
143
+ # (Notation3, RDF/XML, N-Triples and XML formats are also available.)
144
+ require 'open-uri'
145
+ open('http://hosi.org:3000/Date/2014-04-20.json') do |json|
146
+ puts json.read #=> newlines and blanks are inserted for readability.
147
+ # {"frame" : "http://hosi.org/When/CalendarTypes/Gregorian",
148
+ # "precision": 0,
149
+ # "location" : "http://hosi.org/When/Coordinates/Spatial?long=139.4441E&lat=35.3916N&alt=0.0",
150
+ # "sdn" : 2456768,
151
+ # "calendar" : ["http://hosi.org/When/CalendarTypes/Gregorian"],
152
+ # "notes" : [[{"note":"Month","value":"April"}],
153
+ # [{"note":"Week","value":"Sunday(6)"}]],
154
+ # "clock" : "Asia/Tokyo+09:00",
155
+ # "clk_time" : [2456768,0,0,0],
156
+ # "dynamical": 1397919667.184082,
157
+ # "universal": 1397919600.0,
158
+ # "cal_date" : [2014,4,20]}
159
+ end
160
+
161
+ open('http://hosi.org/tp/2014-04-20.json') do |json| # redirected from http://hosi.org to http://hosi.org:3000
162
+ puts json.read #=> newlines and blanks are inserted for readability.
163
+ # {"frame" : "http://hosi.org/When/CalendarTypes/Gregorian",
164
+ # "precision": 0,
165
+ # "sdn" : 2456768,
166
+ # "calendar" : ["http://hosi.org/When/CalendarTypes/Gregorian"],
167
+ # "notes" : [[{"note":"Month","value":"April"}],
168
+ # [{"note":"Week","value":"Sunday(6)"}]],
169
+ # "cal_date" : [2014,4,20]}
170
+ end
171
+
172
+ open('http://hosi.org/tp/2014-04-20.jsonld') do |jsonld| # redirected from http://hosi.org to http://hosi.org:3000
173
+ puts jsonld.read #=> newlines and blanks are inserted for readability.
174
+ # {"@context":
175
+ # {"xsd" :"http://www.w3.org/2001/XMLSchema",
176
+ # "rdf" :"http://www.w3.org/1999/02/22-rdf-syntax-ns#",
177
+ # "rdfs":"http://www.w3.org/2000/01/rdf-schema#",
178
+ # "owl" :"http://www.w3.org/2002/07/owl#",
179
+ # "dc" :"http://purl.org/dc/elements/1.1/",
180
+ # "dcq" :"http://purl.org/dc/terms/",
181
+ # "dct" :"http://purl.org/dc/dcmitype/",
182
+ # "ts" :"http://hosi.org/ts#",
183
+ # "Week":"http://hosi.org/When/Coordinates/Common::Week::",
184
+ # "day" :"http://hosi.org/When/CalendarNote/Christian/Notes::day::"},
185
+ # "@graph":[{
186
+ # "rdf:type" : {"@id":"http://hosi.org/ts/When/TM/CalDate"},
187
+ # "@id" : "http://hosi.org/tp/2014-04-20",
188
+ # "ts:sdn" : 2456768,
189
+ # "ts:frame" : {"@id":"http://hosi.org/When/CalendarTypes/Gregorian"},
190
+ # "ts:coordinate": "20",
191
+ # "@reverse" : {"rdfs:member":{"@id":"http://hosi.org/tp/2014-04"}},
192
+ # "day:Week" : {"@id":"Week:Sunday"},
193
+ # "day:Easter" : "easter(0)",
194
+ # "day:Christmas": "christmas(-249)"
195
+ # }]
196
+ # }
197
+ end
198
+
199
+ open('http://hosi.org/tp/2014-04-20.ttl') do |ttl| # redirected from http://hosi.org to http://hosi.org:3000
200
+ puts ttl.read
201
+ # @prefix Week: <http://hosi.org/When/Coordinates/Common::Week::> .
202
+ # @prefix day: <http://hosi.org/When/CalendarNote/Christian/Notes::day::> .
203
+ # @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
204
+ # @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
205
+ # @prefix ts: <http://hosi.org/ts#> .
206
+ # @prefix xsd: <http://www.w3.org/2001/XMLSchema> .
207
+ #
208
+ # <http://hosi.org/tp/2014-04> rdfs:member <http://hosi.org/tp/2014-04-20> .
209
+ #
210
+ # <http://hosi.org/tp/2014-04-20> a <http://hosi.org/ts/When/TM/CalDate>;
211
+ # day:Christmas "christmas(-249)";
212
+ # day:Easter "easter(0)";
213
+ # day:Week Week:Sunday;
214
+ # ts:coordinate "20";
215
+ # ts:frame <http://hosi.org/When/CalendarTypes/Gregorian>;
216
+ # ts:sdn 2456768 .
217
+ end
218
+
219
+ open('http://hosi.org/When/TM/OrdinalReferenceSystem/GeologicalAge.ttl') do |ttl| # redirected from http://hosi.org to http://hosi.org:3000
220
+ puts ttl.read
221
+ # @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
222
+ # @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
223
+ # @prefix ts: <http://hosi.org/ts#> .
224
+ # @prefix xsd: <http://www.w3.org/2001/XMLSchema> .
225
+ #
226
+ # <http://hosi.org/When/TM/OrdinalReferenceSystem/GeologicalAge> a <http://hosi.org/ts/When/TM/OrdinalReferenceSystem>;
227
+ # rdfs:member <http://hosi.org/When/TM/OrdinalReferenceSystem/GeologicalAge::冥王代>,
228
+ # <http://hosi.org/When/TM/OrdinalReferenceSystem/GeologicalAge::始生代>,
229
+ # <http://hosi.org/When/TM/OrdinalReferenceSystem/GeologicalAge::原生代>,
230
+ # <http://hosi.org/When/TM/OrdinalReferenceSystem/GeologicalAge::顕生代> .
231
+ #
232
+ # <http://hosi.org/When/TM/OrdinalReferenceSystem/GeologicalAge::冥王代> a <http://hosi.org/ts/When/TM/OrdinalEra>;
233
+ # ts:begin "-4600000000";
234
+ # ts:end "-4000000000";
235
+ # ts:label <http://hosi.org/When/TM/OrdinalReferenceSystem/GeologicalAge::冥王代::冥王代> .
236
+ #
237
+ # <http://hosi.org/When/TM/OrdinalReferenceSystem/GeologicalAge::原生代> a <http://hosi.org/ts/When/TM/OrdinalEra>;
238
+ # ts:begin "-2500000000";
239
+ # ts:end "-542000000";
240
+ # ts:label <http://hosi.org/When/TM/OrdinalReferenceSystem/GeologicalAge::原生代::原生代>;
241
+ # rdfs:member <http://hosi.org/When/TM/OrdinalReferenceSystem/GeologicalAge::原生代::前期>,
242
+ # <http://hosi.org/When/TM/OrdinalReferenceSystem/GeologicalAge::原生代::中期>,
243
+ # <http://hosi.org/When/TM/OrdinalReferenceSystem/GeologicalAge::原生代::後期> .
244
+ # <..snip..>
245
+ end
246
+
247
+ #
248
+ # SPARQL endpoint ------------------------------
249
+ # https://rubygems.org/gems/sparql is required for this section's operations.
250
+ # Please install sparql before operation.
251
+
252
+ require 'sparql'
253
+ PREFIXES = When::Parts::Resource.namespace_prefixes(
254
+ '_co:Common', '_co:Common?V=0618', '_m:Calendar', '_m:Japanese', '_n:Japanese/Notes')
255
+
256
+ client = SPARQL::Client.new("http://hosi.org/japan/sparql")
257
+
258
+ client.query(PREFIXES.keys.map {|key|
259
+ "PREFIX #{key}: <#{PREFIXES[key].last}> "}.join("\n") +
260
+ %(
261
+ SELECT DISTINCT ?s
262
+ WHERE {
263
+ ?s ts:coordinate "10" .
264
+ ?s DayNote:廿四節気 SolarTerm:清明 .
265
+ ?s DayNote:干支 Stem-Branch:壬戌 .
266
+ }
267
+ )).each do |solution|
268
+ p solution[:s].to_s #=>
269
+ #=> "http://hosi.org/tp/0689-03-10%5E%5EJapanese"
270
+ #=> "http://hosi.org/tp/1490-03-10%5E%5EJapanese"
271
+ end
272
+
273
+ #
274
+ # TZInfo ---------------------------------------
275
+ # https://rubygems.org/gems/tzinfo is required for this section's operations.
276
+ # Please install tzinfo before operation.
277
+
278
+ gregorian_date = When.tm_pos(2014, 8, 1, 9, 0, 0, :tz=>'Asia/Tokyo')
279
+ p gregorian_date #=> 2014-08-01T09:00:00+09:00
280
+ p gregorian_date.location.iri #=> "http://hosi.org/When/Coordinates/Spatial?long=139.4441E&lat=35.3916N&label=Asia/Tokyo"
281
+ p gregorian_date.sunrise.floor(When::MINUTE) #=> 2014-08-01T04:48+09:00
282
+ p gregorian_date.sunset.floor(When::MINUTE) #=> 2014-08-01T18:45+09:00
283
+
284
+ jst = When.tm_pos(1997, 4, 6, 15, 30, 00, :tz=>'Asia/Tokyo')
285
+ p jst #=> 1997-04-06T15:30:00+09:00
286
+ est = When.Clock('America/New_York') ^ jst
287
+ p est #=> 1997-04-06T01:30:00-05:00
288
+ jst = When.tm_pos(1997, 4, 6, 16, 30, 00, :tz=>'Asia/Tokyo')
289
+ p jst #=> 1997-04-06T16:30:00+09:00
290
+ edt = When.Clock('America/New_York') ^ jst
291
+ p edt #=> 1997-04-06T03:30:00-04:00
292
+
293
+ p When.when?('TZID=America/New_York:1997-10-26T01:30') #=> 1997-10-26T01:30-04:00
294
+ p When.when?('TZID=America/New_York:1997-10-26T01=30') #=> 1997-10-26T01:30-05:00, '=' indicates "leap hour"
295
+ p When.when?('TZID=America/New_York:1997-10-26T02:30') #=> 1997-10-26T02:30-05:00
296
+ p When.when?('TZID=America/New_York:1997-10-26T03:30') #=> 1997-10-26T03:30-05:00
297
+
298
+ # Google Calendar ------------------------------
299
+ # https://github.com/suchowan/gcalapi is required for this section's operations.
300
+ # Please install gcalapi before operation.
301
+ # Please replace xxxxxxxx and ******** to valid id/password pair and access Google Calendar.
302
+
303
+ service = GoogleCalendar::Service.new('xxxxxxxx@gmail.com', '********')
304
+ feed = "http://www.google.com/calendar/feeds/%s__%s%%40holiday.calendar.google.com/public/full" %
305
+ ['japanese', 'ja']
306
+ gcal = GoogleCalendar::Calendar::new(service, feed)
307
+ gcal.enum_for({'start-min'=>'2014-01-01', 'start-max'=>'2015-01-01',
308
+ 'orderby'=>'starttime', 'sortorder'=>'a'
309
+ }).each do |range|
310
+ puts '%s - %s' % [range, range.events[0].summary] #=>
311
+ # 2014-01-01T00:00:00.00+09:00...2014-01-02T00:00:00.00+09:00 - 元日
312
+ # 2014-01-02T00:00:00.00+09:00...2014-01-03T00:00:00.00+09:00 - 銀行休業日
313
+ # 2014-01-03T00:00:00.00+09:00...2014-01-04T00:00:00.00+09:00 - 銀行休業日
314
+ # 2014-01-13T00:00:00.00+09:00...2014-01-14T00:00:00.00+09:00 - 成人の日
315
+ # 2014-02-11T00:00:00.00+09:00...2014-02-12T00:00:00.00+09:00 - 建国記念の日
316
+ # 2014-03-21T00:00:00.00+09:00...2014-03-22T00:00:00.00+09:00 - 春分の日
317
+ # 2014-04-29T00:00:00.00+09:00...2014-04-30T00:00:00.00+09:00 - 昭和の日
318
+ # 2014-05-03T00:00:00.00+09:00...2014-05-04T00:00:00.00+09:00 - 憲法記念日
319
+ # 2014-05-04T00:00:00.00+09:00...2014-05-05T00:00:00.00+09:00 - みどりの日
320
+ # 2014-05-05T00:00:00.00+09:00...2014-05-06T00:00:00.00+09:00 - こどもの日
321
+ # 2014-05-06T00:00:00.00+09:00...2014-05-07T00:00:00.00+09:00 - みどりの日 振替休日
322
+ # 2014-07-21T00:00:00.00+09:00...2014-07-22T00:00:00.00+09:00 - 海の日
323
+ # 2014-09-15T00:00:00.00+09:00...2014-09-16T00:00:00.00+09:00 - 敬老の日
324
+ # 2014-09-23T00:00:00.00+09:00...2014-09-24T00:00:00.00+09:00 - 秋分の日
325
+ # 2014-10-13T00:00:00.00+09:00...2014-10-14T00:00:00.00+09:00 - 体育の日
326
+ # 2014-11-03T00:00:00.00+09:00...2014-11-04T00:00:00.00+09:00 - 文化の日
327
+ # 2014-11-23T00:00:00.00+09:00...2014-11-24T00:00:00.00+09:00 - 勤労感謝の日
328
+ # 2014-11-24T00:00:00.00+09:00...2014-11-25T00:00:00.00+09:00 - 勤労感謝の日 振替休日
329
+ # 2014-12-23T00:00:00.00+09:00...2014-12-24T00:00:00.00+09:00 - 天皇誕生日
330
+ # 2014-12-25T00:00:00.00+09:00...2014-12-26T00:00:00.00+09:00 - クリスマス
331
+ # 2014-12-31T00:00:00.00+09:00...2015-01-01T00:00:00.00+09:00 - 大晦日
332
+ end
333
+