Skip to content

Commit

Permalink
swap arguments for timezone_service
Browse files Browse the repository at this point in the history
  • Loading branch information
jannikac committed Jun 26, 2024
1 parent 523c7c1 commit ca406e0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
27 changes: 21 additions & 6 deletions lib/ical/timezone_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,39 @@ const TimezoneService = {
/**
* Registers a timezone object or component.
*
* @param {Component|Timezone} timezone
* The initialized zone or vtimezone.
*
* @param {String=} name
* The name of the timezone. Defaults to the component's TZID if not
* passed.
* @param {Component|Timezone} timezone
* The initialized zone or vtimezone.
*/
register: function(name, timezone) {
register: function(timezone, name) {
if (zones === null) {
this.reset();
}

if (name instanceof Component) {
if (name.name === 'vtimezone') {
timezone = new Timezone(name);
// This avoids a breaking change by the change of argument order
// TODO remove in v3
if (typeof timezone === "string" && name instanceof Timezone) {
[timezone, name] = [name, timezone];
}

if (!name) {
if (timezone instanceof Timezone) {
name = timezone.tzid;
} else {
if (timezone.name === 'vtimezone') {
timezone = new Timezone(timezone);
name = timezone.tzid;
}
}
}

if (!timezone.tzid && !name) {
throw new TypeError("neither a timezone nor a name was passed");
}

if (timezone instanceof Timezone) {
zones[name] = timezone;
} else {
Expand Down
2 changes: 1 addition & 1 deletion test/timezone_service_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ suite('timezone_service', function() {
assert.throws(function() {
let comp = new ICAL.Component('vtoaster');
subject.register(comp);
}, "timezone must be ICAL.Timezone");
}, "neither a timezone nor a name was passed");
});

test('override', function() {
Expand Down

0 comments on commit ca406e0

Please sign in to comment.