aboutsummaryrefslogtreecommitdiff
path: root/module/vcomponent/recurrence/display/test.scm
blob: 3502cd5a8b145e3c08cd02177d98bd28aae3e531 (plain)
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
;;; Commentary:
;; This is a pure test file, but it's not placed together with the other
;; tests since it requires a human to read the output.
;;; Code:

(use-modules (vcomponent recurrence display)
             (vcomponent recurrence parse)
             (util))

;; Examples copied from RFC5545

(define (run-test desc sources)
  (format #t "~%> ~a~%" desc)
  (for el in (map (compose format-recurrence-rule
                           parse-recurrence-rule)
                  sources)
       (format #t "=> upprepas ~a.~%" el)))

(define-syntax test
  (syntax-rules (description source)
    [(_ (description desc)
        (source sources ...))
     (run-test desc (list sources ...))]))

(test
 (description "Daily for 10 occurrences")
 (source "FREQ=DAILY;COUNT=10"))
;; => "dagligen, 10 gånger."

(test
 (description "Daily until December 24, 1997")
 (source "FREQ=DAILY;UNTIL=19971224T000000Z"))
;; => "dagligen, till och med den 24 december, 1997 kl.  0:00"


(test
 (description "Every other day - forever")
 (source "FREQ=DAILY;INTERVAL=2"))
;; => "varannan dag"

(test
 (description "Every 10 days, 5 occurrences")
 (source "FREQ=DAILY;INTERVAL=10;COUNT=5"))
;; => "var tionde dag, 5 gånger."

;; TODO sortera ordningen på dagar
(test
 (description "Every day in January, for 3 years")
 (source "FREQ=YEARLY;UNTIL=20000131T140000Z;BYMONTH=1;BYDAY=SU,MO,TU,WE,TH,FR,SA"
         "FREQ=DAILY;UNTIL=20000131T140000Z;BYMONTH=1" ))
;; => "varje lördag, fredag, torsdag, onsdag, tisdag, måndag & söndag januari varje år, till och med den 31 januari, 2000 kl. 14:00"
;; => "dagligen, till och med den 31 januari, 2000 kl. 14:00"

(test
 (description "Weekly for 10 occurrences")
 (source "FREQ=WEEKLY;COUNT=10"))
;; => "varje vecka, 10 gånger."

(test
 (description "Weekly until December 24, 1997")
 (source "FREQ=WEEKLY;UNTIL=19971224T000000Z"))
;; => "varje vecka, till och med den 24 december, 1997 kl.  0:00"

(test
 (description "Every other week - forever")
 (source "FREQ=WEEKLY;INTERVAL=2;WKST=SU"))
;; => "varannan vecka"

(test
 (description "Weekly on Tuesday and Thursday for five weeks")
 (source "FREQ=WEEKLY;UNTIL=19971007T000000Z;WKST=SU;BYDAY=TU,TH"
         "FREQ=WEEKLY;COUNT=10;WKST=SU;BYDAY=TU,TH"))
;; => "varje tisdag & torsdag, till och med den 07 oktober, 1997 kl. 00:00"
;; => "varje tisdag & torsdag, 10 gånger."

(test
 (description "Every other week on Monday, Wednesday, and Friday until December 24, 1997, starting on Monday, September 1, 1997:")
 (source "FREQ=WEEKLY;INTERVAL=2;UNTIL=19971224T000000Z;WKST=SU;BYDAY=MO,WE,FR"))
;; => "varannan måndag, onsdag & fredag, till och med den 24 december, 1997 kl.  0:00"

;; TOOD tittta närmare vad de egentligen vill ha här
(test
 (description "Every other week on Tuesday and Thursday, for 8 occurrences")
 (source "FREQ=WEEKLY;INTERVAL=2;COUNT=8;WKST=SU;BYDAY=TU,TH"))
;; => "varannan tisdag & torsdag, 8 gånger."

(test
 (description "Monthly on the first Friday for 10 occurrences")
 (source "FREQ=MONTHLY;COUNT=10;BYDAY=1FR"))
;; => "första fredagen varje månad, 10 gånger."

(test
 (description "Monthly on the first Friday until December 24, 1997")
 (source "FREQ=MONTHLY;UNTIL=19971224T000000Z;BYDAY=1FR"))
;; => "förste fredagen varje månad, till och med den 24 december, 1997 kl.  0:00"

(test
 (description "Every other month on the first and last Sunday of the month for 10 occurrences")
 (source "FREQ=MONTHLY;INTERVAL=2;COUNT=10;BYDAY=1SU,-1SU"))
;; => "första söndagen samt siste söndagen varannan månad, 10 gånger."

(test
 (description "Monthly on the second-to-last Monday of the month for 6 months")
 (source "FREQ=MONTHLY;COUNT=6;BYDAY=-2MO"))
;; => "näst sista måndagen varje månad, 6 gånger."

(test
 (description "Monthly on the third-to-the-last day of the month, forever")
 (source "FREQ=MONTHLY;BYMONTHDAY=-3"))
;; => "den tredje sista varje månad"

(test
 (description "Monthly on the 2nd and 15th of the month for 10 occurrences")
 (source "FREQ=MONTHLY;COUNT=10;BYMONTHDAY=2,15"))
;; => "den andre & femtonde varje månad, 10 gånger."

(test
 (description "Monthly on the first and last day of the month for 10 occurrences")
 (source "FREQ=MONTHLY;COUNT=10;BYMONTHDAY=1,-1"))
;; => "den förste & sista varje månad, 10 gånger."

(test
 (description "Every 18 months on the 10th thru 15th of the month for 10 occurrences")
 (source "FREQ=MONTHLY;INTERVAL=18;COUNT=10;BYMONTHDAY=10,11,12,13,14,15"))
;; => "den tionde, elfte, tolfte, trettonde, fjortonde & femtonde var artonde månad, 10 gånger."

(test
 (description "Every Tuesday, every other month")
 (source "FREQ=MONTHLY;INTERVAL=2;BYDAY=TU"))
;; => "varje tisdag varannan månad"

(test
 (description "Yearly in June and July for 10 occurrences:
Note: Since none of the BYDAY, BYMONTHDAY, or BYYEARDAY
components are specified, the day is gotten from \"DTSTART\".")
 (source "FREQ=YEARLY;COUNT=10;BYMONTH=6,7"))
;; => "juni & juli årligen, 10 gånger."

(test
 (description "Every other year on January, February, and March for 10 occurrences")
 (source "FREQ=YEARLY;INTERVAL=2;COUNT=10;BYMONTH=1,2,3"))
;; => "januari, februari & mars vartannat år, 10 gånger."

(test
 (description "Every third year on the 1st, 100th, and 200th day for 10 occurrences")
 (source "FREQ=YEARLY;INTERVAL=3;COUNT=10;BYYEARDAY=1,100,200"))
;; => "dag 1, 100 & 200 vart tredje år, 10 gånger."

(test
 (description "Every 20th Monday of the year, forever")
 (source "FREQ=YEARLY;BYDAY=20MO"))
;; => "tjugonde måndagen årligen"

(test
 (description "Monday of week number 20 (where the default start of the week is Monday), forever")
 (source "FREQ=YEARLY;BYWEEKNO=20;BYDAY=MO"))
;; => "varje måndag v.20 årligen"

(test
 (description "Every Thursday in March, forever")
 (source "FREQ=YEARLY;BYMONTH=3;BYDAY=TH"))
;; => "varje torsdag i mars, årligen"

(test
 (description "Every Thursday, but only during June, July, and August, forever")
 (source "FREQ=YEARLY;BYDAY=TH;BYMONTH=6,7,8"))
;; => "varje torsdag i juni, juli & augusti, årligen"

;; NOTE This has some weird grammar in swedish
(test
 (description "Every Friday the 13th, forever")
 (source "FREQ=MONTHLY;BYDAY=FR;BYMONTHDAY=13"))
;; => "varje fredag den trettonde varje månad"

(test
 (description "The first Saturday that follows the first Sunday of the month,forever")
 (source "FREQ=MONTHLY;BYDAY=SA;BYMONTHDAY=7,8,9,10,11,12,13"))
;; => "varje lördag den sjunde, åttonde, nionde, tionde, elfte, tolfte & trettonde varje månad"

;; TODO
(test
 (description
  "Every 4 years, the first Tuesday after a Monday in November,
forever (U.S. Presidential Election day)")
 (source "FREQ=YEARLY;INTERVAL=4;BYMONTH=11;BYDAY=TU;BYMONTHDAY=2,3,4,5,6,7,8"))
;; => "varje tisdag  i novembervart fjärde år"
;; => "varje tisdag den andre, tredje, fjärde, femte, sjätte, sjunde & åttonde i november vart fjärde år"

;; TODO bysetpos

(test
 (description "The third instance into the month of one of Tuesday, Wednesday, or
Thursday, for the next 3 months")
 (source "FREQ=MONTHLY;COUNT=3;BYDAY=TU,WE,TH;BYSETPOS=3"))

(test
 (description "The second-to-last weekday of the month")
 (source "FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-2"))

(test
 (description "Every 3 hours from 9:00 AM to 5:00 PM on a specific day")
 (source "FREQ=HOURLY;INTERVAL=3;UNTIL=19970902T170000Z"))
;; => "var tredje timme, till och med den 02 september, 1997 kl. 17:00"

(test
 (description "Every 15 minutes for 6 occurrences")
 (source "FREQ=MINUTELY;INTERVAL=15;COUNT=6"))
;; => "var femtonde minut, 6 gånger."

(test
 (description "Every hour and a half for 4 occurrences")
 (source "FREQ=MINUTELY;INTERVAL=90;COUNT=4"))
;; => "var nitionde minut, 4 gånger."

(test
 (description "Every 20 minutes from 9:00 AM to 4:40 PM every day")
 (source "FREQ=DAILY;BYHOUR=9,10,11,12,13,14,15,16;BYMINUTE=0,20,40"
         "FREQ=MINUTELY;INTERVAL=20;BYHOUR=9,10,11,12,13,14,15,16"))
;; => "dagligen kl. 09:00, 09:20, 09:40, 10:00, 10:20, 10:40, 11:00, 11:20, 11:40, 12:00, 12:20, 12:40, 13:00, 13:20, 13:40, 14:00, 14:20, 14:40, 15:00, 15:20, 15:40, 16:00, 16:20 & 16:40"
;; or
;; => "var 20e minut kl. 9, 10, 11, 12, 13, 14, 15 & 16"

(test
 (description "An example where the days generated makes a difference because of WKST")
 (source "FREQ=WEEKLY;INTERVAL=2;COUNT=4;BYDAY=TU,SU;WKST=MO"))
;; => "varannan tisdag & söndag, 4 gånger."

(test
 (description "changing only WKST from MO to SU, yields different results...")
 (source "FREQ=WEEKLY;INTERVAL=2;COUNT=4;BYDAY=TU,SU;WKST=SU"))
;; => "varannan tisdag & söndag, 4 gånger."

(test
 (description "An example where an invalid date (i.e., February 30) is ignored.")
 (source "FREQ=MONTHLY;BYMONTHDAY=15,30;COUNT=5"))
;; => "den 15 & 30 varje månad, 5 gånger."