Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be strict about how icaltype assigned/used in Time #90

Merged
merged 2 commits into from
Jun 11, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions build/ical.js
Original file line number Diff line number Diff line change
Expand Up @@ -3255,7 +3255,11 @@ ICAL.TimezoneService = (function() {
ICAL.Time.prototype = {

icalclass: "icaltime",
icaltype: "date-time",

// is read only strictly defined by isDate
get icaltype() {
return this.isDate ? 'date' : 'date-time';
},

/**
* @type ICAL.Timezone
Expand Down Expand Up @@ -3333,6 +3337,8 @@ ICAL.TimezoneService = (function() {

fromData: function fromData(aData, aZone) {
for (var key in aData) {
// ical type cannot be set
if (key === 'icaltype') continue;
this[key] = aData[key];
}

Expand All @@ -3346,8 +3352,6 @@ ICAL.TimezoneService = (function() {
this.isDate = aData.isDate;
}

this.icaltype = (this.isDate ? "date" : "date-time");

if (aData && "timezone" in aData) {
var zone = ICAL.TimezoneService.get(
aData.timezone
Expand Down Expand Up @@ -3746,7 +3750,6 @@ ICAL.TimezoneService = (function() {
this._time.minute = 0;
this._time.second = 0;
}
this.icaltype = (isDate ? "date" : "date-time");
this.adjust(0, 0, 0, 0);

return this;
Expand Down
11 changes: 7 additions & 4 deletions lib/ical/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@
ICAL.Time.prototype = {

icalclass: "icaltime",
icaltype: "date-time",

// is read only strictly defined by isDate
get icaltype() {
return this.isDate ? 'date' : 'date-time';
},

/**
* @type ICAL.Timezone
Expand Down Expand Up @@ -124,6 +128,8 @@

fromData: function fromData(aData, aZone) {
for (var key in aData) {
// ical type cannot be set
if (key === 'icaltype') continue;
this[key] = aData[key];
}

Expand All @@ -137,8 +143,6 @@
this.isDate = aData.isDate;
}

this.icaltype = (this.isDate ? "date" : "date-time");

if (aData && "timezone" in aData) {
var zone = ICAL.TimezoneService.get(
aData.timezone
Expand Down Expand Up @@ -537,7 +541,6 @@
this._time.minute = 0;
this._time.second = 0;
}
this.icaltype = (isDate ? "date" : "date-time");
this.adjust(0, 0, 0, 0);

return this;
Expand Down
36 changes: 36 additions & 0 deletions test/time_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,42 @@ suite('icaltime', function() {
});
});

suite('.icaltime', function() {
function verify(time, type) {
test('convert time ' + JSON.stringify(time), function() {
assert.equal(
(new ICAL.Time(time)).icaltype,
type
);
});
}

verify({ year: 2013, month: 1, day: 1 }, 'date');
verify(
{ year: 2013, month: 1, day: 1, hour: 3, isDate: true },
'date'
);

verify(
{ year: 2013, month: 1, day: 1, hour: 22 },
'date-time'
);

verify(
{ year: 2013, isDate: false },
'date-time'
);

test('converting types during runtime', function() {
var time = new ICAL.Time({
year: 2013, isDate: false
});

time.isDate = true;
assert.equal(time.icaltype, 'date');
});
});

suite('setters', function() {
var subject;

Expand Down