Skip to content

Commit 1d2d611

Browse files
committed
Fixed duration issue when having multiple time units
1 parent 7dd8e11 commit 1d2d611

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

ical.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -470,15 +470,19 @@ module.exports = {
470470
S: 'seconds'
471471
};
472472
// Get the list of duration elements
473-
const r = curr.duration.match(/-?\d{1,10}[YMWDHS]/g);
473+
const duration = curr.duration.match(/-?\d{1,10}[YMWDHS]/g);
474474

475475
// Use the duration to create the end value, from the start
476-
let newend = moment.utc(curr.start);
476+
let newEnd = moment.utc(curr.start);
477477
// Is the 1st character a negative sign?
478478
const indicator = curr.duration.startsWith('-') ? -1 : 1;
479-
newend = newend.add(Number.parseInt(r, 10) * indicator, durationUnits[r.toString().slice(-1)]);
479+
480+
for (const r of duration) {
481+
newEnd = newEnd.add(Number.parseInt(r, 10) * indicator, durationUnits[r.toString().slice(-1)]);
482+
}
483+
480484
// End is a Date type, not moment
481-
curr.end = newend.toDate();
485+
curr.end = newEnd.toDate();
482486
}
483487
}
484488

test/test-async.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ vows
851851
},
852852
'it uses the start/end of the event'(event) {
853853
assert.equal(event.start.toJSON(), '2024-02-15T09:00:00.000Z');
854-
assert.equal(event.end.toJSON(), '2024-02-15T09:15:00.000Z');
854+
assert.equal(event.end.toJSON(), '2024-02-15T10:15:00.000Z');
855855
}
856856
}
857857
},

test/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ vows
10411041
},
10421042
'it uses the start/end of the event'(event) {
10431043
assert.equal(event.start.toJSON(), '2024-02-15T09:00:00.000Z');
1044-
assert.equal(event.end.toJSON(), '2024-02-15T09:15:00.000Z');
1044+
assert.equal(event.end.toISOString(), '2024-02-15T10:15:00.000Z');
10451045
}
10461046
}
10471047
},

test/test_date_time_duration.ics

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ DESCRIPTION:
1313
LOCATION:Kriftel
1414
X-APPLE-STRUCTURED-LOCATION;VALUE=URI;X-TITLE=Kriftel: geo:50.083558\,8.4693855
1515
DTSTART:20240215T090000Z
16-
DURATION:PT15M
16+
DURATION:PT1H15M
1717
END:VEVENT
1818
END:VCALENDAR

0 commit comments

Comments
 (0)