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