gentelella
Version:
Gentelella Admin is a free to use Bootstrap admin template
1,554 lines (1,459 loc) • 136 kB
JavaScript
/**
* @overview datejs
* @version 1.0.0-rc3
* @author Gregory Wild-Smith <gregory@wild-smith.com>
* @copyright 2014 Gregory Wild-Smith
* @license MIT
* @homepage https://github.com/abritinthebay/datejs
*/
/*
* DateJS Culture String File
* Country Code: tt-RU
* Name: Tatar (Russia)
* Format: "key" : "value"
* Key is the en-US term, Value is the Key in the current language.
*/
Date.CultureStrings = Date.CultureStrings || {};
Date.CultureStrings["tt-RU"] = {
"name": "tt-RU",
"englishName": "Tatar (Russia)",
"nativeName": "Татар (Россия)",
"Sunday": "Якшәмбе",
"Monday": "Дүшәмбе",
"Tuesday": "Сишәмбе",
"Wednesday": "Чәршәмбе",
"Thursday": "Пәнҗешәмбе",
"Friday": "Җомга",
"Saturday": "Шимбә",
"Sun": "Якш",
"Mon": "Дүш",
"Tue": "Сиш",
"Wed": "Чәрш",
"Thu": "Пәнҗ",
"Fri": "Җом",
"Sat": "Шим",
"Su": "Якш",
"Mo": "Дүш",
"Tu": "Сиш",
"We": "Чәрш",
"Th": "Пәнҗ",
"Fr": "Җом",
"Sa": "Шим",
"S_Sun_Initial": "Я",
"M_Mon_Initial": "Д",
"T_Tue_Initial": "С",
"W_Wed_Initial": "Ч",
"T_Thu_Initial": "П",
"F_Fri_Initial": "Җ",
"S_Sat_Initial": "Ш",
"January": "Гыйнварь",
"February": "Февраль",
"March": "Март",
"April": "Апрель",
"May": "Май",
"June": "Июнь",
"July": "Июль",
"August": "Август",
"September": "Сентябрь",
"October": "Октябрь",
"November": "Ноябрь",
"December": "Декабрь",
"Jan_Abbr": "Гыйнв",
"Feb_Abbr": "Фев",
"Mar_Abbr": "Мар",
"Apr_Abbr": "Апр",
"May_Abbr": "Май",
"Jun_Abbr": "Июн",
"Jul_Abbr": "Июл",
"Aug_Abbr": "Авг",
"Sep_Abbr": "Сен",
"Oct_Abbr": "Окт",
"Nov_Abbr": "Ноя",
"Dec_Abbr": "Дек",
"AM": "",
"PM": "",
"firstDayOfWeek": 1,
"twoDigitYearMax": 2029,
"mdy": "dmy",
"M/d/yyyy": "dd.MM.yyyy",
"dddd, MMMM dd, yyyy": "d MMMM yyyy",
"h:mm tt": "H:mm",
"h:mm:ss tt": "H:mm:ss",
"dddd, MMMM dd, yyyy h:mm:ss tt": "d MMMM yyyy H:mm:ss",
"yyyy-MM-ddTHH:mm:ss": "yyyy-MM-ddTHH:mm:ss",
"yyyy-MM-dd HH:mm:ssZ": "yyyy-MM-dd HH:mm:ssZ",
"ddd, dd MMM yyyy HH:mm:ss": "ddd, dd MMM yyyy HH:mm:ss",
"MMMM dd": "d MMMM",
"MMMM, yyyy": "MMMM yyyy",
"/jan(uary)?/": "гыйнв(арь)?",
"/feb(ruary)?/": "фев(раль)?",
"/mar(ch)?/": "мар(т)?",
"/apr(il)?/": "апр(ель)?",
"/may/": "май",
"/jun(e)?/": "июн(ь)?",
"/jul(y)?/": "июл(ь)?",
"/aug(ust)?/": "авг(уст)?",
"/sep(t(ember)?)?/": "сен(тябрь)?",
"/oct(ober)?/": "окт(ябрь)?",
"/nov(ember)?/": "ноя(брь)?",
"/dec(ember)?/": "дек(абрь)?",
"/^su(n(day)?)?/": "^якшәмбе",
"/^mo(n(day)?)?/": "^дүшәмбе",
"/^tu(e(s(day)?)?)?/": "^сишәмбе",
"/^we(d(nesday)?)?/": "^чәршәмбе",
"/^th(u(r(s(day)?)?)?)?/": "^пәнҗешәмбе",
"/^fr(i(day)?)?/": "^җомга",
"/^sa(t(urday)?)?/": "^шимбә",
"/^next/": "^next",
"/^last|past|prev(ious)?/": "^last|past|prev(ious)?",
"/^(\\+|aft(er)?|from|hence)/": "^(\\+|aft(er)?|from|hence)",
"/^(\\-|bef(ore)?|ago)/": "^(\\-|bef(ore)?|ago)",
"/^yes(terday)?/": "^yes(terday)?",
"/^t(od(ay)?)?/": "^t(od(ay)?)?",
"/^tom(orrow)?/": "^tom(orrow)?",
"/^n(ow)?/": "^n(ow)?",
"/^ms|milli(second)?s?/": "^ms|milli(second)?s?",
"/^sec(ond)?s?/": "^sec(ond)?s?",
"/^mn|min(ute)?s?/": "^mn|min(ute)?s?",
"/^h(our)?s?/": "^h(our)?s?",
"/^w(eek)?s?/": "^w(eek)?s?",
"/^m(onth)?s?/": "^m(onth)?s?",
"/^d(ay)?s?/": "^d(ay)?s?",
"/^y(ear)?s?/": "^y(ear)?s?",
"/^(a|p)/": "^(a|p)",
"/^(a\\.?m?\\.?|p\\.?m?\\.?)/": "^(a\\.?m?\\.?|p\\.?m?\\.?)",
"/^((e(s|d)t|c(s|d)t|m(s|d)t|p(s|d)t)|((gmt)?\\s*(\\+|\\-)\\s*\\d\\d\\d\\d?)|gmt|utc)/": "^((e(s|d)t|c(s|d)t|m(s|d)t|p(s|d)t)|((gmt)?\\s*(\\+|\\-)\\s*\\d\\d\\d\\d?)|gmt|utc)",
"/^\\s*(st|nd|rd|th)/": "^\\s*(st|nd|rd|th)",
"/^\\s*(\\:|a(?!u|p)|p)/": "^\\s*(\\:|a(?!u|p)|p)",
"LINT": "LINT",
"TOT": "TOT",
"CHAST": "CHAST",
"NZST": "NZST",
"NFT": "NFT",
"SBT": "SBT",
"AEST": "AEST",
"ACST": "ACST",
"JST": "JST",
"CWST": "CWST",
"CT": "CT",
"ICT": "ICT",
"MMT": "MMT",
"BIOT": "BST",
"NPT": "NPT",
"IST": "IST",
"PKT": "PKT",
"AFT": "AFT",
"MSK": "MSK",
"IRST": "IRST",
"FET": "FET",
"EET": "EET",
"CET": "CET",
"UTC": "UTC",
"GMT": "GMT",
"CVT": "CVT",
"GST": "GST",
"BRT": "BRT",
"NST": "NST",
"AST": "AST",
"EST": "EST",
"CST": "CST",
"MST": "MST",
"PST": "PST",
"AKST": "AKST",
"MIT": "MIT",
"HST": "HST",
"SST": "SST",
"BIT": "BIT",
"CHADT": "CHADT",
"NZDT": "NZDT",
"AEDT": "AEDT",
"ACDT": "ACDT",
"AZST": "AZST",
"IRDT": "IRDT",
"EEST": "EEST",
"CEST": "CEST",
"BST": "BST",
"PMDT": "PMDT",
"ADT": "ADT",
"NDT": "NDT",
"EDT": "EDT",
"CDT": "CDT",
"MDT": "MDT",
"PDT": "PDT",
"AKDT": "AKDT",
"HADT": "HADT"
};
Date.CultureStrings.lang = "tt-RU";
/**
* @overview datejs
* @version 1.0.0-rc3
* @author Gregory Wild-Smith <gregory@wild-smith.com>
* @copyright 2014 Gregory Wild-Smith
* @license MIT
* @homepage https://github.com/abritinthebay/datejs
*/(function () {
var $D = Date;
var lang = Date.CultureStrings ? Date.CultureStrings.lang : null;
var loggedKeys = {}; // for debug purposes.
var getText = {
getFromKey: function (key, countryCode) {
var output;
if (Date.CultureStrings && Date.CultureStrings[countryCode] && Date.CultureStrings[countryCode][key]) {
output = Date.CultureStrings[countryCode][key];
} else {
output = getText.buildFromDefault(key);
}
if (key.charAt(0) === "/") { // Assume it's a regex
output = getText.buildFromRegex(key, countryCode);
}
return output;
},
getFromObjectValues: function (obj, countryCode) {
var key, output = {};
for(key in obj) {
if (obj.hasOwnProperty(key)) {
output[key] = getText.getFromKey(obj[key], countryCode);
}
}
return output;
},
getFromObjectKeys: function (obj, countryCode) {
var key, output = {};
for(key in obj) {
if (obj.hasOwnProperty(key)) {
output[getText.getFromKey(key, countryCode)] = obj[key];
}
}
return output;
},
getFromArray: function (arr, countryCode) {
var output = [];
for (var i=0; i < arr.length; i++){
if (i in arr) {
output[i] = getText.getFromKey(arr[i], countryCode);
}
}
return output;
},
buildFromDefault: function (key) {
var output, length, split, last;
switch(key) {
case "name":
output = "en-US";
break;
case "englishName":
output = "English (United States)";
break;
case "nativeName":
output = "English (United States)";
break;
case "twoDigitYearMax":
output = 2049;
break;
case "firstDayOfWeek":
output = 0;
break;
default:
output = key;
split = key.split("_");
length = split.length;
if (length > 1 && key.charAt(0) !== "/") {
// if the key isn't a regex and it has a split.
last = split[(length - 1)].toLowerCase();
if (last === "initial" || last === "abbr") {
output = split[0];
}
}
break;
}
return output;
},
buildFromRegex: function (key, countryCode) {
var output;
if (Date.CultureStrings && Date.CultureStrings[countryCode] && Date.CultureStrings[countryCode][key]) {
output = new RegExp(Date.CultureStrings[countryCode][key], "i");
} else {
output = new RegExp(key.replace(new RegExp("/", "g"),""), "i");
}
return output;
}
};
var shallowMerge = function (obj1, obj2) {
for (var attrname in obj2) {
if (obj2.hasOwnProperty(attrname)) {
obj1[attrname] = obj2[attrname];
}
}
};
var __ = function (key, language) {
var countryCode = (language) ? language : lang;
loggedKeys[key] = key;
if (typeof key === "object") {
if (key instanceof Array) {
return getText.getFromArray(key, countryCode);
} else {
return getText.getFromObjectKeys(key, countryCode);
}
} else {
return getText.getFromKey(key, countryCode);
}
};
var loadI18nScript = function (code) {
// paatterned after jQuery's getScript.
var url = Date.Config.i18n + code + ".js";
var head = document.getElementsByTagName("head")[0] || document.documentElement;
var script = document.createElement("script");
script.src = url;
var completed = false;
var events = {
done: function (){} // placeholder function
};
// Attach handlers for all browsers
script.onload = script.onreadystatechange = function() {
if ( !completed && (!this.readyState || this.readyState === "loaded" || this.readyState === "complete") ) {
events.done();
head.removeChild(script);
}
};
setTimeout(function() {
head.insertBefore(script, head.firstChild);
}, 0); // allows return to execute first
return {
done: function (cb) {
events.done = function() {
if (cb) {
setTimeout(cb,0);
}
};
}
};
};
var buildInfo = {
buildFromMethodHash: function (obj) {
var key;
for(key in obj) {
if (obj.hasOwnProperty(key)) {
obj[key] = buildInfo[obj[key]]();
}
}
return obj;
},
timeZoneDST: function () {
var DST = {
"CHADT": "+1345",
"NZDT": "+1300",
"AEDT": "+1100",
"ACDT": "+1030",
"AZST": "+0500",
"IRDT": "+0430",
"EEST": "+0300",
"CEST": "+0200",
"BST": "+0100",
"PMDT": "-0200",
"ADT": "-0300",
"NDT": "-0230",
"EDT": "-0400",
"CDT": "-0500",
"MDT": "-0600",
"PDT": "-0700",
"AKDT": "-0800",
"HADT": "-0900"
};
return __(DST);
},
timeZoneStandard: function () {
var standard = {
"LINT": "+1400",
"TOT": "+1300",
"CHAST": "+1245",
"NZST": "+1200",
"NFT": "+1130",
"SBT": "+1100",
"AEST": "+1000",
"ACST": "+0930",
"JST": "+0900",
"CWST": "+0845",
"CT": "+0800",
"ICT": "+0700",
"MMT": "+0630",
"BST": "+0600",
"NPT": "+0545",
"IST": "+0530",
"PKT": "+0500",
"AFT": "+0430",
"MSK": "+0400",
"IRST": "+0330",
"FET": "+0300",
"EET": "+0200",
"CET": "+0100",
"GMT": "+0000",
"UTC": "+0000",
"CVT": "-0100",
"GST": "-0200",
"BRT": "-0300",
"NST": "-0330",
"AST": "-0400",
"EST": "-0500",
"CST": "-0600",
"MST": "-0700",
"PST": "-0800",
"AKST": "-0900",
"MIT": "-0930",
"HST": "-1000",
"SST": "-1100",
"BIT": "-1200"
};
return __(standard);
},
timeZones: function (data) {
var zone;
data.timezones = [];
for (zone in data.abbreviatedTimeZoneStandard) {
if (data.abbreviatedTimeZoneStandard.hasOwnProperty(zone)) {
data.timezones.push({ name: zone, offset: data.abbreviatedTimeZoneStandard[zone]});
}
}
for (zone in data.abbreviatedTimeZoneDST) {
if (data.abbreviatedTimeZoneDST.hasOwnProperty(zone)) {
data.timezones.push({ name: zone, offset: data.abbreviatedTimeZoneDST[zone], dst: true});
}
}
return data.timezones;
},
days: function () {
return __(["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]);
},
dayAbbr: function () {
return __(["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]);
},
dayShortNames: function () {
return __(["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]);
},
dayFirstLetters: function () {
return __(["S_Sun_Initial", "M_Mon_Initial", "T_Tues_Initial", "W_Wed_Initial", "T_Thu_Initial", "F_Fri_Initial", "S_Sat_Initial"]);
},
months: function () {
return __(["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]);
},
monthAbbr: function () {
return __(["Jan_Abbr", "Feb_Abbr", "Mar_Abbr", "Apr_Abbr", "May_Abbr", "Jun_Abbr", "Jul_Abbr", "Aug_Abbr", "Sep_Abbr", "Oct_Abbr", "Nov_Abbr", "Dec_Abbr"]);
},
formatPatterns: function () {
return getText.getFromObjectValues({
shortDate: "M/d/yyyy",
longDate: "dddd, MMMM dd, yyyy",
shortTime: "h:mm tt",
longTime: "h:mm:ss tt",
fullDateTime: "dddd, MMMM dd, yyyy h:mm:ss tt",
sortableDateTime: "yyyy-MM-ddTHH:mm:ss",
universalSortableDateTime: "yyyy-MM-dd HH:mm:ssZ",
rfc1123: "ddd, dd MMM yyyy HH:mm:ss",
monthDay: "MMMM dd",
yearMonth: "MMMM, yyyy"
}, Date.i18n.currentLanguage());
},
regex: function () {
return getText.getFromObjectValues({
inTheMorning: "/( in the )(morn(ing)?)\\b/",
thisMorning: "/(this )(morn(ing)?)\\b/",
amThisMorning: "/(\b\\d(am)? )(this )(morn(ing)?)/",
inTheEvening: "/( in the )(even(ing)?)\\b/",
thisEvening: "/(this )(even(ing)?)\\b/",
pmThisEvening: "/(\b\\d(pm)? )(this )(even(ing)?)/",
jan: "/jan(uary)?/",
feb: "/feb(ruary)?/",
mar: "/mar(ch)?/",
apr: "/apr(il)?/",
may: "/may/",
jun: "/jun(e)?/",
jul: "/jul(y)?/",
aug: "/aug(ust)?/",
sep: "/sep(t(ember)?)?/",
oct: "/oct(ober)?/",
nov: "/nov(ember)?/",
dec: "/dec(ember)?/",
sun: "/^su(n(day)?)?/",
mon: "/^mo(n(day)?)?/",
tue: "/^tu(e(s(day)?)?)?/",
wed: "/^we(d(nesday)?)?/",
thu: "/^th(u(r(s(day)?)?)?)?/",
fri: "/fr(i(day)?)?/",
sat: "/^sa(t(urday)?)?/",
future: "/^next/",
past: "/^last|past|prev(ious)?/",
add: "/^(\\+|aft(er)?|from|hence)/",
subtract: "/^(\\-|bef(ore)?|ago)/",
yesterday: "/^yes(terday)?/",
today: "/^t(od(ay)?)?/",
tomorrow: "/^tom(orrow)?/",
now: "/^n(ow)?/",
millisecond: "/^ms|milli(second)?s?/",
second: "/^sec(ond)?s?/",
minute: "/^mn|min(ute)?s?/",
hour: "/^h(our)?s?/",
week: "/^w(eek)?s?/",
month: "/^m(onth)?s?/",
day: "/^d(ay)?s?/",
year: "/^y(ear)?s?/",
shortMeridian: "/^(a|p)/",
longMeridian: "/^(a\\.?m?\\.?|p\\.?m?\\.?)/",
timezone: "/^((e(s|d)t|c(s|d)t|m(s|d)t|p(s|d)t)|((gmt)?\\s*(\\+|\\-)\\s*\\d\\d\\d\\d?)|gmt|utc)/",
ordinalSuffix: "/^\\s*(st|nd|rd|th)/",
timeContext: "/^\\s*(\\:|a(?!u|p)|p)/"
}, Date.i18n.currentLanguage());
}
};
var CultureInfo = function () {
var info = getText.getFromObjectValues({
name: "name",
englishName: "englishName",
nativeName: "nativeName",
amDesignator: "AM",
pmDesignator: "PM",
firstDayOfWeek: "firstDayOfWeek",
twoDigitYearMax: "twoDigitYearMax",
dateElementOrder: "mdy"
}, Date.i18n.currentLanguage());
var constructedInfo = buildInfo.buildFromMethodHash({
dayNames: "days",
abbreviatedDayNames: "dayAbbr",
shortestDayNames: "dayShortNames",
firstLetterDayNames: "dayFirstLetters",
monthNames: "months",
abbreviatedMonthNames: "monthAbbr",
formatPatterns: "formatPatterns",
regexPatterns: "regex",
abbreviatedTimeZoneDST: "timeZoneDST",
abbreviatedTimeZoneStandard: "timeZoneStandard"
});
shallowMerge(info, constructedInfo);
buildInfo.timeZones(info);
return info;
};
$D.i18n = {
__: function (key, lang) {
return __(key, lang);
},
currentLanguage: function () {
return lang || "en-US";
},
setLanguage: function (code, force, cb) {
var async = false;
if (force || code === "en-US" || (!!Date.CultureStrings && !!Date.CultureStrings[code])) {
lang = code;
Date.CultureStrings = Date.CultureStrings || {};
Date.CultureStrings.lang = code;
Date.CultureInfo = new CultureInfo();
} else {
if (!(!!Date.CultureStrings && !!Date.CultureStrings[code])) {
if (typeof exports !== "undefined" && this.exports !== exports) {
// we're in a Node enviroment, load it using require
try {
require("../i18n/" + code + ".js");
lang = code;
Date.CultureStrings.lang = code;
Date.CultureInfo = new CultureInfo();
} catch (e) {
// var str = "The language for '" + code + "' could not be loaded by Node. It likely does not exist.";
throw new Error("The DateJS IETF language tag '" + code + "' could not be loaded by Node. It likely does not exist.");
}
} else if (Date.Config && Date.Config.i18n) {
// we know the location of the files, so lets load them
async = true;
loadI18nScript(code).done(function(){
lang = code;
Date.CultureStrings = Date.CultureStrings || {};
Date.CultureStrings.lang = code;
Date.CultureInfo = new CultureInfo();
$D.Parsing.Normalizer.buildReplaceData(); // because this is async
if ($D.Grammar) {
$D.Grammar.buildGrammarFormats(); // so we can parse those strings...
}
if (cb) {
setTimeout(cb,0);
}
});
} else {
Date.console.error("The DateJS IETF language tag '" + code + "' is not available and has not been loaded.");
return false;
}
}
}
$D.Parsing.Normalizer.buildReplaceData(); // rebuild normalizer strings
if ($D.Grammar) {
$D.Grammar.buildGrammarFormats(); // so we can parse those strings...
}
if (!async && cb) {
setTimeout(cb,0);
}
},
getLoggedKeys: function () {
return loggedKeys;
},
updateCultureInfo: function () {
Date.CultureInfo = new CultureInfo();
}
};
$D.i18n.updateCultureInfo(); // run automatically
}());
(function () {
var $D = Date,
$P = $D.prototype,
p = function (s, l) {
if (!l) {
l = 2;
}
return ("000" + s).slice(l * -1);
};
if (typeof window !== "undefined" && typeof window.console !== "undefined" && typeof window.console.log !== "undefined") {
$D.console = console; // used only to raise non-critical errors if available
} else {
// set mock so we don't give errors.
$D.console = {
log: function(){},
error: function(){}
};
}
$D.Config = $D.Config || {};
$D.initOverloads = function() {
/**
* Overload of Date.now. Allows an alternate call for Date.now where it returns the
* current Date as an object rather than just milliseconds since the Unix Epoch.
*
* Also provides an implementation of now() for browsers (IE<9) that don't have it.
*
* Backwards compatible so with work with either:
* Date.now() [returns ms]
* or
* Date.now(true) [returns Date]
*/
if (!$D.now) {
$D._now = function now() {
return new Date().getTime();
};
} else if (!$D._now) {
$D._now = $D.now;
}
$D.now = function (returnObj) {
if (returnObj) {
return $D.present();
} else {
return $D._now();
}
};
if ( !$P.toISOString ) {
$P.toISOString = function() {
return this.getUTCFullYear() +
"-" + p(this.getUTCMonth() + 1) +
"-" + p(this.getUTCDate()) +
"T" + p(this.getUTCHours()) +
":" + p(this.getUTCMinutes()) +
":" + p(this.getUTCSeconds()) +
"." + String( (this.getUTCMilliseconds()/1000).toFixed(3)).slice(2, 5) +
"Z";
};
}
// private
if ( $P._toString === undefined ){
$P._toString = $P.toString;
}
};
$D.initOverloads();
/**
* Gets a date that is set to the current date. The time is set to the start of the day (00:00 or 12:00 AM).
* @return {Date} The current date.
*/
$D.today = function () {
return new Date().clearTime();
};
/**
* Gets a date that is set to the current date and time (same as new Date, but chainable)
* @return {Date} The current date.
*/
$D.present = function () {
return new Date();
};
/**
* Compares the first date to the second date and returns an number indication of their relative values.
* @param {Date} First Date object to compare [Required].
* @param {Date} Second Date object to compare to [Required].
* @return {Number} -1 = date1 is lessthan date2. 0 = values are equal. 1 = date1 is greaterthan date2.
*/
$D.compare = function (date1, date2) {
if (isNaN(date1) || isNaN(date2)) {
throw new Error(date1 + " - " + date2);
} else if (date1 instanceof Date && date2 instanceof Date) {
return (date1 < date2) ? -1 : (date1 > date2) ? 1 : 0;
} else {
throw new TypeError(date1 + " - " + date2);
}
};
/**
* Compares the first Date object to the second Date object and returns true if they are equal.
* @param {Date} First Date object to compare [Required]
* @param {Date} Second Date object to compare to [Required]
* @return {Boolean} true if dates are equal. false if they are not equal.
*/
$D.equals = function (date1, date2) {
return (date1.compareTo(date2) === 0);
};
/**
* Gets the language appropriate day name when given the day number(0-6)
* eg - 0 == Sunday
* @return {String} The day name
*/
$D.getDayName = function (n) {
return Date.CultureInfo.dayNames[n];
};
/**
* Gets the day number (0-6) if given a CultureInfo specific string which is a valid dayName, abbreviatedDayName or shortestDayName (two char).
* @param {String} The name of the day (eg. "Monday, "Mon", "tuesday", "tue", "We", "we").
* @return {Number} The day number
*/
$D.getDayNumberFromName = function (name) {
var n = Date.CultureInfo.dayNames, m = Date.CultureInfo.abbreviatedDayNames, o = Date.CultureInfo.shortestDayNames, s = name.toLowerCase();
for (var i = 0; i < n.length; i++) {
if (n[i].toLowerCase() === s || m[i].toLowerCase() === s || o[i].toLowerCase() === s) {
return i;
}
}
return -1;
};
/**
* Gets the month number (0-11) if given a Culture Info specific string which is a valid monthName or abbreviatedMonthName.
* @param {String} The name of the month (eg. "February, "Feb", "october", "oct").
* @return {Number} The day number
*/
$D.getMonthNumberFromName = function (name) {
var n = Date.CultureInfo.monthNames, m = Date.CultureInfo.abbreviatedMonthNames, s = name.toLowerCase();
for (var i = 0; i < n.length; i++) {
if (n[i].toLowerCase() === s || m[i].toLowerCase() === s) {
return i;
}
}
return -1;
};
/**
* Gets the language appropriate month name when given the month number(0-11)
* eg - 0 == January
* @return {String} The month name
*/
$D.getMonthName = function (n) {
return Date.CultureInfo.monthNames[n];
};
/**
* Determines if the current date instance is within a LeapYear.
* @param {Number} The year.
* @return {Boolean} true if date is within a LeapYear, otherwise false.
*/
$D.isLeapYear = function (year) {
return ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0);
};
/**
* Gets the number of days in the month, given a year and month value. Automatically corrects for LeapYear.
* @param {Number} The year.
* @param {Number} The month (0-11).
* @return {Number} The number of days in the month.
*/
$D.getDaysInMonth = function (year, month) {
if (!month && $D.validateMonth(year)) {
month = year;
year = Date.today().getFullYear();
}
return [31, ($D.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
};
$P.getDaysInMonth = function () {
return $D.getDaysInMonth(this.getFullYear(), this.getMonth());
};
$D.getTimezoneAbbreviation = function (offset, dst) {
var p, n = (dst || false) ? Date.CultureInfo.abbreviatedTimeZoneDST : Date.CultureInfo.abbreviatedTimeZoneStandard;
for (p in n) {
if (n.hasOwnProperty(p)) {
if (n[p] === offset) {
return p;
}
}
}
return null;
};
$D.getTimezoneOffset = function (name, dst) {
var i, a =[], z = Date.CultureInfo.timezones;
if (!name) { name = (new Date()).getTimezone();}
for (i = 0; i < z.length; i++) {
if (z[i].name === name.toUpperCase()) {
a.push(i);
}
}
if (!z[a[0]]) {
return null;
}
if (a.length === 1 || !dst) {
return z[a[0]].offset;
} else {
for (i=0; i < a.length; i++) {
if (z[a[i]].dst) {
return z[a[i]].offset;
}
}
}
};
$D.getQuarter = function (d) {
d = d || new Date(); // If no date supplied, use today
var q = [1,2,3,4];
return q[Math.floor(d.getMonth() / 3)]; // ~~~ is a bitwise op. Faster than Math.floor
};
$D.getDaysLeftInQuarter = function (d) {
d = d || new Date();
var qEnd = new Date(d);
qEnd.setMonth(qEnd.getMonth() + 3 - qEnd.getMonth() % 3, 0);
return Math.floor((qEnd - d) / 8.64e7);
};
// private
var validate = function (n, min, max, name) {
name = name ? name : "Object";
if (typeof n === "undefined") {
return false;
} else if (typeof n !== "number") {
throw new TypeError(n + " is not a Number.");
} else if (n < min || n > max) {
// As failing validation is *not* an exceptional circumstance
// lets not throw a RangeError Exception here.
// It's semantically correct but it's not sensible.
return false;
}
return true;
};
/**
* Validates the number is within an acceptable range for milliseconds [0-999].
* @param {Number} The number to check if within range.
* @return {Boolean} true if within range, otherwise false.
*/
$D.validateMillisecond = function (value) {
return validate(value, 0, 999, "millisecond");
};
/**
* Validates the number is within an acceptable range for seconds [0-59].
* @param {Number} The number to check if within range.
* @return {Boolean} true if within range, otherwise false.
*/
$D.validateSecond = function (value) {
return validate(value, 0, 59, "second");
};
/**
* Validates the number is within an acceptable range for minutes [0-59].
* @param {Number} The number to check if within range.
* @return {Boolean} true if within range, otherwise false.
*/
$D.validateMinute = function (value) {
return validate(value, 0, 59, "minute");
};
/**
* Validates the number is within an acceptable range for hours [0-23].
* @param {Number} The number to check if within range.
* @return {Boolean} true if within range, otherwise false.
*/
$D.validateHour = function (value) {
return validate(value, 0, 23, "hour");
};
/**
* Validates the number is within an acceptable range for the days in a month [0-MaxDaysInMonth].
* @param {Number} The number to check if within range.
* @return {Boolean} true if within range, otherwise false.
*/
$D.validateDay = function (value, year, month) {
if (year === undefined || year === null || month === undefined || month === null) { return false;}
return validate(value, 1, $D.getDaysInMonth(year, month), "day");
};
/**
* Validates the number is within an acceptable range for months [0-11].
* @param {Number} The number to check if within range.
* @return {Boolean} true if within range, otherwise false.
*/
$D.validateWeek = function (value) {
return validate(value, 0, 53, "week");
};
/**
* Validates the number is within an acceptable range for months [0-11].
* @param {Number} The number to check if within range.
* @return {Boolean} true if within range, otherwise false.
*/
$D.validateMonth = function (value) {
return validate(value, 0, 11, "month");
};
/**
* Validates the number is within an acceptable range for years.
* @param {Number} The number to check if within range.
* @return {Boolean} true if within range, otherwise false.
*/
$D.validateYear = function (value) {
/**
* Per ECMAScript spec the range of times supported by Date objects is
* exactly -100,000,000 days to +100,000,000 days measured relative to
* midnight at the beginning of 01 January, 1970 UTC.
* This gives a range of 8,640,000,000,000,000 milliseconds to either
* side of 01 January, 1970 UTC.
*
* Earliest possible date: Tue, 20 Apr 271,822 B.C. 00:00:00 UTC
* Latest possible date: Sat, 13 Sep 275,760 00:00:00 UTC
*/
return validate(value, -271822, 275760, "year");
};
$D.validateTimezone = function(value) {
var timezones = {"ACDT":1,"ACST":1,"ACT":1,"ADT":1,"AEDT":1,"AEST":1,"AFT":1,"AKDT":1,"AKST":1,"AMST":1,"AMT":1,"ART":1,"AST":1,"AWDT":1,"AWST":1,"AZOST":1,"AZT":1,"BDT":1,"BIOT":1,"BIT":1,"BOT":1,"BRT":1,"BST":1,"BTT":1,"CAT":1,"CCT":1,"CDT":1,"CEDT":1,"CEST":1,"CET":1,"CHADT":1,"CHAST":1,"CHOT":1,"ChST":1,"CHUT":1,"CIST":1,"CIT":1,"CKT":1,"CLST":1,"CLT":1,"COST":1,"COT":1,"CST":1,"CT":1,"CVT":1,"CWST":1,"CXT":1,"DAVT":1,"DDUT":1,"DFT":1,"EASST":1,"EAST":1,"EAT":1,"ECT":1,"EDT":1,"EEDT":1,"EEST":1,"EET":1,"EGST":1,"EGT":1,"EIT":1,"EST":1,"FET":1,"FJT":1,"FKST":1,"FKT":1,"FNT":1,"GALT":1,"GAMT":1,"GET":1,"GFT":1,"GILT":1,"GIT":1,"GMT":1,"GST":1,"GYT":1,"HADT":1,"HAEC":1,"HAST":1,"HKT":1,"HMT":1,"HOVT":1,"HST":1,"ICT":1,"IDT":1,"IOT":1,"IRDT":1,"IRKT":1,"IRST":1,"IST":1,"JST":1,"KGT":1,"KOST":1,"KRAT":1,"KST":1,"LHST":1,"LINT":1,"MAGT":1,"MART":1,"MAWT":1,"MDT":1,"MET":1,"MEST":1,"MHT":1,"MIST":1,"MIT":1,"MMT":1,"MSK":1,"MST":1,"MUT":1,"MVT":1,"MYT":1,"NCT":1,"NDT":1,"NFT":1,"NPT":1,"NST":1,"NT":1,"NUT":1,"NZDT":1,"NZST":1,"OMST":1,"ORAT":1,"PDT":1,"PET":1,"PETT":1,"PGT":1,"PHOT":1,"PHT":1,"PKT":1,"PMDT":1,"PMST":1,"PONT":1,"PST":1,"PYST":1,"PYT":1,"RET":1,"ROTT":1,"SAKT":1,"SAMT":1,"SAST":1,"SBT":1,"SCT":1,"SGT":1,"SLST":1,"SRT":1,"SST":1,"SYOT":1,"TAHT":1,"THA":1,"TFT":1,"TJT":1,"TKT":1,"TLT":1,"TMT":1,"TOT":1,"TVT":1,"UCT":1,"ULAT":1,"UTC":1,"UYST":1,"UYT":1,"UZT":1,"VET":1,"VLAT":1,"VOLT":1,"VOST":1,"VUT":1,"WAKT":1,"WAST":1,"WAT":1,"WEDT":1,"WEST":1,"WET":1,"WST":1,"YAKT":1,"YEKT":1,"Z":1};
return (timezones[value] === 1);
};
$D.validateTimezoneOffset= function(value) {
// timezones go from +14hrs to -12hrs, the +X hours are negative offsets.
return (value > -841 && value < 721);
};
}());
(function () {
var $D = Date,
$P = $D.prototype,
p = function (s, l) {
if (!l) {
l = 2;
}
return ("000" + s).slice(l * -1);
};
var validateConfigObject = function (obj) {
var result = {}, self = this, prop, testFunc;
testFunc = function (prop, func, value) {
if (prop === "day") {
var month = (obj.month !== undefined) ? obj.month : self.getMonth();
var year = (obj.year !== undefined) ? obj.year : self.getFullYear();
return $D[func](value, year, month);
} else {
return $D[func](value);
}
};
for (prop in obj) {
if (hasOwnProperty.call(obj, prop)) {
var func = "validate" + prop.charAt(0).toUpperCase() + prop.slice(1);
if ($D[func] && obj[prop] !== null && testFunc(prop, func, obj[prop])) {
result[prop] = obj[prop];
}
}
}
return result;
};
/**
* Resets the time of this Date object to 12:00 AM (00:00), which is the start of the day.
* @param {Boolean} .clone() this date instance before clearing Time
* @return {Date} this
*/
$P.clearTime = function () {
this.setHours(0);
this.setMinutes(0);
this.setSeconds(0);
this.setMilliseconds(0);
return this;
};
/**
* Resets the time of this Date object to the current time ('now').
* @return {Date} this
*/
$P.setTimeToNow = function () {
var n = new Date();
this.setHours(n.getHours());
this.setMinutes(n.getMinutes());
this.setSeconds(n.getSeconds());
this.setMilliseconds(n.getMilliseconds());
return this;
};
/**
* Returns a new Date object that is an exact date and time copy of the original instance.
* @return {Date} A new Date instance
*/
$P.clone = function () {
return new Date(this.getTime());
};
/**
* Compares this instance to a Date object and returns an number indication of their relative values.
* @param {Date} Date object to compare [Required]
* @return {Number} -1 = this is lessthan date. 0 = values are equal. 1 = this is greaterthan date.
*/
$P.compareTo = function (date) {
return Date.compare(this, date);
};
/**
* Compares this instance to another Date object and returns true if they are equal.
* @param {Date} Date object to compare. If no date to compare, new Date() [now] is used.
* @return {Boolean} true if dates are equal. false if they are not equal.
*/
$P.equals = function (date) {
return Date.equals(this, (date !== undefined ? date : new Date()));
};
/**
* Determines if this instance is between a range of two dates or equal to either the start or end dates.
* @param {Date} Start of range [Required]
* @param {Date} End of range [Required]
* @return {Boolean} true is this is between or equal to the start and end dates, else false
*/
$P.between = function (start, end) {
return this.getTime() >= start.getTime() && this.getTime() <= end.getTime();
};
/**
* Determines if this date occurs after the date to compare to.
* @param {Date} Date object to compare. If no date to compare, new Date() ("now") is used.
* @return {Boolean} true if this date instance is greater than the date to compare to (or "now"), otherwise false.
*/
$P.isAfter = function (date) {
return this.compareTo(date || new Date()) === 1;
};
/**
* Determines if this date occurs before the date to compare to.
* @param {Date} Date object to compare. If no date to compare, new Date() ("now") is used.
* @return {Boolean} true if this date instance is less than the date to compare to (or "now").
*/
$P.isBefore = function (date) {
return (this.compareTo(date || new Date()) === -1);
};
/**
* Determines if the current Date instance occurs today.
* @return {Boolean} true if this date instance is 'today', otherwise false.
*/
/**
* Determines if the current Date instance occurs on the same Date as the supplied 'date'.
* If no 'date' to compare to is provided, the current Date instance is compared to 'today'.
* @param {date} Date object to compare. If no date to compare, the current Date ("now") is used.
* @return {Boolean} true if this Date instance occurs on the same Day as the supplied 'date'.
*/
$P.isToday = $P.isSameDay = function (date) {
return this.clone().clearTime().equals((date || new Date()).clone().clearTime());
};
/**
* Adds the specified number of milliseconds to this instance.
* @param {Number} The number of milliseconds to add. The number can be positive or negative [Required]
* @return {Date} this
*/
$P.addMilliseconds = function (value) {
if (!value) { return this; }
this.setTime(this.getTime() + value * 1);
return this;
};
/**
* Adds the specified number of seconds to this instance.
* @param {Number} The number of seconds to add. The number can be positive or negative [Required]
* @return {Date} this
*/
$P.addSeconds = function (value) {
if (!value) { return this; }
return this.addMilliseconds(value * 1000);
};
/**
* Adds the specified number of seconds to this instance.
* @param {Number} The number of seconds to add. The number can be positive or negative [Required]
* @return {Date} this
*/
$P.addMinutes = function (value) {
if (!value) { return this; }
return this.addMilliseconds(value * 60000); // 60*1000
};
/**
* Adds the specified number of hours to this instance.
* @param {Number} The number of hours to add. The number can be positive or negative [Required]
* @return {Date} this
*/
$P.addHours = function (value) {
if (!value) { return this; }
return this.addMilliseconds(value * 3600000); // 60*60*1000
};
/**
* Adds the specified number of days to this instance.
* @param {Number} The number of days to add. The number can be positive or negative [Required]
* @return {Date} this
*/
$P.addDays = function (value) {
if (!value) { return this; }
this.setDate(this.getDate() + value * 1);
return this;
};
/**
* Adds the specified number of weekdays (ie - not sat or sun) to this instance.
* @param {Number} The number of days to add. The number can be positive or negative [Required]
* @return {Date} this
*/
$P.addWeekdays = function (value) {
if (!value) { return this; }
var day = this.getDay();
var weeks = (Math.ceil(Math.abs(value)/7));
if (day === 0 || day === 6) {
if (value > 0) {
this.next().monday();
this.addDays(-1);
day = this.getDay();
}
}
if (value < 0) {
while (value < 0) {
this.addDays(-1);
day = this.getDay();
if (day !== 0 && day !== 6) {
value++;
}
}
return this;
} else if (value > 5 || (6-day) <= value) {
value = value + (weeks * 2);
}
return this.addDays(value);
};
/**
* Adds the specified number of weeks to this instance.
* @param {Number} The number of weeks to add. The number can be positive or negative [Required]
* @return {Date} this
*/
$P.addWeeks = function (value) {
if (!value) { return this; }
return this.addDays(value * 7);
};
/**
* Adds the specified number of months to this instance.
* @param {Number} The number of months to add. The number can be positive or negative [Required]
* @return {Date} this
*/
$P.addMonths = function (value) {
if (!value) { return this; }
var n = this.getDate();
this.setDate(1);
this.setMonth(this.getMonth() + value * 1);
this.setDate(Math.min(n, $D.getDaysInMonth(this.getFullYear(), this.getMonth())));
return this;
};
$P.addQuarters = function (value) {
if (!value) { return this; }
// note this will take you to the same point in the quarter as you are now.
// i.e. - if you are 15 days into the quarter you'll be 15 days into the resulting one.
// bonus: this allows adding fractional quarters
return this.addMonths(value * 3);
};
/**
* Adds the specified number of years to this instance.
* @param {Number} The number of years to add. The number can be positive or negative [Required]
* @return {Date} this
*/
$P.addYears = function (value) {
if (!value) { return this; }
return this.addMonths(value * 12);
};
/**
* Adds (or subtracts) to the value of the years, months, weeks, days, hours, minutes, seconds, milliseconds of the date instance using given configuration object. Positive and Negative values allowed.
* Example
<pre><code>
Date.today().add( { days: 1, months: 1 } )
new Date().add( { years: -1 } )
</code></pre>
* @param {Object} Configuration object containing attributes (months, days, etc.)
* @return {Date} this
*/
$P.add = function (config) {
if (typeof config === "number") {
this._orient = config;
return this;
}
var x = config;
if (x.day) {
// If we should be a different date than today (eg: for 'tomorrow -1d', etc).
// Should only effect parsing, not direct usage (eg, Finish and FinishExact)
if ((x.day - this.getDate()) !== 0) {
this.setDate(x.day);
}
}
if (x.milliseconds) {
this.addMilliseconds(x.milliseconds);
}
if (x.seconds) {
this.addSeconds(x.seconds);
}
if (x.minutes) {
this.addMinutes(x.minutes);
}
if (x.hours) {
this.addHours(x.hours);
}
if (x.weeks) {
this.addWeeks(x.weeks);
}
if (x.months) {
this.addMonths(x.months);
}
if (x.years) {
this.addYears(x.years);
}
if (x.days) {
this.addDays(x.days);
}
return this;
};
/**
* Get the week number. Week one (1) is the week which contains the first Thursday of the year. Monday is considered the first day of the week.
* The .getWeek() function does NOT convert the date to UTC. The local datetime is used.
* Please use .getISOWeek() to get the week of the UTC converted date.
* @return {Number} 1 to 53
*/
$P.getWeek = function (utc) {
// Create a copy of this date object
var self, target = new Date(this.valueOf());
if (utc) {
target.addMinutes(target.getTimezoneOffset());
self = target.clone();
} else {
self = this;
}
// ISO week date weeks start on monday
// so correct the day number
var dayNr = (self.getDay() + 6) % 7;
// ISO 8601 states that week 1 is the week
// with the first thursday of that year.
// Set the target date to the thursday in the target week
target.setDate(target.getDate() - dayNr + 3);
// Store the millisecond value of the target date
var firstThursday = target.valueOf();
// Set the target to the first thursday of the year
// First set the target to january first
target.setMonth(0, 1);
// Not a thursday? Correct the date to the next thursday
if (target.getDay() !== 4) {
target.setMonth(0, 1 + ((4 - target.getDay()) + 7) % 7);
}
// The weeknumber is the number of weeks between the
// first thursday of the year and the thursday in the target week
return 1 + Math.ceil((firstThursday - target) / 604800000); // 604800000 = 7 * 24 * 3600 * 1000
};
/**
* Get the ISO 8601 week number. Week one ("01") is the week which contains the first Thursday of the year. Monday is considered the first day of the week.
* The .getISOWeek() function does convert the date to it's UTC value. Please use .getWeek() to get the week of the local date.
* @return {String} "01" to "53"
*/
$P.getISOWeek = function () {
return p(this.getWeek(true));
};
/**
* Moves the date to Monday of the week set. Week one (1) is the week which contains the first Thursday of the year.
* @param {Number} A Number (1 to 53) that represents the week of the year.
* @return {Date} this
*/
$P.setWeek = function (n) {
if ((n - this.getWeek()) === 0) {
if (this.getDay() !== 1) {
return this.moveToDayOfWeek(1, (this.getDay() > 1 ? -1 : 1));
} else {
return this;
}
} else {
return this.moveToDayOfWeek(1, (this.getDay() > 1 ? -1 : 1)).addWeeks(n - this.getWeek());
}
};
$P.setQuarter = function (qtr) {
var month = Math.abs(((qtr-1) * 3) + 1);
return this.setMonth(month, 1);
};
$P.getQuarter = function () {
return Date.getQuarter(this);
};
$P.getDaysLeftInQuarter = function () {
return Date.getDaysLeftInQuarter(this);
};
/**
* Moves the date to the next n'th occurrence of the dayOfWeek starting from the beginning of the month. The number (-1) is a magic number and will return the last occurrence of the dayOfWeek in the month.
* @param {Number} The dayOfWeek to move to
* @param {Number} The n'th occurrence to move to. Use (-1) to return the last occurrence in the month
* @return {Date} this
*/
$P.moveToNthOccurrence = function (dayOfWeek, occurrence) {
if (dayOfWeek === "Weekday") {
if (occurrence > 0) {
this.moveToFirstDayOfMonth();
if (this.is().weekday()) {
occurrence -= 1;
}
} else if (occurrence < 0) {
this.moveToLastDayOfMonth();
if (this.is().weekday()) {
occurrence += 1;
}
} else {
return this;
}
return this.addWeekdays(occurrence);
}
var shift = 0;
if (occurrence > 0) {
shift = occurrence - 1;
}
else if (occurrence === -1) {
this.moveToLastDayOfMonth();
if (this.getDay() !== dayOfWeek) {
this.moveToDayOfWeek(dayOfWeek, -1);
}
return this;
}
return this.moveToFirstDayOfMonth().addDays(-1).moveToDayOfWeek(dayOfWeek, +1).addWeeks(shift);
};
var moveToN = function (getFunc, addFunc, nVal) {
return function (value, orient) {
var diff = (value - this[getFunc]() + nVal * (orient || +1)) % nVal;
return this[addFunc]((diff === 0) ? diff += nVal * (orient || +1) : diff);
};
};
/**
* Move to the next or last dayOfWeek based on the orient value.
* @param {Number} The dayOfWeek to move to
* @param {Number} Forward (+1) or Back (-1). Defaults to +1. [Optional]
* @return {Date} this
*/
$P.moveToDayOfWeek = moveToN("getDay", "addDays", 7);
/**
* Move to the next or last month based on the orient value.
* @param {Number} The month to move to. 0 = January, 11 = December
* @param {Number} Forward (+1) or Back (-1). Defaults to +1. [Optional]
* @return {Date} this
*/
$P.moveToMonth = moveToN("getMonth", "addMonths", 12);
/**
* Get the Ordinate of the current day ("th", "st", "rd").
* @return {String}
*/
$P.getOrdinate = function () {
var num = this.getDate();
return ord(num);
};
/**
* Get the Ordinal day (numeric day number) of the year, adjusted for leap year.
* @return {Number} 1 through 365 (366 in leap years)
*/
$P.getOrdinalNumber = function () {
return Math.ceil((this.clone().clearTime() - new Date(this.getFullYear(), 0, 1)) / 86400000) + 1;
};
/**
* Get the time zone abbreviation of the current date.
* @return {String} The abbreviated time zone name (e.g. "EST")
*/
$P.getTimezone = function () {
return $D.getTimezoneAbbreviation(this.getUTCOffset(), this.isDaylightSavingTime());
};
$P.setTimezoneOffset = function (offset) {
var here = this.getTimezoneOffset(), there = Number(offset) * -6 / 10;
return (there || there === 0) ? this.addMinutes(there - here) : this;
};
$P.setTimezone = function (offset) {
return this.setTimezoneOffset($D.getTimezoneOffset(offset));
};
/**
* Indicates whether Daylight Saving Time is observed in the current time zone.
* @return {Boolean} true|false
*/
$P.hasDaylightSavingTime = function () {
return (Date.today().set({month: 0, day: 1}).getTimezoneOffset() !== Date.today().set({month: 6, day: 1}).getTimezoneOffset());
};
/**
* Indicates whether this Date instance is within the Daylight Saving Time range for the current time zone.
* @return {Boolean} true|false
*/
$P.isDaylightSavingTime = function () {
return Date.today().set({month: 0, day: 1}).getTimezoneOffset() !== this.getTimezoneOffset();
};
/**
* Get the offset from UTC of the current date.
* @return {String} The 4-character offset string prefixed with + or - (e.g. "-0500")
*/
$P.getUTCOffset = function (offset) {
var n = (offset || this.getTimezoneOffset()) * -10 / 6, r;
if (n < 0) {
r = (n - 10000).toString();
return r.charAt(0) + r.substr(2);
} else {
r = (n + 10000).toString();
return "+" + r.substr(1);
}
};
/**
* Returns the number of milliseconds between this date and date.
* @param {Date} Defaults to now
* @return {Number} The diff in milliseconds
*/
$P.getElapsed = function (date) {
return (date || new Date()) - this;
};
/**
* Set the value of year, month, day, hour, minute, second, millisecond of date instance using given configuration object.
* Example
<pre><code>
Date.today().set( { day: 20, month: 1 } )
new Date().set( { millisecond: 0 } )
</code></pre>
*
* @param {Object} Configuration object containing attributes (month, day, etc.)
* @return {Date} this
*/
$P.set = function (config) {
config = validateConfigObject.call(this, config);
var key;
for (key in config) {
if (hasOwnProperty.call(config, key)) {
var name = key.charAt(0).toUpperCase() + key.slice(1);
var addFunc, getFunc;
if (key !== "week" && key !== "month" && key !== "timezone" && key !== "timezoneOffset") {
name += "s";
}
addFunc = "add" + name;
getFunc = "get" + name;
if (key === "month") {
addFunc = addFunc + "s";
} else if (key === "year"){
getFunc = "getFullYear";
}
if (key !== "day" && key !== "timezone" && key !== "timezoneOffset" && key !== "week" && key !== "hour") {
this[addFunc](config[key] - this[getFunc]());
} else if ( key === "timezone"|| key === "timezoneOffset" || key === "week" || key === "hour") {
this["set"+name](config[key]);
}
}
}
// day has to go last because you can't validate the day without first knowing the month
if (config.day) {
this.addDays(config.day - this.getDate());
}
return this;
};
/**
* Moves the date to the first day of the month.
* @return {Date} this
*/
$P.moveToFirstDayOfMonth = function () {
return this.set({ day: 1 });
};
/**
* Moves the date to the last day of the month.
* @return {Date} this
*/
$P.moveToLastDayOfMonth = function () {
return this.set({ day: $D.getDaysInMonth(this.getFullYear(), this.getMonth())});
};
/**
* Converts the value of the current Date object to its equivalent string representation.
* Format Specifiers
* CUSTOM DATE AND TIME FORMAT STRINGS
* Format Description Example
* ------ --------------------------------------------------------------------------- -----------------------
* s The seconds of the minute between 0-59. "0" to "59"
* ss The seconds of the minute with leading zero if required. "00" to "59"
*
* m The minute of the hour between 0-59. "0" or "59"
* mm The minute of the hour with leading zero if required. "00" or "59"
*
* h The hour of the day between 1-12. "1" to "12"
* hh The hour of the day with leading zero if required. "01" to "12"
*
* H The hour of the day between 0-23. "0" to "23"
* HH The hour of the day with leading zero if required. "00" to "23"
*
* d The day of the month between 1 and 31. "1" to "31"
* dd The day of the month with leading zero if required. "01" to "31"
* ddd Abbreviated day name. Date.CultureInfo.abbreviatedDayNames. "Mon" to "Sun"
* dddd The full day name. Date.CultureInfo.dayNames. "Monday" to "Sunday"
*
* M The month of the year between 1-12. "1" to "12"
* MM The month of the year with leading zero if required. "01" to "12"
* MMM Abbreviated month name. Date.CultureInfo.abbreviatedMonth