Commit 2663beac authored by Sebastian's avatar Sebastian
Browse files

Event: inherit timezone from calendar

see #36
parent a21e6147
......@@ -222,11 +222,11 @@ var ICalCalendar = function(_data) {
* @returns {ICalCalendar}
*/
this.timezone = function(timezone) {
if(!timezone) {
if(timezone === undefined) {
return data.timezone;
}
data.timezone = timezone.toString();
data.timezone = timezone ? timezone.toString() : null;
return this;
};
......@@ -296,7 +296,7 @@ var ICalCalendar = function(_data) {
// update errors to 0.1.x version
try {
e = new ICalEvent(event);
e = new ICalEvent(event, this);
}
catch(err) {
throw err.replace(/`([\w.]+)`/i, 'event.$1');
......@@ -316,7 +316,7 @@ var ICalCalendar = function(_data) {
*/
this.createEvent = function(eventData) {
var ICalEvent = require('./event.js'),
event = new ICalEvent(eventData);
event = new ICalEvent(eventData, this);
data.events.push(event);
return event;
......
......@@ -6,7 +6,7 @@
* @module event
* @constructor ICalEvent Event
*/
var ICalEvent = function(_data) {
var ICalEvent = function(_data, cal) {
var attributes = ['id', 'uid', 'sequence', 'start', 'end', 'timezone', 'stamp', 'timestamp', 'allDay', 'floating', 'repeating', 'summary', 'location', 'description', 'organizer', 'attendees', 'alarms', 'method', 'status', 'url'],
vars,
i,
......@@ -23,7 +23,7 @@ var ICalEvent = function(_data) {
sequence: 0,
start: null,
end: null,
timezone: null,
timezone: undefined,
stamp: new Date(),
allDay: false,
floating: false,
......@@ -157,11 +157,17 @@ var ICalEvent = function(_data) {
* @returns {ICalEvent|String}
*/
this.timezone = function(timezone) {
if(!timezone) {
if(timezone === undefined && data.timezone !== undefined) {
return data.timezone;
}
if(timezone === undefined && cal.timezone() !== undefined) {
return cal.timezone();
}
if(timezone === undefined) {
return null;
}
data.timezone = timezone.toString();
data.timezone = timezone ? timezone.toString() : null;
data.floating = false;
return this;
};
......@@ -606,6 +612,9 @@ var ICalEvent = function(_data) {
if(!data.start) {
throw 'No value for `start` in ICalEvent #' + data.id + ' given!';
}
if(data.timezone) {
data.floating = false;
}
// DATE & TIME
g += 'BEGIN:VEVENT\r\n';
......
......@@ -448,7 +448,7 @@ describe('ical-generator 0.2.x / ICalCalendar', function() {
it('should change something', function() {
var cal = ical();
cal.createEvent({
sequenze: 512,
sequence: 512,
start: new Date(),
end: new Date(new Date().getTime() + 3600000),
summary: 'Example Event'
......@@ -550,6 +550,34 @@ describe('ical-generator 0.2.x / ICalCalendar', function() {
e.timezone('Europe/London');
assert.ok(cal.toString().indexOf('Europe/London') > -1);
});
it('should inherit from calendar', function() {
var cal = ical(),
e = cal.createEvent({
start: new Date(),
end: new Date(new Date().getTime() + 3600000),
summary: 'Example Event'
});
assert.equal(cal.timezone(), null);
assert.equal(e.timezone(), null);
cal.timezone('Europe/London');
assert.equal(cal.timezone(), 'Europe/London');
assert.equal(e.timezone(), 'Europe/London');
e.timezone('Europe/Berlin');
assert.equal(cal.timezone(), 'Europe/London');
assert.equal(e.timezone(), 'Europe/Berlin');
cal.timezone(null);
assert.equal(cal.timezone(), null);
assert.equal(e.timezone(), 'Europe/Berlin');
e.timezone(null);
assert.equal(cal.timezone(), null);
assert.ok(!e.timezone());
});
});
describe('stamp()', function() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment