]> gitweb.factorcode.org Git - factor.git/blob - basis/calendar/calendar.factor
cee2358f67f161028b519f29502c1977dd64b0bf
[factor.git] / basis / calendar / calendar.factor
1 ! Copyright (C) 2007 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays classes.tuple combinators
4 combinators.short-circuit kernel locals math math.functions
5 math.order sequences summary system vocabs vocabs.loader
6 assocs ;
7 IN: calendar
8
9 HOOK: gmt-offset os ( -- hours minutes seconds )
10
11 HOOK: gmt os ( -- timestamp )
12
13 TUPLE: duration
14     { year real }
15     { month real }
16     { day real }
17     { hour real }
18     { minute real }
19     { second real } ;
20
21 C: <duration> duration
22
23 : instant ( -- duration ) 0 0 0 0 0 0 <duration> ;
24
25 TUPLE: timestamp
26     { year integer }
27     { month integer }
28     { day integer }
29     { hour integer }
30     { minute integer }
31     { second real }
32     { gmt-offset duration } ;
33
34 C: <timestamp> timestamp
35
36 M: timestamp clone (clone) [ clone ] change-gmt-offset ;
37
38 : gmt-offset-duration ( -- duration )
39     0 0 0 gmt-offset <duration> ; inline
40
41 : <date> ( year month day -- timestamp )
42     0 0 0 gmt-offset-duration <timestamp> ; inline
43
44 : <date-gmt> ( year month day -- timestamp )
45     0 0 0 instant <timestamp> ; inline
46
47 : <year> ( year -- timestamp )
48     1 1 <date> ; inline
49
50 : <year-gmt> ( year -- timestamp )
51     1 1 <date-gmt> ; inline
52
53 ERROR: not-a-month ;
54 M: not-a-month summary
55     drop "Months are indexed starting at 1" ;
56
57 <PRIVATE
58
59 : check-month ( n -- n )
60     [ not-a-month ] when-zero ;
61
62 PRIVATE>
63
64 CONSTANT: month-names
65     {
66         "January" "February" "March" "April" "May" "June"
67         "July" "August" "September" "October" "November" "December"
68     }
69
70 GENERIC: month-name ( obj -- string )
71
72 M: integer month-name check-month 1 - month-names nth ;
73 M: timestamp month-name month>> 1 - month-names nth ;
74
75 ERROR: not-a-month-abbreviation string ;
76
77 CONSTANT: month-abbreviations
78     {
79         "Jan" "Feb" "Mar" "Apr" "May" "Jun"
80         "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"
81     }
82
83 CONSTANT: month-abbreviations-hash
84     H{
85         { "Jan" 1 } { "Feb" 2 } { "Mar" 3 }
86         { "Apr" 4 } { "May" 5 } { "Jun" 6 }
87         { "Jul" 7 } { "Aug" 8 } { "Sep" 9 }
88         { "Oct" 10 } { "Nov" 11 } { "Dec" 12 }
89     }
90
91 : month-abbreviation ( n -- string )
92     check-month 1 - month-abbreviations nth ;
93
94 : month-abbreviation-index ( string -- n )
95     month-abbreviations-hash ?at
96     [ not-a-month-abbreviation ] unless ;
97
98 CONSTANT: day-counts { 0 31 28 31 30 31 30 31 31 30 31 30 31 }
99
100 CONSTANT: day-names
101     { "Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" }
102
103 CONSTANT: day-abbreviations2
104     { "Su" "Mo" "Tu" "We" "Th" "Fr" "Sa" }
105
106 : day-abbreviation2 ( n -- string )
107     day-abbreviations2 nth ; inline
108
109 CONSTANT: day-abbreviations3
110     { "Sun" "Mon" "Tue" "Wed" "Thu" "Fri" "Sat" }
111
112 CONSTANT: day-abbreviations3-hash
113     H{
114         { "Sun" 0 } { "Mon" 1 } { "Tue" 2 } { "Wed" 3 }
115         { "Thu" 4 } { "Fri" 5 } { "Sat" 6 }
116     }
117
118 CONSTANT: average-month 30+5/12
119 CONSTANT: months-per-year 12
120 CONSTANT: days-per-year 3652425/10000
121 CONSTANT: hours-per-year 876582/100
122 CONSTANT: minutes-per-year 5259492/10
123 CONSTANT: seconds-per-year 31556952
124
125 :: julian-day-number ( year month day -- n )
126     #! Returns a composite date number
127     #! Not valid before year -4800
128     14 month - 12 /i :> a
129     year 4800 + a - :> y
130     month 12 a * + 3 - :> m
131
132     day 153 m * 2 + 5 /i + 365 y * +
133     y 4 /i + y 100 /i - y 400 /i + 32045 - ;
134
135 :: julian-day-number>date ( n -- year month day )
136     #! Inverse of julian-day-number
137     n 32044 + :> a
138     4 a * 3 + 146097 /i :> b
139     a 146097 b * 4 /i - :> c
140     4 c * 3 + 1461 /i :> d
141     c 1461 d * 4 /i - :> e
142     5 e * 2 + 153 /i :> m
143
144     100 b * d + 4800 -
145     m 10 /i + m 3 +
146     12 m 10 /i * -
147     e 153 m * 2 + 5 /i - 1 + ;
148
149 GENERIC: easter ( obj -- obj' )
150
151 :: easter-month-day ( year -- month day )
152     year 19 mod :> a
153     year 100 /mod :> ( b c )
154     b 4 /mod :> ( d e )
155     b 8 + 25 /i :> f
156     b f - 1 + 3 /i :> g
157     19 a * b + d - g - 15 + 30 mod :> h
158     c 4 /mod :> ( i k )
159     32 2 e * + 2 i * + h - k - 7 mod :> l
160     a 11 h * + 22 l * + 451 /i :> m
161
162     h l + 7 m * - 114 + 31 /mod 1 + ;
163
164 M: integer easter ( year -- timestamp )
165     dup easter-month-day <date> ;
166
167 M: timestamp easter ( timestamp -- timestamp )
168     clone
169     dup year>> easter-month-day
170     swapd >>day swap >>month ;
171
172 : >date< ( timestamp -- year month day )
173     [ year>> ] [ month>> ] [ day>> ] tri ;
174
175 : >time< ( timestamp -- hour minute second )
176     [ hour>> ] [ minute>> ] [ second>> ] tri ;
177
178 : years ( x -- duration ) instant swap >>year ;
179 : months ( x -- duration ) instant swap >>month ;
180 : days ( x -- duration ) instant swap >>day ;
181 : weeks ( x -- duration ) 7 * days ;
182 : hours ( x -- duration ) instant swap >>hour ;
183 : minutes ( x -- duration ) instant swap >>minute ;
184 : seconds ( x -- duration ) instant swap >>second ;
185 : milliseconds ( x -- duration ) 1000 / seconds ;
186 : microseconds ( x -- duration ) 1000000 / seconds ;
187 : nanoseconds ( x -- duration ) 1000000000 / seconds ;
188
189 GENERIC: leap-year? ( obj -- ? )
190
191 M: integer leap-year? ( year -- ? )
192     dup 100 divisor? 400 4 ? divisor? ;
193
194 M: timestamp leap-year? ( timestamp -- ? )
195     year>> leap-year? ;
196
197 <PRIVATE
198
199 GENERIC: +year ( timestamp x -- timestamp )
200 GENERIC: +month ( timestamp x -- timestamp )
201 GENERIC: +day ( timestamp x -- timestamp )
202 GENERIC: +hour ( timestamp x -- timestamp )
203 GENERIC: +minute ( timestamp x -- timestamp )
204 GENERIC: +second ( timestamp x -- timestamp )
205
206 : /rem ( f n -- q r )
207     #! q is positive or negative, r is positive from 0 <= r < n
208     [ / floor >integer ] 2keep rem ;
209
210 : float>whole-part ( float -- int float )
211     [ floor >integer ] keep over - ;
212
213 : adjust-leap-year ( timestamp -- timestamp )
214     dup
215     { [ day>> 29 = ] [ month>> 2 = ] [ leap-year? not ] } 1&&
216     [ 3 >>month 1 >>day ] when ;
217
218 M: integer +year ( timestamp n -- timestamp )
219     [ + ] curry change-year adjust-leap-year ;
220
221 M: real +year ( timestamp n -- timestamp )
222     [ float>whole-part swapd days-per-year * +day swap +year ] unless-zero ;
223
224 : months/years ( n -- months years )
225     12 /rem [ 1 - 12 ] when-zero swap ; inline
226
227 M: integer +month ( timestamp n -- timestamp )
228     [ over month>> + months/years [ >>month ] dip +year ] unless-zero ;
229
230 M: real +month ( timestamp n -- timestamp )
231     [ float>whole-part swapd average-month * +day swap +month ] unless-zero ;
232
233 M: integer +day ( timestamp n -- timestamp )
234     [
235         over >date< julian-day-number + julian-day-number>date
236         [ >>year ] [ >>month ] [ >>day ] tri*
237     ] unless-zero ;
238
239 M: real +day ( timestamp n -- timestamp )
240     [ float>whole-part swapd 24 * +hour swap +day ] unless-zero ;
241
242 : hours/days ( n -- hours days )
243     24 /rem swap ;
244
245 M: integer +hour ( timestamp n -- timestamp )
246     [ over hour>> + hours/days [ >>hour ] dip +day ] unless-zero ;
247
248 M: real +hour ( timestamp n -- timestamp )
249     float>whole-part swapd 60 * +minute swap +hour ;
250
251 : minutes/hours ( n -- minutes hours )
252     60 /rem swap ;
253
254 M: integer +minute ( timestamp n -- timestamp )
255     [ over minute>> + minutes/hours [ >>minute ] dip +hour ] unless-zero ;
256
257 M: real +minute ( timestamp n -- timestamp )
258     [ float>whole-part swapd 60 * +second swap +minute ] unless-zero ;
259
260 : seconds/minutes ( n -- seconds minutes )
261     60 /rem swap >integer ;
262
263 M: number +second ( timestamp n -- timestamp )
264     [ over second>> + seconds/minutes [ >>second ] dip +minute ] unless-zero ;
265
266 : (time+) ( timestamp duration -- timestamp' duration )
267     [ second>> +second ] keep
268     [ minute>> +minute ] keep
269     [ hour>>   +hour   ] keep
270     [ day>>    +day    ] keep
271     [ month>>  +month  ] keep
272     [ year>>   +year   ] keep ; inline
273
274 : +slots ( obj1 obj2 quot -- n obj1 obj2 )
275     [ bi@ + ] curry 2keep ; inline
276
277 PRIVATE>
278
279 GENERIC# time+ 1 ( time1 time2 -- time3 )
280
281 M: timestamp time+
282     [ clone ] dip (time+) drop ;
283
284 M: duration time+
285     dup timestamp? [
286         swap time+
287     ] [
288         [ year>> ] +slots
289         [ month>> ] +slots
290         [ day>> ] +slots
291         [ hour>> ] +slots
292         [ minute>> ] +slots
293         [ second>> ] +slots
294         2drop <duration>
295     ] if ;
296
297 : duration>years ( duration -- x )
298     #! Uses average month/year length since duration loses calendar
299     #! data
300     0 swap
301     {
302         [ year>> + ]
303         [ month>> months-per-year / + ]
304         [ day>> days-per-year / + ]
305         [ hour>> hours-per-year / + ]
306         [ minute>> minutes-per-year / + ]
307         [ second>> seconds-per-year / + ]
308     } cleave ;
309
310 M: duration <=> [ duration>years ] compare ;
311
312 : duration>months ( duration -- x ) duration>years months-per-year * ;
313 : duration>days ( duration -- x ) duration>years days-per-year * ;
314 : duration>hours ( duration -- x ) duration>years hours-per-year * ;
315 : duration>minutes ( duration -- x ) duration>years minutes-per-year * ;
316 : duration>seconds ( duration -- x ) duration>years seconds-per-year * ;
317 : duration>milliseconds ( duration -- x ) duration>seconds 1000 * ;
318 : duration>microseconds ( duration -- x ) duration>seconds 1000000 * ;
319 : duration>nanoseconds ( duration -- x ) duration>seconds 1000000000 * ;
320
321 GENERIC: time- ( time1 time2 -- time3 )
322
323 : convert-timezone ( timestamp duration -- timestamp' )
324     over gmt-offset>> over = [ drop ] [
325         [ over gmt-offset>> time- time+ ] keep >>gmt-offset
326     ] if ;
327
328 : >local-time ( timestamp -- timestamp' )
329     clone gmt-offset-duration convert-timezone ;
330
331 : >gmt ( timestamp -- timestamp' )
332     clone dup gmt-offset>> dup instant =
333     [ drop ] [
334         [ neg +second 0 ] change-second
335         [ neg +minute 0 ] change-minute
336         [ neg +hour   0 ] change-hour
337         [ neg +day    0 ] change-day
338         [ neg +month  0 ] change-month
339         [ neg +year   0 ] change-year drop
340     ] if ;
341
342 M: timestamp <=> ( ts1 ts2 -- n )
343     [ >gmt tuple-slots ] compare ;
344
345 : same-day? ( ts1 ts2 -- ? )
346     [ >gmt >date< <date> ] same? ;
347
348 : (time-) ( timestamp timestamp -- n )
349     [ >gmt ] bi@
350     [ [ >date< julian-day-number ] bi@ - 86400 * ] 2keep
351     [ >time< [ [ 3600 * ] [ 60 * ] bi* ] dip + + ] bi@ - + ;
352
353 M: timestamp time-
354     #! Exact calendar-time difference
355     (time-) seconds ;
356
357 : time* ( obj1 obj2 -- obj3 )
358     dup real? [ swap ] when
359     dup real? [ * ] [
360         {
361             [   year>> * ]
362             [  month>> * ]
363             [    day>> * ]
364             [   hour>> * ]
365             [ minute>> * ]
366             [ second>> * ]
367         } 2cleave <duration>
368     ] if ;
369
370 : before ( duration -- -duration )
371     -1 time* ;
372
373 <PRIVATE
374
375 : -slots ( obj1 obj2 quot -- n obj1 obj2 )
376     [ bi@ - ] curry 2keep ; inline
377
378 PRIVATE>
379
380 M: duration time-
381     over timestamp? [
382         before time+
383     ] [
384         [ year>> ] -slots
385         [ month>> ] -slots
386         [ day>> ] -slots
387         [ hour>> ] -slots
388         [ minute>> ] -slots
389         [ second>> ] -slots
390         2drop <duration>
391     ] if ;
392
393 : <zero> ( -- timestamp )
394     0 0 0 <date-gmt> ; inline
395
396 : valid-timestamp? ( timestamp -- ? )
397     clone instant >>gmt-offset
398     dup <zero> time- <zero> time+ = ;
399
400 : unix-1970 ( -- timestamp )
401     1970 <year-gmt> ; inline
402
403 : millis>timestamp ( x -- timestamp )
404     [ unix-1970 ] dip 1000 / +second ;
405
406 : timestamp>millis ( timestamp -- n )
407     unix-1970 (time-) 1000 * >integer ;
408
409 : micros>timestamp ( x -- timestamp )
410     [ unix-1970 ] dip 1000000 / +second ;
411
412 : timestamp>micros ( timestamp -- n )
413     unix-1970 (time-) 1000000 * >integer ;
414
415 : now ( -- timestamp )
416     gmt gmt-offset-duration (time+) >>gmt-offset ;
417
418 : hence ( duration -- timestamp ) now swap time+ ;
419
420 : ago ( duration -- timestamp ) now swap time- ;
421
422 : zeller-congruence ( year month day -- n )
423     #! Zeller Congruence
424     #! http://web.textfiles.com/computers/formulas.txt
425     #! good for any date since October 15, 1582
426     [
427         dup 2 <= [ [ 1 - ] [ 12 + ] bi* ] when
428         [ dup [ 4 /i + ] [ 100 /i - ] [ 400 /i + ] tri ] dip
429         [ 1 + 3 * 5 /i + ] keep 2 * +
430     ] dip 1 + + 7 mod ;
431
432 GENERIC: days-in-year ( obj -- n )
433
434 M: integer days-in-year ( year -- n ) leap-year? 366 365 ? ;
435 M: timestamp days-in-year ( timestamp -- n ) year>> days-in-year ;
436
437 : (days-in-month) ( year month -- n )
438     dup 2 = [ drop leap-year? 29 28 ? ] [ nip day-counts nth ] if ;
439
440 : days-in-month ( timestamp -- n )
441     >date< drop (days-in-month) ;
442
443 : day-of-week ( timestamp -- n )
444     >date< zeller-congruence ;
445
446 GENERIC: day-name ( obj -- string )
447 M: integer day-name day-names nth ;
448 M: timestamp day-name day-of-week day-names nth ;
449
450 :: (day-of-year) ( year month day -- n )
451     day-counts month head-slice sum day +
452     year leap-year? [
453         year month day <date>
454         year 3 1 <date>
455         after=? [ 1 + ] when
456     ] when ;
457
458 : day-of-year ( timestamp -- n )
459     >date< (day-of-year) ;
460
461 : midnight ( timestamp -- new-timestamp )
462     clone 0 >>hour 0 >>minute 0 >>second ; inline
463
464 : noon ( timestamp -- new-timestamp )
465     midnight 12 >>hour ; inline
466
467 : today ( -- timestamp )
468     now midnight ; inline
469
470 : tomorrow ( -- timestamp )
471     1 days hence midnight ; inline
472
473 : yesterday ( -- timestamp )
474     1 days ago midnight ; inline
475
476 : beginning-of-month ( timestamp -- new-timestamp )
477     midnight 1 >>day ; inline
478
479 : end-of-month ( timestamp -- new-timestamp )
480     [ midnight ] [ days-in-month ] bi >>day ;
481
482 <PRIVATE
483
484 : day-offset ( timestamp m -- new-timestamp n )
485     over day-of-week - ; inline
486
487 : day-this-week ( timestamp n -- new-timestamp )
488     day-offset days time+ ;
489
490 :: nth-day-this-month ( timestamp n day -- new-timestamp )
491     timestamp beginning-of-month day day-this-week
492     dup timestamp [ month>> ] same? [ 1 weeks time+ ] unless
493     n 1 - [ weeks time+ ] unless-zero ;
494
495 : last-day-this-month ( timestamp day -- new-timestamp )
496     [ 1 months time+ 1 ] dip nth-day-this-month 1 weeks time- ;
497
498 PRIVATE>
499
500 GENERIC: january ( obj -- timestamp )
501 GENERIC: february ( obj -- timestamp )
502 GENERIC: march ( obj -- timestamp )
503 GENERIC: april ( obj -- timestamp )
504 GENERIC: may ( obj -- timestamp )
505 GENERIC: june ( obj -- timestamp )
506 GENERIC: july ( obj -- timestamp )
507 GENERIC: august ( obj -- timestamp )
508 GENERIC: september ( obj -- timestamp )
509 GENERIC: october ( obj -- timestamp )
510 GENERIC: november ( obj -- timestamp )
511 GENERIC: december ( obj -- timestamp )
512
513 M: integer january 1 1 <date> ;
514 M: integer february 2 1 <date> ;
515 M: integer march 3 1 <date> ;
516 M: integer april 4 1 <date> ;
517 M: integer may 5 1 <date> ;
518 M: integer june 6 1 <date> ;
519 M: integer july 7 1 <date> ;
520 M: integer august 8 1 <date> ;
521 M: integer september 9 1 <date> ;
522 M: integer october 10 1 <date> ;
523 M: integer november 11 1 <date> ;
524 M: integer december 12 1 <date> ;
525
526 M: timestamp january clone 1 >>month ;
527 M: timestamp february clone 2 >>month ;
528 M: timestamp march clone 3 >>month ;
529 M: timestamp april clone 4 >>month ;
530 M: timestamp may clone 5 >>month ;
531 M: timestamp june clone 6 >>month ;
532 M: timestamp july clone 7 >>month ;
533 M: timestamp august clone 8 >>month ;
534 M: timestamp september clone 9 >>month ;
535 M: timestamp october clone 10 >>month ;
536 M: timestamp november clone 11 >>month ;
537 M: timestamp december clone 12 >>month ;
538
539 : sunday ( timestamp -- new-timestamp ) 0 day-this-week ;
540 : monday ( timestamp -- new-timestamp ) 1 day-this-week ;
541 : tuesday ( timestamp -- new-timestamp ) 2 day-this-week ;
542 : wednesday ( timestamp -- new-timestamp ) 3 day-this-week ;
543 : thursday ( timestamp -- new-timestamp ) 4 day-this-week ;
544 : friday ( timestamp -- new-timestamp ) 5 day-this-week ;
545 : saturday ( timestamp -- new-timestamp ) 6 day-this-week ;
546
547 : sunday? ( timestamp -- ? ) day-of-week 0 = ;
548 : monday? ( timestamp -- ? ) day-of-week 1 = ;
549 : tuesday? ( timestamp -- ? ) day-of-week 2 = ;
550 : wednesday? ( timestamp -- ? ) day-of-week 3 = ;
551 : thursday? ( timestamp -- ? ) day-of-week 4 = ;
552 : friday? ( timestamp -- ? ) day-of-week 5 = ;
553 : saturday? ( timestamp -- ? ) day-of-week 6 = ;
554
555 : sunday-of-month ( timestamp n -- new-timestamp ) 0 nth-day-this-month ;
556 : monday-of-month ( timestamp n -- new-timestamp ) 1 nth-day-this-month ;
557 : tuesday-of-month ( timestamp n -- new-timestamp ) 2 nth-day-this-month ;
558 : wednesday-of-month ( timestamp n -- new-timestamp ) 3 nth-day-this-month ;
559 : thursday-of-month ( timestamp n -- new-timestamp ) 4 nth-day-this-month ;
560 : friday-of-month ( timestamp n -- new-timestamp ) 5 nth-day-this-month ;
561 : saturday-of-month ( timestamp n -- new-timestamp ) 6 nth-day-this-month ;
562
563 : last-sunday-of-month ( timestamp -- new-timestamp ) 0 last-day-this-month ;
564 : last-monday-of-month ( timestamp -- new-timestamp ) 1 last-day-this-month ;
565 : last-tuesday-of-month ( timestamp -- new-timestamp ) 2 last-day-this-month ;
566 : last-wednesday-of-month ( timestamp -- new-timestamp ) 3 last-day-this-month ;
567 : last-thursday-of-month ( timestamp -- new-timestamp ) 4 last-day-this-month ;
568 : last-friday-of-month ( timestamp -- new-timestamp ) 5 last-day-this-month ;
569 : last-saturday-of-month ( timestamp -- new-timestamp ) 6 last-day-this-month ;
570
571 CONSTANT: day-predicates
572     { sunday? monday? tuesday? wednesday? thursday? friday? saturday? }
573
574 : day-predicate ( string -- predicate )
575     day-predicates nth ;
576
577 : day-abbreviation3 ( n -- string )
578     day-abbreviations3 nth ; inline
579
580 ERROR: not-a-day-abbreviation string ;
581
582 : day-abbreviation3-index ( string -- n )
583     day-abbreviations3-hash ?at [ not-a-day-abbreviation ] unless ; inline
584
585 : day-abbreviation3-predicate ( string -- predicate )
586     day-abbreviation3-index day-predicates nth ;
587
588 : beginning-of-week ( timestamp -- new-timestamp )
589     midnight sunday ;
590
591 : o'clock ( timestamp n -- new-timestamp )
592     [ midnight ] dip >>hour ;
593
594 ERROR: twelve-hour-expected n ;
595
596 : check-twelve-hour ( n -- n )
597     dup 0 12 between? [ twelve-hour-expected ] unless ;
598
599 : am ( timestamp n -- new-timestamp )
600     check-twelve-hour o'clock ;
601
602 : pm ( timestamp n -- new-timestamp )
603     check-twelve-hour 12 + o'clock ;
604
605 GENERIC: beginning-of-year ( object -- new-timestamp )
606 M: timestamp beginning-of-year beginning-of-month 1 >>month ;
607 M: integer beginning-of-year <year> ;
608
609 GENERIC: end-of-year ( object -- new-timestamp )
610 M: timestamp end-of-year 12 >>month 31 >>day ;
611 M: integer end-of-year 12 31 <date> ;
612
613 : time-since-midnight ( timestamp -- duration )
614     dup midnight time- ; inline
615
616 : since-1970 ( duration -- timestamp )
617     unix-1970 time+ ; inline
618
619 : timestamp>unix-time ( timestamp -- seconds )
620     unix-1970 (time-) ; inline
621
622 : unix-time>timestamp ( seconds -- timestamp )
623     [ unix-1970 ] dip +second ; inline
624
625 {
626     { [ os unix? ] [ "calendar.unix" ] }
627     { [ os windows? ] [ "calendar.windows" ] }
628 } cond require
629
630 { "threads" "calendar" } "calendar.threads" require-when