Skip to content

Commit

Permalink
fix test for whole day event cross over dst change (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdetweil authored Oct 21, 2024
1 parent 2d16244 commit c20e9f3
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 5 deletions.
7 changes: 2 additions & 5 deletions ical.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,11 +584,8 @@ module.exports = {
rule = rule.slice(rule.lastIndexOf('FREQ='));
// If no rule start date
if (rule.includes('DTSTART') === false) {
// Get date/time into a specific format for comapare
let x = moment(curr.start).format('MMMM/Do/YYYY, h:mm:ss a');
// If the local time value is midnight
// This a whole day event
if (x.slice(-11) === '12:00:00 am') {
if (curr.datetype === 'date') {
// Get the timezone offset
// The internal date is stored in UTC format
const offset = curr.start.getTimezoneOffset();
Expand All @@ -600,7 +597,7 @@ module.exports = {
curr.start = new Date(curr.start.getTime() + (Math.abs(offset) * 60000));
} else {
// Get rid of any time (shouldn't be any, but be sure)
x = moment(curr.start).format('MMMM/Do/YYYY');
const x = moment(curr.start).format('MMMM/Do/YYYY');
const comps = /^(\d{2})\/(\d{2})\/(\d{4})/.exec(x);
if (comps) {
curr.start = new Date(comps[3], comps[1] - 1, comps[2]);
Expand Down
15 changes: 15 additions & 0 deletions test/germany_at_end_of_day_repeating.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
BEGIN:VCALENDAR
BEGIN:VEVENT
DTSTART;TZID=Europe/Germany:20241022T230000
DTEND;TZID=TZID=Europe/Germany:20241023T000000
RRULE:FREQ=DAILY;WKST=MO;COUNT=4
DTSTAMP:20241009T153220Z
UID:[email protected]
CREATED:20241009T153058Z
LAST-MODIFIED:20241009T153205Z
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:TestCal_AllDayRepeatingEvent
TRANSP:TRANSPARENT
END:VEVENT
END:VCALENDAR
35 changes: 35 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,41 @@ vows
}
}
}
},
'with germany_at_end_of_day_repeating.ics': {
topic() {
return ical.parseFile('./test/germany_at_end_of_day_repeating.ics');
},
checkEnd: {
topic(events) {
return _.select(_.values(events), x => {
return x.uid === '[email protected]';
})[0];
},
'task completed'(task) {
assert.equal(task.start.toDateString(), new Date(2024, 9, 22, 23, 0, 0).toDateString());
}
}
},
'with whole_day_moved_over_dst_change_berlin.ics': {
topic() {
return ical.parseFile('./test/whole_day_moved_over_dst_change_berlin.ics');
},
checkEnd: {
topic(events) {
return _.select(_.values(events), x => {
return x.uid === '[email protected]';
})[0].recurrences['2024-10-28'];
},
'topic recurrence': {
'datetype is date'(task) {
assert.equal(task.datetype, 'date');
},
'moved event starts 30 Oct 2024'(now) {
assert.equal(now.start.toDateString(), new Date(2024, 9, 30, 0, 0, 0).toDateString());
}
}
}
}
})
.export(module);
28 changes: 28 additions & 0 deletions test/whole_day_moved_over_dst_change_berlin.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
BEGIN:VCALENDAR
BEGIN:VEVENT
DTSTART;VALUE=DATE:20241027
DTEND;VALUE=DATE:20241028
RRULE:FREQ=DAILY;WKST=SU;COUNT=3
DTSTAMP:20241020T152634Z
UID:[email protected]
CREATED:20241020T152434Z
LAST-MODIFIED:20241020T152536Z
SEQUENCE:1
STATUS:CONFIRMED
SUMMARY:test whole day moved
TRANSP:TRANSPARENT
END:VEVENT
BEGIN:VEVENT
DTSTART;VALUE=DATE:20241030
DTEND;VALUE=DATE:20241031
DTSTAMP:20241020T152634Z
UID:[email protected]
RECURRENCE-ID;VALUE=DATE:20241028
CREATED:20241020T152434Z
LAST-MODIFIED:20241020T152536Z
SEQUENCE:2
STATUS:CONFIRMED
SUMMARY:test whole day moved
TRANSP:TRANSPARENT
END:VEVENT
END:VCALENDAR

0 comments on commit c20e9f3

Please sign in to comment.