Files

9 lines
2.7 KiB
JavaScript

/**
* angular-strap
* @version v2.0.4 - 2014-07-24
* @link http://mgcrea.github.io/angular-strap
* @author Olivier Louvignes (olivier@mg-crea.com)
* @license MIT License, http://www.opensource.org/licenses/MIT
*/
"use strict";angular.module("mgcrea.ngStrap.helpers.dateParser",[]).provider("$dateParser",["$localeProvider",function(){var t=Date.prototype,e=this.defaults={format:"shortDate",strict:!1};this.$get=["$locale","dateFilter",function(r,s){var n=function(n){function i(t){var e,r=Object.keys(h),s=[],n=[],i=t;for(e=0;e<r.length;e++)if(t.split(r[e]).length>1){var a=i.search(r[e]);t=t.split(r[e]).join(""),h[r[e]]&&(s[a]=h[r[e]])}return angular.forEach(s,function(t){n.push(t)}),n}function a(t){return t.replace(/\//g,"[\\/]").replace("/-/g","[-]").replace(/\./g,"[.]").replace(/\\s/g,"[\\s]")}function o(t){var e,r=Object.keys(f),s=t;for(e=0;e<r.length;e++)s=s.split(r[e]).join("${"+e+"}");for(e=0;e<r.length;e++)s=s.split("${"+e+"}").join("("+f[r[e]]+")");return t=a(t),new RegExp("^"+s+"$",["i"])}var u,M,c=angular.extend({},e,n),l={},f={sss:"[0-9]{3}",ss:"[0-5][0-9]",s:c.strict?"[1-5]?[0-9]":"[0-9]|[0-5][0-9]",mm:"[0-5][0-9]",m:c.strict?"[1-5]?[0-9]":"[0-9]|[0-5][0-9]",HH:"[01][0-9]|2[0-3]",H:c.strict?"1?[0-9]|2[0-3]":"[01]?[0-9]|2[0-3]",hh:"[0][1-9]|[1][012]",h:c.strict?"[1-9]|1[012]":"0?[1-9]|1[012]",a:"AM|PM",EEEE:r.DATETIME_FORMATS.DAY.join("|"),EEE:r.DATETIME_FORMATS.SHORTDAY.join("|"),dd:"0[1-9]|[12][0-9]|3[01]",d:c.strict?"[1-9]|[1-2][0-9]|3[01]":"0?[1-9]|[1-2][0-9]|3[01]",MMMM:r.DATETIME_FORMATS.MONTH.join("|"),MMM:r.DATETIME_FORMATS.SHORTMONTH.join("|"),MM:"0[1-9]|1[012]",M:c.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:c.strict?"-?(0|[1-9][0-9]{0,3})":"-?0*[0-9]{1,4}"},h={sss:t.setMilliseconds,ss:t.setSeconds,s:t.setSeconds,mm:t.setMinutes,m:t.setMinutes,HH:t.setHours,H:t.setHours,hh:t.setHours,h:t.setHours,dd:t.setDate,d:t.setDate,a:function(t){var e=this.getHours();return this.setHours(t.match(/pm/i)?e+12:e)},MMMM:function(t){return this.setMonth(r.DATETIME_FORMATS.MONTH.indexOf(t))},MMM:function(t){return this.setMonth(r.DATETIME_FORMATS.SHORTMONTH.indexOf(t))},MM:function(t){return this.setMonth(1*t-1)},M:function(t){return this.setMonth(1*t-1)},yyyy:t.setFullYear,yy:function(t){return this.setFullYear(2e3+1*t)},y:t.setFullYear};return l.init=function(){l.$format=r.DATETIME_FORMATS[c.format]||c.format,u=o(l.$format),M=i(l.$format)},l.isValid=function(t){return angular.isDate(t)?!isNaN(t.getTime()):u.test(t)},l.parse=function(t,e,r){angular.isDate(t)&&(t=s(t,r||l.$format));var n=r?o(r):u,a=r?i(r):M,c=n.exec(t);if(!c)return!1;for(var f=e||new Date(0,0,1),h=0;h<c.length-1;h++)a[h]&&a[h].call(f,c[h+1]);return f},l.init(),l};return n}]}]);
//# sourceMappingURL=date-parser.min.js.map