date-parser.min.js 5.3 KB

12345678910
  1. /**
  2. * angular-strap
  3. * @version v2.3.9 - 2016-06-10
  4. * @link http://mgcrea.github.io/angular-strap
  5. * @author Olivier Louvignes <olivier@mg-crea.com> (https://github.com/mgcrea)
  6. * @license MIT License, http://www.opensource.org/licenses/MIT
  7. */
  8. 'use strict';angular.module('mgcrea.ngStrap.helpers.dateParser',[]).provider('$dateParser',['$localeProvider',function(t){function e(){this.year=1970,this.month=0,this.day=1,this.hours=0,this.minutes=0,this.seconds=0,this.milliseconds=0}function n(){}function r(t){return!isNaN(parseFloat(t))&&isFinite(t)}function s(t,e){for(var n=t.length,r=e.toString().toLowerCase(),s=0;n>s;s++)if(t[s].toLowerCase()===r)return s;return-1}e.prototype.setMilliseconds=function(t){this.milliseconds=t},e.prototype.setSeconds=function(t){this.seconds=t},e.prototype.setMinutes=function(t){this.minutes=t},e.prototype.setHours=function(t){this.hours=t},e.prototype.getHours=function(){return this.hours},e.prototype.setDate=function(t){this.day=t},e.prototype.setMonth=function(t){this.month=t},e.prototype.setFullYear=function(t){this.year=t},e.prototype.fromDate=function(t){return this.year=t.getFullYear(),this.month=t.getMonth(),this.day=t.getDate(),this.hours=t.getHours(),this.minutes=t.getMinutes(),this.seconds=t.getSeconds(),this.milliseconds=t.getMilliseconds(),this},e.prototype.toDate=function(){return new Date(this.year,this.month,this.day,this.hours,this.minutes,this.seconds,this.milliseconds)};var i=e.prototype,o=this.defaults={format:'shortDate',strict:!1};this.$get=['$locale','dateFilter',function(t,a){var u=function(u){function c(t){var e=l(t);return M(e)}function l(t){var e=h(t),n=e.replace(/''/g,'\\\''),r=/('(?:\\'|.)*?')/,s=n.split(r),i=Object.keys(E),o=[];return angular.forEach(s,function(t){if(f(t))t=g(t);else for(var e=0;e<i.length;e++)t=t.split(i[e]).join('${'+e+'}');o.push(t)}),o.join('')}function h(t){return t.replace(/\\/g,'[\\\\]').replace(/-/g,'[-]').replace(/\./g,'[.]').replace(/\*/g,'[*]').replace(/\+/g,'[+]').replace(/\?/g,'[?]').replace(/\$/g,'[$]').replace(/\^/g,'[^]').replace(/\//g,'[/]').replace(/\\s/g,'[\\s]')}function f(t){return/^'.*'$/.test(t)}function g(t){return t.replace(/^'(.*)'$/,'$1')}function M(t){for(var e=Object.keys(E),n=t,r=0;r<e.length;r++)n=n.split('${'+r+'}').join('('+E[e[r]]+')');return new RegExp('^'+n+'$',['i'])}function p(t){var e=l(t);return m(e)}function m(t){for(var e,n,r,s,i=Object.keys(E),o=new RegExp('\\${(\\d+)}','g'),a=[];null!==(e=o.exec(t));)n=e[1],r=i[n],s=H[r],a.push(s);return a}var d,D,y=angular.extend({},o,u),T={},E={sss:'[0-9]{3}',ss:'[0-5][0-9]',s:y.strict?'[1-5]?[0-9]':'[0-9]|[0-5][0-9]',mm:'[0-5][0-9]',m:y.strict?'[1-5]?[0-9]':'[0-9]|[0-5][0-9]',HH:'[01][0-9]|2[0-3]',H:y.strict?'1?[0-9]|2[0-3]':'[01]?[0-9]|2[0-3]',hh:'[0][1-9]|[1][012]',h:y.strict?'[1-9]|1[012]':'0?[1-9]|1[012]',a:'AM|PM',EEEE:t.DATETIME_FORMATS.DAY.join('|'),EEE:t.DATETIME_FORMATS.SHORTDAY.join('|'),dd:'0[1-9]|[12][0-9]|3[01]',d:y.strict?'[1-9]|[1-2][0-9]|3[01]':'0?[1-9]|[1-2][0-9]|3[01]',MMMM:t.DATETIME_FORMATS.MONTH.join('|'),MMM:t.DATETIME_FORMATS.SHORTMONTH.join('|'),MM:'0[1-9]|1[012]',M:y.strict?'[1-9]|1[012]':'0?[1-9]|1[012]',yyyy:'[1]{1}[0-9]{3}|[2]{1}[0-9]{3}',yy:'[0-9]{2}',y:y.strict?'-?(0|[1-9][0-9]{0,3})':'-?0*[0-9]{1,4}'},H={sss:i.setMilliseconds,ss:i.setSeconds,s:i.setSeconds,mm:i.setMinutes,m:i.setMinutes,HH:i.setHours,H:i.setHours,hh:i.setHours,h:i.setHours,EEEE:n,EEE:n,dd:i.setDate,d:i.setDate,a:function(t){var e=this.getHours()%12;return this.setHours(t.match(/pm/i)?e+12:e)},MMMM:function(e){return this.setMonth(s(t.DATETIME_FORMATS.MONTH,e))},MMM:function(e){return this.setMonth(s(t.DATETIME_FORMATS.SHORTMONTH,e))},MM:function(t){return this.setMonth(1*t-1)},M:function(t){return this.setMonth(1*t-1)},yyyy:i.setFullYear,yy:function(t){return this.setFullYear(2e3+1*t)},y:function(t){return 50>=1*t&&2===t.length?this.setFullYear(2e3+1*t):this.setFullYear(1*t)}};return T.init=function(){T.$format=t.DATETIME_FORMATS[y.format]||y.format,d=c(T.$format),D=p(T.$format)},T.isValid=function(t){return angular.isDate(t)?!isNaN(t.getTime()):d.test(t)},T.parse=function(n,r,s,i){s&&(s=t.DATETIME_FORMATS[s]||s),angular.isDate(n)&&(n=a(n,s||T.$format,i));var o=s?c(s):d,u=s?p(s):D,l=o.exec(n);if(!l)return!1;for(var h=r&&!isNaN(r.getTime())?(new e).fromDate(r):(new e).fromDate(new Date(1970,0,1,0)),f=0;f<l.length-1;f++)u[f]&&u[f].call(h,l[f+1]);var g=h.toDate();return parseInt(h.day,10)!==g.getDate()?!1:g},T.getDateForAttribute=function(t,e){var n;if('today'===e){var s=new Date;n=new Date(s.getFullYear(),s.getMonth(),s.getDate()+('maxDate'===t?1:0),0,0,0,'minDate'===t?0:-1)}else n=angular.isString(e)&&e.match(/^".+"$/)?new Date(e.substr(1,e.length-2)):r(e)?new Date(parseInt(e,10)):angular.isString(e)&&0===e.length?'minDate'===t?-(1/0):+(1/0):new Date(e);return n},T.getTimeForAttribute=function(t,e){var n;return n='now'===e?(new Date).setFullYear(1970,0,1):angular.isString(e)&&e.match(/^".+"$/)?new Date(e.substr(1,e.length-2)).setFullYear(1970,0,1):r(e)?new Date(parseInt(e,10)).setFullYear(1970,0,1):angular.isString(e)&&0===e.length?'minTime'===t?-(1/0):+(1/0):T.parse(e,new Date(1970,0,1,0))},T.daylightSavingAdjust=function(t){return t?(t.setHours(t.getHours()>12?t.getHours()+2:0),t):null},T.timezoneOffsetAdjust=function(t,e,n){return t?(e&&'UTC'===e&&(t=new Date(t.getTime()),t.setMinutes(t.getMinutes()+(n?-1:1)*t.getTimezoneOffset())),t):null},T.init(),T};return u}]}]);
  9. //# sourceMappingURL=date-parser.min.js.map