Skip to content

Commit

Permalink
feat(Event): Allow X-APPLE-STRUCTURED-LOCATION without address
Browse files Browse the repository at this point in the history
Closes #236
  • Loading branch information
sebbo2002 committed Apr 9, 2021
1 parent 1eddcc7 commit 4e63e29
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1448,10 +1448,14 @@ export default class ICalEvent {

// LOCATION
if (this.data.location?.title) {
if (this.data.location.address && this.data.location.radius && this.data.location.geo) {
g += 'LOCATION:' + escape(this.data.location.title + '\n' + this.data.location.address) + '\r\n';

g += 'X-APPLE-STRUCTURED-LOCATION;VALUE=URI;X-ADDRESS=' + escape(this.data.location.address) + ';' +
if (this.data.location.radius && this.data.location.geo) {
g += 'LOCATION:' + escape(
this.data.location.title +
(this.data.location.address ? '\n' + this.data.location.address : '')
) + '\r\n';

g += 'X-APPLE-STRUCTURED-LOCATION;VALUE=URI;' +
(this.data.location.address ? 'X-ADDRESS=' + escape(this.data.location.address) + ';' : '') +
'X-APPLE-RADIUS=' + escape(this.data.location.radius) + ';' +
'X-TITLE=' + escape(this.data.location.title) +
':geo:' + escape(this.data.location.geo?.lat) + ',' + escape(this.data.location.geo?.lon) + '\r\n';
Expand Down
39 changes: 39 additions & 0 deletions test/issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,43 @@ describe('Issues', function () {
assert.ok(str.indexOf('EXDATE;TZID=America/New_York:20201213T000000') > -1);
});
});

describe('Issue #236', function () {
it('should look like in the example', function () {
const calendar = ical({
events: [{
id: 'foo',
start: new Date('2020-08-13T00:00:00-05:00'),
stamp: new Date('2020-08-13T00:00:00-05:00'),
summary: 'Example Event',
location: {
title: 'Los Angeles, California, United States',
geo: {
lon: -118.24368,
lat: 34.05223,
},
radius: 400
}
}]
});

assert.strictEqual(calendar.toString(), [
'BEGIN:VCALENDAR',
'VERSION:2.0',
'PRODID:-//sebbo.net//ical-generator//EN',
'BEGIN:VEVENT',
'UID:foo',
'SEQUENCE:0',
'DTSTAMP:20200813T050000Z',
'DTSTART:20200813T050000Z',
'SUMMARY:Example Event',
'LOCATION:Los Angeles\\, California\\, United States',
'X-APPLE-STRUCTURED-LOCATION;VALUE=URI;X-APPLE-RADIUS=400;X-TITLE=Los Angel',
' es\\, California\\, United States:geo:34.05223,-118.24368',
'GEO:34.05223;-118.24368',
'END:VEVENT',
'END:VCALENDAR'
].join('\r\n'));
});
});
});

0 comments on commit 4e63e29

Please sign in to comment.