Skip to content

Commit

Permalink
ICAL.Event duration should take timezones into account
Browse files Browse the repository at this point in the history
Signed-off-by: Georg Ehrke <[email protected]>
  • Loading branch information
georgehrke authored and kewisch committed Jan 13, 2020
1 parent ac4df07 commit a8d4b84
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/ical/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ ICAL.Event = (function() {
get duration() {
var duration = this._firstProp('duration');
if (!duration) {
return this.endDate.subtractDate(this.startDate);
return this.endDate.subtractDateTz(this.startDate);
}
return duration;
},
Expand Down
47 changes: 45 additions & 2 deletions test/event_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ suite('ICAL.Event', function() {


var testTzid = 'America/New_York';
testSupport.useTimezones(testTzid, 'America/Denver');
testSupport.useTimezones(testTzid, 'America/Denver', 'America/Los_Angeles');

var icsData;

Expand Down Expand Up @@ -867,7 +867,7 @@ suite('ICAL.Event', function() {
day: 2,
hour: 6,
isDate: false,
timezone: testTzid
timezone: subject.startDate.zone
});

assert.equal(subject.duration.toString(), 'P2D');
Expand Down Expand Up @@ -956,6 +956,49 @@ suite('ICAL.Event', function() {
icsData = data;
});

test('result with different timezones', function() {
var subject = (new ICAL.Component(ICAL.parse(icsData)))
.getFirstSubcomponent('vevent');
// 3 hours ahead of L.A.
subject.updatePropertyWithValue('dtstart', ICAL.Time.fromData({
year: 2012,
month: 1,
day: 1,
hour: 10,
minute: 20,
timezone: 'America/New_York'
}));
subject.updatePropertyWithValue('dtend', ICAL.Time.fromData({
year: 2012,
month: 1,
day: 1,
hour: 12,
minute: 50,
timezone: 'America/Los_Angeles'
}));

subject = new ICAL.Event(subject);
assert.equal(subject.startDate.toString(), ICAL.Time.fromData({
year: 2012,
month: 1,
day: 1,
hour: 10,
minute: 20,
timezone: 'America/New_York',
}).toString());

assert.equal(subject.endDate.toString(), ICAL.Time.fromData({
year: 2012,
month: 1,
day: 1,
hour: 12,
minute: 50,
timezone: 'America/Los_Angeles'
}).toString());

assert.equal(subject.duration.toString(), 'PT5H30M');
})

test('set', function() {
var subject = new ICAL.Component(ICAL.parse(icsData));
subject = new ICAL.Event(subject.getFirstSubcomponent('vevent'));
Expand Down

0 comments on commit a8d4b84

Please sign in to comment.