Skip to content

Commit c20e9f3

Browse files
authored
fix test for whole day event cross over dst change (#345)
1 parent 2d16244 commit c20e9f3

File tree

4 files changed

+80
-5
lines changed

4 files changed

+80
-5
lines changed

ical.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -584,11 +584,8 @@ module.exports = {
584584
rule = rule.slice(rule.lastIndexOf('FREQ='));
585585
// If no rule start date
586586
if (rule.includes('DTSTART') === false) {
587-
// Get date/time into a specific format for comapare
588-
let x = moment(curr.start).format('MMMM/Do/YYYY, h:mm:ss a');
589-
// If the local time value is midnight
590587
// This a whole day event
591-
if (x.slice(-11) === '12:00:00 am') {
588+
if (curr.datetype === 'date') {
592589
// Get the timezone offset
593590
// The internal date is stored in UTC format
594591
const offset = curr.start.getTimezoneOffset();
@@ -600,7 +597,7 @@ module.exports = {
600597
curr.start = new Date(curr.start.getTime() + (Math.abs(offset) * 60000));
601598
} else {
602599
// Get rid of any time (shouldn't be any, but be sure)
603-
x = moment(curr.start).format('MMMM/Do/YYYY');
600+
const x = moment(curr.start).format('MMMM/Do/YYYY');
604601
const comps = /^(\d{2})\/(\d{2})\/(\d{4})/.exec(x);
605602
if (comps) {
606603
curr.start = new Date(comps[3], comps[1] - 1, comps[2]);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
BEGIN:VCALENDAR
2+
BEGIN:VEVENT
3+
DTSTART;TZID=Europe/Germany:20241022T230000
4+
DTEND;TZID=TZID=Europe/Germany:20241023T000000
5+
RRULE:FREQ=DAILY;WKST=MO;COUNT=4
6+
DTSTAMP:20241009T153220Z
7+
8+
CREATED:20241009T153058Z
9+
LAST-MODIFIED:20241009T153205Z
10+
SEQUENCE:0
11+
STATUS:CONFIRMED
12+
SUMMARY:TestCal_AllDayRepeatingEvent
13+
TRANSP:TRANSPARENT
14+
END:VEVENT
15+
END:VCALENDAR

test/test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,41 @@ vows
11611161
}
11621162
}
11631163
}
1164+
},
1165+
'with germany_at_end_of_day_repeating.ics': {
1166+
topic() {
1167+
return ical.parseFile('./test/germany_at_end_of_day_repeating.ics');
1168+
},
1169+
checkEnd: {
1170+
topic(events) {
1171+
return _.select(_.values(events), x => {
1172+
return x.uid === '[email protected]';
1173+
})[0];
1174+
},
1175+
'task completed'(task) {
1176+
assert.equal(task.start.toDateString(), new Date(2024, 9, 22, 23, 0, 0).toDateString());
1177+
}
1178+
}
1179+
},
1180+
'with whole_day_moved_over_dst_change_berlin.ics': {
1181+
topic() {
1182+
return ical.parseFile('./test/whole_day_moved_over_dst_change_berlin.ics');
1183+
},
1184+
checkEnd: {
1185+
topic(events) {
1186+
return _.select(_.values(events), x => {
1187+
return x.uid === '[email protected]';
1188+
})[0].recurrences['2024-10-28'];
1189+
},
1190+
'topic recurrence': {
1191+
'datetype is date'(task) {
1192+
assert.equal(task.datetype, 'date');
1193+
},
1194+
'moved event starts 30 Oct 2024'(now) {
1195+
assert.equal(now.start.toDateString(), new Date(2024, 9, 30, 0, 0, 0).toDateString());
1196+
}
1197+
}
1198+
}
11641199
}
11651200
})
11661201
.export(module);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
BEGIN:VCALENDAR
2+
BEGIN:VEVENT
3+
DTSTART;VALUE=DATE:20241027
4+
DTEND;VALUE=DATE:20241028
5+
RRULE:FREQ=DAILY;WKST=SU;COUNT=3
6+
DTSTAMP:20241020T152634Z
7+
8+
CREATED:20241020T152434Z
9+
LAST-MODIFIED:20241020T152536Z
10+
SEQUENCE:1
11+
STATUS:CONFIRMED
12+
SUMMARY:test whole day moved
13+
TRANSP:TRANSPARENT
14+
END:VEVENT
15+
BEGIN:VEVENT
16+
DTSTART;VALUE=DATE:20241030
17+
DTEND;VALUE=DATE:20241031
18+
DTSTAMP:20241020T152634Z
19+
20+
RECURRENCE-ID;VALUE=DATE:20241028
21+
CREATED:20241020T152434Z
22+
LAST-MODIFIED:20241020T152536Z
23+
SEQUENCE:2
24+
STATUS:CONFIRMED
25+
SUMMARY:test whole day moved
26+
TRANSP:TRANSPARENT
27+
END:VEVENT
28+
END:VCALENDAR

0 commit comments

Comments
 (0)