inputmask.date.extensions.min.js 5.8 KB

123456789
  1. /*!
  2. * inputmask.date.extensions.min.js
  3. * https://github.com/RobinHerbots/Inputmask
  4. * Copyright (c) 2010 - 2018 Robin Herbots
  5. * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  6. * Version: 4.0.1-beta.37
  7. */
  8. !function(t){"function"==typeof define&&define.amd?define(["./inputmask"],t):"object"==typeof exports?module.exports=t(require("./inputmask")):t(window.Inputmask)}(function(s){var u=s.dependencyLib,l={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 m(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 m(Date.prototype.getMonth.call(this)+1,2)}],mmm:[""],mmmm:[""],yy:["[0-9]{2}",Date.prototype.setFullYear,"year",function(){return m(Date.prototype.getFullYear.call(this),2)}],yyyy:["[0-9]{4}",Date.prototype.setFullYear,"year",function(){return m(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 m(Date.prototype.getHours.call(this),2)}],hhh:["[0-9]+",Date.prototype.setHours,"hours",Date.prototype.getHours],H:["1?[0-9]|2[0-3]",Date.prototype.setHours,"hours",Date.prototype.getHours],HH:["[01][0-9]|2[0-3]",Date.prototype.setHours,"hours",function(){return m(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 m(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 m(Date.prototype.getSeconds.call(this),2)}],l:["[0-9]{3}",Date.prototype.setMilliseconds,"milliseconds",function(){return m(Date.prototype.getMilliseconds.call(this),3)}],L:["[0-9]{2}",Date.prototype.setMilliseconds,"milliseconds",function(){return m(Date.prototype.getMilliseconds.call(this),2)}],t:["[ap]"],tt:["[ap]m"],T:["[AP]"],TT:["[AP]M"],Z:[""],o:[""],S:[""]},e={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'"};function y(t){if(!t.tokenizer){var e=[];for(var o in l)-1===e.indexOf(o[0])&&e.push(o[0]);t.tokenizer="("+e.join("+|")+")+?|.",t.tokenizer=new RegExp(t.tokenizer,"g")}return t.tokenizer}function p(t,e,o,r){for(var a,n="";a=y(o).exec(t);){if(void 0===e)if(l[a[0]])n+="("+l[a[0]][0]+")";else switch(a[0]){case"[":n+="(";break;case"]":n+=")?";break;default:n+=s.escapeRegex(a[0])}else if(l[a[0]])if(!0!==r&&l[a[0]][3])n+=l[a[0]][3].call(e.date);else l[a[0]][2]?n+=e["raw"+l[a[0]][2]]:n+=a[0];else n+=a[0]}return n}function m(t,e){for(t=String(t),e=e||2;t.length<e;)t="0"+t;return t}function d(t,e,a){var n,o,r,i,s={date:new Date(1,0,1)},u=t;function p(t,e,o){t[n]=function(t){var e;if(a.min&&a.min[n]||a.max&&a.max[n]){var o=a.min&&a.min[n]||a.max[n],r=a.max&&a.max[n]||a.min[n];for(e=t.replace(/[^0-9]/g,""),e+=(o.indexOf(e)<r.indexOf(e)?r:o).toString().substr(e.length);!new RegExp(i).test(e);)e--}else e=t.replace(/[^0-9]/g,"0");return e}(e),t["raw"+n]=e,void 0!==r&&r.call(t.date,"month"==n?parseInt(t[n])-1:t[n])}if("string"==typeof u){for(;o=y(a).exec(e);){var m=u.slice(0,o[0].length);l.hasOwnProperty(o[0])&&(i=l[o[0]][0],n=l[o[0]][2],r=l[o[0]][1],p(s,m)),u=u.slice(m.length)}return s}if(u&&"object"==typeof u&&u.hasOwnProperty("date"))return u}return s.extendAliases({datetime:{mask:function(t){return l.S=t.i18n.ordinalSuffix.join("|"),t.inputFormat=e[t.inputFormat]||t.inputFormat,t.displayFormat=e[t.displayFormat]||t.displayFormat||t.inputFormat,t.outputFormat=e[t.outputFormat]||t.outputFormat||t.inputFormat,t.placeholder=""!==t.placeholder?t.placeholder:t.inputFormat.replace(/[\[\]]/,""),t.regex=p(t.inputFormat,void 0,t),null},placeholder:"",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"],ordinalSuffix:["st","nd","rd","th"]},postValidation:function(t,e,o,r){r.min=d(r.min,r.inputFormat,r),r.max=d(r.max,r.inputFormat,r);var a,n,i=o,s=d(t.join(""),r.inputFormat,r);return i&&s.date.getTime()==s.date.getTime()&&(a=s,n=i,i=(i=(!isFinite(a.rawday)||"29"==a.day&&!isFinite(a.rawyear)||new Date(a.date.getFullYear(),isFinite(a.rawmonth)?a.month:a.date.getMonth()+1,0).getDate()>=a.day)&&n)&&function(t,e){var o=!0;if(e.min){if(t.rawyear){var r=t.rawyear.replace(/[^0-9]/g,"");o=e.min.year.substr(0,r.length)<=r}t.year===t.rawyear&&e.min.date.getTime()==e.min.date.getTime()&&(o=e.min.date.getTime()<=t.date.getTime())}return o&&e.max&&e.max.date.getTime()==e.max.date.getTime()&&(o=e.max.date.getTime()>=t.date.getTime()),o}(s,r)),e&&i&&o.pos!==e?{buffer:p(r.inputFormat,s,r),refreshFromBuffer:{start:e,end:o.pos}}:i},onKeyDown:function(t,e,o,r){if(t.ctrlKey&&t.keyCode===s.keyCode.RIGHT){for(var a,n=new Date,i="";a=y(r).exec(r.inputFormat);)"d"===a[0].charAt(0)?i+=m(n.getDate(),a[0].length):"m"===a[0].charAt(0)?i+=m(n.getMonth()+1,a[0].length):"yyyy"===a[0]?i+=n.getFullYear().toString():"y"===a[0].charAt(0)&&(i+=m(n.getYear(),a[0].length));this.inputmask._valueSet(i),u(this).trigger("setvalue")}},onUnMask:function(t,e,o){return p(o.outputFormat,d(t,o.inputFormat,o),o,!0)},casing:function(t,e,o,r){return 0==e.nativeDef.indexOf("[ap]")?t.toLowerCase():0==e.nativeDef.indexOf("[AP]")?t.toUpperCase():t},insertMode:!1}}),s});