(function(Date, _, undefined){
+ // create shortcuts to Date.prototype for minification
+ var dateProto = Date.prototype;
// assign variables here so they can be overwritten for i18n or customization
var self = this, _d,
wordsMonths = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
}
// Date.prototype.humanize
- function humanize(inputString) {
+ dateProto.humanize = function(inputString) {
// shortcuts to this and getting time functions
// done to save bytes in minification
var self = this,
return inputString.replace(charactersToReplace, replaceFunction);
}
+ // is leap year
+ dateProto.isleapyear = function() {
+ var year = this.getFullYear();
+ return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
+ }
+
+ // is daylight savings time
+ dateProto.isdst = function() {
+ var year = this.getFullYear();
+ var offset = new Date(year, 0, 1).getTimezoneOffset();
+ offset = Math.max(offset, new Date(year, 6, 1).getTimezoneOffset());
+ return this.getTimezoneOffset() < offset;
+ }
+
+ // helper function for Date.prototype.add and Date.prototype.subtract
+ function dateAddRemove(input, self, adding){
+ var ms = input.ms,
+ s = input.s,
+ m = input.m,
+ h = input.h,
+ d = input.d,
+ w = input.w,
+ M = input.M,
+ y = input.y;
+ ms && self.addMilliseconds(ms * adding);
+ s && self.addSeconds(s * adding);
+ m && self.addMinutes(m * adding);
+ h && self.addHours(h * adding);
+ d && self.addDays(d * adding);
+ w && self.addWeeks(w * adding);
+ M && self.addMonths(M * adding);
+ y && self.addYears(y * adding);
+ }
+
+ dateProto.add = function (input) {
+ dateAddRemove(input, this, 1);
+ };
+
+ dateProto.subtract = function (input) {
+ dateAddRemove(input, this, -1);
+ };
+
/*
* Underscore mixins
*/
}
};
- // assign to prototype
- Date.prototype.humanize = humanize;
-
// assign to global
self._d = _d;