/*! * inputmask.date.extensions.js * https://github.com/RobinHerbots/Inputmask * Copyright (c) 2010 - 2017 Robin Herbots * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php) * Version: 4.0.0-75 */ !function(factory) { "function" == typeof define && define.amd ? define([ "./dependencyLibs/inputmask.dependencyLib", "./inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("./dependencyLibs/inputmask.dependencyLib"), require("./inputmask")) : factory(window.dependencyLib || jQuery, window.Inputmask); }(function($, Inputmask) { function getTokenizer(opts) { if (!opts.tokenizer) { var tokens = []; for (var ndx in formatCode) -1 === tokens.indexOf(ndx[0]) && tokens.push(ndx[0]); opts.tokenizer = "(" + tokens.join("+|") + ")+?|.", opts.tokenizer = new RegExp(opts.tokenizer, "g"); } return opts.tokenizer; } function isValidDate(dateParts, currentResult) { return (!isFinite(dateParts.day) || "29" == dateParts.day && !isFinite(dateParts.rawyear) || new Date(dateParts.date.getFullYear(), isFinite(dateParts.month) ? dateParts.month : dateParts.date.getMonth() + 1, 0).getDate() >= dateParts.day) && currentResult; } function isDateInRange(maskDate, opts) { var result = !0; return opts.min && opts.min.date.getTime() === opts.min.date.getTime() && (result = result && opts.min.date.getTime() <= maskDate.getTime()), opts.max && opts.max.date.getTime() === opts.max.date.getTime() && (result = result && opts.max.date.getTime() >= maskDate.getTime()), result; } function parse(format, dateObjValue, opts) { for (var match, mask = ""; match = getTokenizer(opts).exec(format); ) void 0 === dateObjValue ? mask += formatCode[match[0]] ? "(" + formatCode[match[0]][0] + ")" : match[0] : formatCode[match[0]] ? mask += formatCode[match[0]][3].call(dateObjValue.date) : mask += match[0]; return mask; } function pad(val, len) { for (val = String(val), len = len || 2; val.length < len; ) val = "0" + val; return val; } function analyseMask(maskString, format, opts) { function extendYear(year) { var correctedyear = 4 === year.length ? year : new Date().getFullYear().toString().substr(0, 4 - year.length) + year; return opts.min && opts.min.year && opts.max && opts.max.year ? (correctedyear = correctedyear.replace(/[^0-9]/g, ""), correctedyear = year.charAt(0) === opts.max.year.charAt(0) ? year.replace(/[^0-9]/g, "0") : correctedyear + opts.min.year.substr(correctedyear.length)) : correctedyear = correctedyear.replace(/[^0-9]/g, "0"), correctedyear; } var targetProp, match, dateOperation, dateObj = { date: new Date(1, 0, 1) }, mask = maskString; if ("string" == typeof mask) { for (;match = getTokenizer(opts).exec(format); ) { var value = mask.slice(0, match[0].length); formatCode.hasOwnProperty(match[0]) && (targetProp = formatCode[match[0]][2], dateOperation = formatCode[match[0]][1], function(dateObj, value, opts) { "year" === targetProp ? (dateObj[targetProp] = extendYear(value), dateObj["raw" + targetProp] = value) : dateObj[targetProp] = opts.min && value.match(/[^0-9]/) ? opts.min[targetProp] : value, void 0 !== dateOperation && dateOperation.call(dateObj.date, "month" == targetProp ? parseInt(dateObj[targetProp]) - 1 : dateObj[targetProp]); }(dateObj, value, opts)), mask = mask.slice(value.length); } return dateObj; } } var formatCode = { d: [ "[1-9]|[12][0-9]|3[01]", Date.prototype.setDate, "day", Date.prototype.getDate ], dd: [ "0[1-9]|[12][0-9]|3[01]", Date.prototype.setDate, "day", function() { return pad(Date.prototype.getDate.call(this), 2); } ], ddd: [ "" ], dddd: [ "" ], m: [ "[1-9]|1[012]", Date.prototype.setMonth, "month", function() { return Date.prototype.getMonth.call(this) + 1; } ], mm: [ "0[1-9]|1[012]", Date.prototype.setMonth, "month", function() { return pad(Date.prototype.getMonth.call(this) + 1, 2); } ], mmm: [ "" ], mmmm: [ "" ], yy: [ "[0-9]{2}", Date.prototype.setFullYear, "year", function() { return pad(Date.prototype.getFullYear.call(this), 2); } ], yyyy: [ "[0-9]{4}", Date.prototype.setFullYear, "year", function() { return pad(Date.prototype.getFullYear.call(this), 4); } ], h: [ "[1-9]|1[0-2]", Date.prototype.setHours, "hours", Date.prototype.getHours ], hh: [ "0[1-9]|1[0-2]", Date.prototype.setHours, "hours", function() { return pad(Date.prototype.getHours.call(this), 2); } ], hhh: [ "[0-9]+", Date.prototype.setHours, "hours", Date.prototype.getHours ], H: [ "1?[1-9]|2[0-3]", Date.prototype.setHours, "hours", Date.prototype.getHours ], HH: [ "[01][1-9]|2[0-3]", Date.prototype.setHours, "hours", function() { return pad(Date.prototype.getHours.call(this), 2); } ], HHH: [ "[0-9]+", Date.prototype.setHours, "hours", Date.prototype.getHours ], M: [ "[1-5]?[0-9]", Date.prototype.setMinutes, "minutes", Date.prototype.getMinutes ], MM: [ "[0-5][0-9]", Date.prototype.setMinutes, "minutes", function() { return pad(Date.prototype.getMinutes.call(this), 2); } ], s: [ "[1-5]?[0-9]", Date.prototype.setSeconds, "seconds", Date.prototype.getSeconds ], ss: [ "[0-5][0-9]", Date.prototype.setSeconds, "seconds", function() { return pad(Date.prototype.getSeconds.call(this), 2); } ], l: [ "[0-9]{3}", Date.prototype.setMilliseconds, "milliseconds", function() { return pad(Date.prototype.getMilliseconds.call(this), 3); } ], L: [ "[0-9]{2}", Date.prototype.setMilliseconds, "milliseconds", function() { return pad(Date.prototype.getMilliseconds.call(this), 2); } ], t: [ "" ], tt: [ "" ], T: [ "" ], TT: [ "" ], Z: [ "" ], o: [ "" ], S: [ "" ] }, formatAlias = { isoDate: "yyyy-mm-dd", isoTime: "HH:MM:ss", isoDateTime: "yyyy-mm-dd'T'HH:MM:ss", isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'" }; return Inputmask.extendAliases({ datetime: { mask: function(opts) { return opts.inputFormat = formatAlias[opts.inputFormat] || opts.inputFormat, opts.displayFormat = formatAlias[opts.displayFormat] || opts.displayFormat || opts.inputFormat, opts.outputFormat = formatAlias[opts.outputFormat] || opts.outputFormat || opts.inputFormat, opts.placeholder = opts.placeholder !== Inputmask.prototype.defaults.placeholder ? opts.placeholder : opts.inputFormat, opts.min = analyseMask(opts.min, opts.inputFormat, opts), opts.max = analyseMask(opts.max, opts.inputFormat, opts), opts.regex = parse(opts.inputFormat, void 0, opts), null; }, inputFormat: "isoDateTime", displayFormat: void 0, outputFormat: void 0, min: null, max: null, i18n: { dayNames: [ "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ], monthNames: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ] }, postValidation: function(buffer, currentResult, opts) { var result = currentResult, dateParts = analyseMask(buffer.join(""), opts.inputFormat, opts); return result && dateParts.date.getTime() === dateParts.date.getTime() && (result = (result = isValidDate(dateParts, result)) && isDateInRange(dateParts.date, opts)), result; }, onKeyDown: function(e, buffer, caretPos, opts) { var input = this; if (e.ctrlKey && e.keyCode === Inputmask.keyCode.RIGHT) { for (var match, today = new Date(), date = ""; match = getTokenizer(opts).exec(opts.inputFormat); ) "d" === match[0].charAt(0) ? date += today.getDate().toString() : "m" === match[0].charAt(0) ? date += (today.getMonth() + 1).toString() : "yyyy" === match[0] ? date += today.getFullYear().toString() : "yy" === match[0] && (date += today.getYear().toString()); input.inputmask._valueSet(date), $(input).trigger("setvalue"); } }, onUnMask: function(maskedValue, unmaskedValue, opts) { return parse(opts.outputFormat, analyseMask(maskedValue, opts.inputFormat, opts), opts); }, insertMode: !1 } }), Inputmask; });