jakubroztocil/rrule — pull request #78 by mattcasey (2014-12-11 22:55:17+00:00)
Title: allow ability to provide timezone support via custom Date class

Integration was inspired by @chotiwat. I wanted to use moment-timezone, so this patch allows anyone to write a plugin to override the Date object used internally by rrule. My fork also includes a new rrule option "timezone"

Next steps: Tests? Also, I would like to include my moment-timezone plugin as part of the rrule library, would be happy to hear suggestions. Currently, I'm implementing moment-timezone like this:

```
var rrule = require('rrule');
var RRule = rrule.RRule;

var moment = require('moment-timezone');

function momentDate() {
var date, tz;
if (arguments[0] instanceof Date) {
date = arguments[0];
tz = arguments[1];
}
else if (arguments.length === 1) {
date = new Date(arguments[0]);
}
else {
date = {
years: arguments[0],
months: arguments[1],
days: arguments[2],
hours: arguments[3],
minutes: arguments[4],
seconds: arguments[5]
};
tz = arguments[6];
}
this._moment = moment.tz(date, tz);
}

momentDate.prototype.getDate = function () {
return this._moment.date();
};

momentDate.prototype.getDay = function () {
return this._moment.day();
};

momentDate.prototype.getFullYear = function () {
return this._moment.toDate().getFullYear();
};

momentDate.prototype.getHours = function () {
return this._moment.hours();
};

momentDate.prototype.getMinutes = function () {
return this._moment.minutes();
};

momentDate.prototype.getMonth = function () {
return this._moment.month();
};

momentDate.prototype.getSeconds = function () {
return this._moment.seconds();
};

momentDate.prototype.getTime = function () {
return this._moment.toDate().getTime();
};

momentDate.prototype.getTimezoneOffset = function () {
return this._moment.zone();
};

momentDate.prototype.setMilliseconds = function (ms) {
this._moment.milliseconds(ms);
};

momentDate.prototype.toString = function () {
return this._moment.toString();
};

momentDate.prototype.valueOf = function () {
return this._moment.toDate().getTime();
};

rrule.setDateClass(momentDate);