tzrules.n3
7.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
@prefix dc: <http://purl.org/dc/elements/1.1/>.
<> dc:description """
some timezone and recurrence rules:
* figure Z-time of Vevents from local time and timezone info, in
* limited cases.
* relate URIs such as
http://www.w3.org/2002/12/cal/tzd/America/Chicago#tz
to geographical regions Chicago and America
* find out if dateTimes intersect weekly recurring events
(the business hours case)
* compute the month and day of easter in any given year
""",
"$Id: tzrules.n3,v 1.4 2003/03/14 16:39:50 connolly Exp $".
@prefix : <tzrules#>.
@prefix tzr: <tzrules#>.
@prefix k: <http://opencyc.sourceforge.net/daml/cyc.daml#>.
@prefix ical: <http://www.w3.org/2002/12/cal/ical#>.
#http://www.w3.org/TR/xmlschema-2/
@prefix dt: <http://www.w3.org/2001/XMLSchema#> .
<> dc:source <http://www.ludd.luth.se/~ams/djgpp/cvs/djgpp/zoneinfo/src/theory>.
<http://www.ludd.luth.se/~ams/djgpp/cvs/djgpp/zoneinfo/src/theory>
dc:description # excerpt, actually...
"""
Names normally have the form AREA/LOCATION, where AREA is the name
of a continent or ocean, and LOCATION is the name of a specific
location within that region. North and South America share the same
area, `America'. Typical names are `Africa/Cairo', `America/New_York',
and `Pacific/Honolulu'.
""".
[ k:nameString "America";
k:geographicalSubRegions [ k:nameString "Chicago" ] ].
@prefix log: <http://www.w3.org/2000/10/swap/log#> .
@prefix str: <http://www.w3.org/2000/10/swap/string#> .
@prefix time: <http://www.w3.org/2000/10/swap/time#>.
@prefix math: <http://www.w3.org/2000/10/swap/math#>.
this log:forAll :TZ.
{
?LOCATION k:nameString ?LOCATION_N;
is k:geographicalSubRegions of [ k:nameString ?AREA_N].
?TZN is str:concatenation of (
"http://www.w3.org/2002/12/cal/tzd/" ?AREA_N "/" ?LOCATION_N "#tz" ).
:TZ log:uri ?TZN.
[ is log:racine of :TZ ] log:semantics [ log:includes {
:TZ a ical:Vtimezone } ].
}
log:implies {
:TZ a ical:Vtimezone.
?LOCATION :timeZone :TZ.
}.
# convert ical dateTime/tzid to Z-time, in limited cases:
# RRULE has freq YEARLY
# DST
# month not on boundary
# first, find offset for a whole month...
{
?TZ ical:tzid ?TZID;
ical:standard [
ical:rrule [ ical:freq "YEARLY"; ical:bymonth ?SMO ];
ical:tzoffsetto ?STZTO
];
ical:daylight [
ical:rrule [ ical:freq "YEARLY"; ical:bymonth ?DMO ];
ical:tzoffsetto ?DTZTO
].
# month of ?DT within daylight time?
#only works if ?SMO > ?DMO
#We leave the edge-month cases alone for now...
[ ical:dateTime [ time:month ?M ] ]. #@@hmm...
?M
math:greaterThan ?DMO;
math:lessThan ?SMO.
?DOFFSECS is math:product of ( ?DTZTO "0.01" "3600" ). # only works for whole hours
} =>
{ ?TZ :offsetDuring [ :monthNum ?M; :offset ?DOFFSECS ] }.
{
?TZ ical:tzid ?TZID;
:offsetDuring [ :monthNum ?M; :offset ?DOFFSECS ].
?WHEN ical:dateTime ?DT; ical:tzid ?TZID.
?DT time:month ?M.
[ is str:concatenation of (?DT "Z")] time:inSeconds ?DTSECS.
?UT time:inSeconds [ is math:sum of ( ?DTSECS ?DOFFSECS ) ].
} => { ?WHEN dt:dateTime ?UT }.
#######
#
# business hours usecase...
#
# is the business open at time ?WHEN ?
#
:exampleTime1 dt:dateTime "2003-06-13T22:00:00Z".
:exampleTime2 ical:dateTime "2003-05-13T22:00:00";
ical:tzid "/softwarestudio.org/Olson_20011030_5/America/New_York".
:exampleTime3 ical:dateTime "2003-06-13T22:00:00";
ical:tzid "/softwarestudio.org/Olson_20011030_5/America/Chicago".
# relate cyc's day of week types to
# time:dayOfWeek indexes and to
# ical abbreviations
# hmm... move this to a week.rdf KB?
k:Sunday :index "0"; :dayAbbr "SU".
k:Monday :index "1"; :dayAbbr "MO".
k:Tuesday :index "2"; :dayAbbr "TU".
k:Wednesday :index "3"; :dayAbbr "WE".
k:Thursday :index "4"; :dayAbbr "TH".
k:Friday :index "5"; :dayAbbr "FR".
k:Saturday :index "6"; :dayAbbr "SA".
# Turn Z time into, say, Monday 10:35 Chicago time
# based the fact that Chicago is -0600 during June.
{
?WHEN dt:dateTime ?UT.
?UT time:month ?M.
?TZ :offsetDuring [ :monthNum ?M; :offset ?DOFFSECS ].
(?DOFFSECS [ is time:inSeconds of ?UT ]) math:sum ?LTSECS.
?LT time:inSeconds ?LTSECS.
?LT time:dayOfWeek [ is :index of ?DOW ];
time:hour ?HH; time:minute ?MM.
} => { ?WHEN :localTime [ :tz ?TZ; :dow ?DOW; :hh ?HH; :mm ?MM ] }.
# Now compare Monday 10:35 Chicago time
# with the shop hours for Monday...
{
?WHEN :localTime [ :tz ?TZ; :dow ?DOW; :hh ?HH; :mm ?MM ].
?TZ ical:tzid ?TZID.
?E
ical:dtstart [
ical:tzid ?TZID;
ical:dateTime [
time:hour ?START_HH;
time:minute ?START_MM;
];
];
ical:dtend [
ical:tzid ?TZID;
ical:dateTime [
time:hour ?END_HH;
time:minute ?END_MM;
];
];
ical:rrule [ ical:freq "WEEKLY"; ical:interval "1";
ical:byday [ str:contains [ is :dayAbbr of ?DOW ] ] ].
[ is str:concatenation of (?HH ?MM) ]
str:notLessThan [ is str:concatenation of (?START_HH ?START_MM) ];
str:notGreaterThan [ is str:concatenation of (?END_HH ?END_MM) ];
}
=> { ?WHEN k:temporallyIntersects ?E }.
####
#
# when is easter this year?
#
<> dc:source
<http://lists.w3.org/Archives/Public/www-rdf-calendar/2003Mar/0022.html>,
<http://www.w3.org/mid/BKELLDAGKABIOCHDFDBPIEJCCDAA.danny666@virgilio.it>,
<http://www.codeproject.com/datetime/easter.asp>,
<http://www.codeproject.com/datetime/easter.asp>,
<http://www.hourworld.com/easter.htm>.
[ :startYear "0"; :endYear "1700"; :easterCorrection "4"].
[ :startYear "1700"; :endYear "1800"; :easterCorrection "5"].
[ :startYear "1800"; :endYear "1900"; :easterCorrection "6"].
[ :startYear "1900"; :endYear "2100"; :easterCorrection "0"].
[ :startYear "2100"; :endYear "2200"; :easterCorrection "1"].
[ :startYear "2200"; :endYear "2300"; :easterCorrection "2"].
[ :startYear "2300"; :endYear "2500"; :easterCorrection "3"].
# some test data...
:DansBirthDay dt:date "1967-12-09".
:USIndependenceDay dt:date "1776-07-04".
# discover that various years exist...
# called k:TheYearNNNN
{ [ dt:date [ time:year ?YYYY ]].
?I is str:concatenation of (
"http://opencyc.sourceforge.net/daml/cyc.daml#TheYear"
?YYYY
).
?YEAR log:uri ?I.
}
=>
{
?YEAR a k:CalendarYear;
dt:gYear ?YYYY;
is k:YearFn of [ dt:integer ?YYYY ]
}.
# relate them to dates
{ ?WHEN dt:date [ time:year ?YYYY ].
?YEAR dt:gYear ?YYYY.
} => { ?YEAR k:temporallySubsumes ?WHEN }.
# now find easter on each such year...
{
?WHEN dt:gYear ?YYYY.
[ :startYear [ str:notGreaterThan ?YYYY ];
:endYear [ str:greaterThan ?YYYY ];
:easterCorrection ?C ].
?wDay is math:remainder of (
[ is math:sum of (
[ is math:product of (
"19"
[ is math:remainder of (?YYYY "19")]
)]
"24"
)]
"30").
?wDay2 is math:sum of (
"22"
?wDay
[ is math:remainder of (
[ is math:sum of (
[ is math:product of (
"2"
[is math:remainder of (?YYYY "4")]
)]
[ is math:product of ("4" [is math:remainder of (?YYYY "7")])]
[ is math:product of ("6" ?wDay)]
"5"
?C
)]
"7"
)]
).
} => { ?WHEN :easterStep1 ?wDay2 }.
{
?WHEN :easterStep1 ?wDay.
?wDay math:greaterThan "31".
?wDay2 is math:difference of ( ?wDay "31").
}
=> { ?WHEN :easterDay ?wDay2; :easterMonth "04" }.
{
?WHEN :easterStep1 ?wDay.
?wDay math:notGreaterThan "31".
}
=> { ?WHEN :easterDay ?wDay; :easterMonth "03" }.
# now put it all together...
{
?WHEN dt:gYear ?YYYY; :easterDay ?D; :easterMonth ?MM.
# prepend "0" then take last 2 chars
?DD is str:scrape of ([ is str:concatenation of ("0" ?D) ] "(..)$").
?YMD is str:concatenation of (?YYYY "-" ?MM "-" ?DD ).
}
=> { ?WHEN k:temporallySubsumes [ a :EasterHoliday; dt:date ?YMD ] }.