diff --git a/dist/ng-quick-date.js b/dist/ng-quick-date.js
index 610d500..9e5a2a3 100644
--- a/dist/ng-quick-date.js
+++ b/dist/ng-quick-date.js
@@ -21,8 +21,209 @@
dayAbbreviations: ["Su", "M", "Tu", "W", "Th", "F", "Sa"],
dateFilter: null,
parseDateFunction: function(str) {
- var seconds;
- seconds = Date.parse(str);
+ var getDateFromFormat, scope, seconds;
+ getDateFromFormat = function(val, format) {
+ var ampm, c, date, day_name, hh, i, i_format, i_val, mm, month, month_name, newdate, now, ss, token, token2, x, y, year, _getInt, _isInteger;
+ _isInteger = function(val) {
+ var digits, i;
+ digits = "1234567890";
+ i = 0;
+ while (i < val.length) {
+ if (digits.indexOf(val.charAt(i)) === -1) {
+ return false;
+ }
+ i++;
+ }
+ return true;
+ };
+ _getInt = function(str, i, minlength, maxlength) {
+ var token, x;
+ x = maxlength;
+ while (x >= minlength) {
+ token = str.substring(i, i + x);
+ if (token.length < minlength) {
+ return null;
+ }
+ if (_isInteger(token)) {
+ return token;
+ }
+ x--;
+ }
+ return null;
+ };
+ val = val + "";
+ format = format + "";
+ i_val = 0;
+ i_format = 0;
+ c = "";
+ token = "";
+ token2 = "";
+ x = void 0;
+ y = void 0;
+ now = new Date();
+ year = now.getYear();
+ month = now.getMonth() + 1;
+ date = 1;
+ hh = now.getHours();
+ mm = now.getMinutes();
+ ss = now.getSeconds();
+ ampm = "";
+ while (i_format < format.length) {
+ c = format.charAt(i_format);
+ token = "";
+ while ((format.charAt(i_format) === c) && (i_format < format.length)) {
+ token += format.charAt(i_format++);
+ }
+ if (token === "yyyy" || token === "yy" || token === "y") {
+ if (token === "yyyy") {
+ x = 4;
+ y = 4;
+ }
+ if (token === "yy") {
+ x = 2;
+ y = 2;
+ }
+ if (token === "y") {
+ x = 2;
+ y = 4;
+ }
+ year = _getInt(val, i_val, x, y);
+ if (year == null) {
+ return 0;
+ }
+ i_val += year.length;
+ if (year.length === 2) {
+ if (year > 70) {
+ year = 1900 + (year - 0);
+ } else {
+ year = 2000 + (year - 0);
+ }
+ }
+ } else if (token === "MMM" || token === "NNN") {
+ month = 0;
+ i = 0;
+ while (i < MONTH_NAMES.length) {
+ month_name = MONTH_NAMES[i];
+ if (val.substring(i_val, i_val + month_name.length).toLowerCase() === month_name.toLowerCase()) {
+ if (token === "MMM" || (token === "NNN" && i > 11)) {
+ month = i + 1;
+ if (month > 12) {
+ month -= 12;
+ }
+ i_val += month_name.length;
+ break;
+ }
+ }
+ i++;
+ }
+ if ((month < 1) || (month > 12)) {
+ return 0;
+ }
+ } else if (token === "EE" || token === "E") {
+ i = 0;
+ while (i < DAY_NAMES.length) {
+ day_name = DAY_NAMES[i];
+ if (val.substring(i_val, i_val + day_name.length).toLowerCase() === day_name.toLowerCase()) {
+ i_val += day_name.length;
+ break;
+ }
+ i++;
+ }
+ } else if (token === "MM" || token === "M") {
+ month = _getInt(val, i_val, token.length, 2);
+ if ((month == null) || (month < 1) || (month > 12)) {
+ return 0;
+ }
+ i_val += month.length;
+ } else if (token === "dd" || token === "d") {
+ date = _getInt(val, i_val, token.length, 2);
+ if ((date == null) || (date < 1) || (date > 31)) {
+ return 0;
+ }
+ i_val += date.length;
+ } else if (token === "hh" || token === "h") {
+ hh = _getInt(val, i_val, token.length, 2);
+ if ((hh == null) || (hh < 1) || (hh > 12)) {
+ return 0;
+ }
+ i_val += hh.length;
+ } else if (token === "HH" || token === "H") {
+ hh = _getInt(val, i_val, token.length, 2);
+ if ((hh == null) || (hh < 0) || (hh > 23)) {
+ return 0;
+ }
+ i_val += hh.length;
+ } else if (token === "KK" || token === "K") {
+ hh = _getInt(val, i_val, token.length, 2);
+ if ((hh == null) || (hh < 0) || (hh > 11)) {
+ return 0;
+ }
+ i_val += hh.length;
+ } else if (token === "kk" || token === "k") {
+ hh = _getInt(val, i_val, token.length, 2);
+ if ((hh == null) || (hh < 1) || (hh > 24)) {
+ return 0;
+ }
+ i_val += hh.length;
+ hh--;
+ } else if (token === "mm" || token === "m") {
+ mm = _getInt(val, i_val, token.length, 2);
+ if ((mm == null) || (mm < 0) || (mm > 59)) {
+ return 0;
+ }
+ i_val += mm.length;
+ } else if (token === "ss" || token === "s") {
+ ss = _getInt(val, i_val, token.length, 2);
+ if ((ss == null) || (ss < 0) || (ss > 59)) {
+ return 0;
+ }
+ i_val += ss.length;
+ } else if (token === "a") {
+ if (val.substring(i_val, i_val + 2).toLowerCase() === "am") {
+ ampm = "AM";
+ } else if (val.substring(i_val, i_val + 2).toLowerCase() === "pm") {
+ ampm = "PM";
+ } else {
+ return 0;
+ }
+ i_val += 2;
+ } else {
+ if (val.substring(i_val, i_val + token.length) !== token) {
+ return 0;
+ } else {
+ i_val += token.length;
+ }
+ }
+ }
+ if (i_val !== val.length) {
+ return 0;
+ }
+ if (month === 2) {
+ if (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0)) {
+ if (date > 29) {
+ return 0;
+ }
+ } else {
+ if (date > 28) {
+ return 0;
+ }
+ }
+ }
+ if ((month === 4) || (month === 6) || (month === 9) || (month === 11) ? date > 30 : void 0) {
+ return 0;
+ }
+ if (hh < 12 && ampm === "PM") {
+ hh = hh - 0 + 12;
+ } else {
+ if (hh > 11 && ampm === "AM") {
+ hh -= 12;
+ }
+ }
+ newdate = new Date(year, month - 1, date, hh, mm, ss);
+ return newdate.getTime();
+ };
+ scope = this;
+ seconds = getDateFromFormat(str, scope.labelFormat) || Date.parse(str);
if (isNaN(seconds)) {
return null;
} else {
@@ -202,7 +403,9 @@
return date;
}
};
- parseDateString = ngQuickDateDefaults.parseDateFunction;
+ parseDateString = function() {
+ return ngQuickDateDefaults.parseDateFunction.apply(scope, arguments);
+ };
datesAreEqual = function(d1, d2, compareTimes) {
if (compareTimes == null) {
compareTimes = false;
diff --git a/dist/ng-quick-date.min.js b/dist/ng-quick-date.min.js
index 42eeb01..f3b135b 100644
--- a/dist/ng-quick-date.min.js
+++ b/dist/ng-quick-date.min.js
@@ -1 +1 @@
-(function(){var a;a=angular.module("ngQuickDate",[]),a.provider("ngQuickDateDefaults",function(){return{options:{dateFormat:"M/d/yyyy",timeFormat:"h:mm a",labelFormat:null,placeholder:"Click to Set Date",hoverText:null,buttonIconHtml:null,closeButtonHtml:"×",nextLinkHtml:"Next →",prevLinkHtml:"← Prev",disableTimepicker:!1,disableClearButton:!1,defaultTime:null,dayAbbreviations:["Su","M","Tu","W","Th","F","Sa"],dateFilter:null,parseDateFunction:function(a){var b;return b=Date.parse(a),isNaN(b)?null:new Date(b)}},$get:function(){return this.options},set:function(a,b){var c,d,e;if("object"==typeof a){e=[];for(c in a)d=a[c],e.push(this.options[c]=d);return e}return this.options[a]=b}}}),a.directive("quickDatepicker",["ngQuickDateDefaults","$filter","$sce",function(a,b,c){return{restrict:"E",require:"?ngModel",scope:{dateFilter:"=?",onChange:"&",required:"@"},replace:!0,link:function(d,e,f,g){var h,i,j,k,l,m,n,o,p,q,r,s,t;return m=function(){return q(),d.toggleCalendar(!1),d.weeks=[],d.inputDate=null,d.inputTime=null,d.invalid=!0,"string"==typeof f.initValue&&g.$setViewValue(f.initValue),p(),o()},q=function(){var b,e;for(b in a)e=a[b],b.match(/[Hh]tml/)?d[b]=c.trustAsHtml(a[b]||""):!d[b]&&f[b]?d[b]=f[b]:d[b]||(d[b]=a[b]);return d.labelFormat||(d.labelFormat=d.dateFormat,d.disableTimepicker||(d.labelFormat+=" "+d.timeFormat)),f.iconClass&&f.iconClass.length?d.buttonIconHtml=c.trustAsHtml(""):void 0},i=!1,window.document.addEventListener("click",function(){return d.calendarShown&&!i&&(d.toggleCalendar(!1),d.$apply()),i=!1}),angular.element(e[0])[0].addEventListener("click",function(){return i=!0}),o=function(){var a;return a=g.$modelValue?n(g.$modelValue):null,s(),r(a),d.mainButtonStr=a?b("date")(a,d.labelFormat):d.placeholder,d.invalid=g.$invalid},r=function(a){return null!=a?(d.inputDate=b("date")(a,d.dateFormat),d.inputTime=b("date")(a,d.timeFormat)):(d.inputDate=null,d.inputTime=null)},p=function(a){var b;return null==a&&(a=null),b=null!=a?new Date(a):new Date,"Invalid Date"===b.toString()&&(b=new Date),b.setDate(1),d.calendarDate=new Date(b)},s=function(){var a,b,c,e,f,h,i,k,m,n,o,p,q,r;for(h=d.calendarDate.getDay(),e=l(d.calendarDate.getFullYear(),d.calendarDate.getMonth()),f=Math.ceil((h+e)/7),o=[],a=new Date(d.calendarDate),a.setDate(a.getDate()+-1*h),i=p=0,r=f-1;r>=0?r>=p:p>=r;i=r>=0?++p:--p)for(o.push([]),c=q=0;6>=q;c=++q)b=new Date(a),d.defaultTime&&(m=d.defaultTime.split(":"),b.setHours(m[0]||0),b.setMinutes(m[1]||0),b.setSeconds(m[2]||0)),k=g.$modelValue&&b&&j(b,g.$modelValue),n=j(b,new Date),o[i].push({date:b,selected:k,disabled:"function"==typeof d.dateFilter?!d.dateFilter(b):!1,other:b.getMonth()!==d.calendarDate.getMonth(),today:n}),a.setDate(a.getDate()+1);return d.weeks=o},g.$parsers.push(function(a){return d.required&&null==a?(g.$setValidity("required",!1),null):angular.isDate(a)?(g.$setValidity("required",!0),a):angular.isString(a)?(g.$setValidity("required",!0),d.parseDateFunction(a)):null}),g.$formatters.push(function(a){return angular.isDate(a)?a:angular.isString(a)?d.parseDateFunction(a):void 0}),h=function(a,c){return b("date")(a,c)},t=function(a){return"string"==typeof a?n(a):a},n=a.parseDateFunction,j=function(a,b,c){return null==c&&(c=!1),c?a-b===0:(a=t(a),b=t(b),a&&b&&a.getYear()===b.getYear()&&a.getMonth()===b.getMonth()&&a.getDate()===b.getDate())},k=function(a,b){return a&&b?parseInt(a.getTime()/6e4)===parseInt(b.getTime()/6e4):!1},l=function(a,b){return[31,a%4===0&&a%100!==0||a%400===0?29:28,31,30,31,30,31,31,30,31,30,31][b]},g.$render=function(){return p(g.$viewValue),o()},g.$viewChangeListeners.unshift(function(){return p(g.$viewValue),o(),d.onChange?d.onChange():void 0}),d.$watch("calendarShown",function(a){var b;return a?(b=angular.element(e[0].querySelector(".quickdate-date-input"))[0],b.select()):void 0}),d.toggleCalendar=function(a){return d.calendarShown=isFinite(a)?a:!d.calendarShown},d.selectDate=function(a,b){var c;return null==b&&(b=!0),c=!g.$viewValue&&a||g.$viewValue&&!a||a&&g.$viewValue&&a.getTime()!==g.$viewValue.getTime(),"function"!=typeof d.dateFilter||d.dateFilter(a)?(g.$setViewValue(a),b&&d.toggleCalendar(!1),!0):!1},d.selectDateFromInput=function(a){var b,c,e,f;null==a&&(a=!1);try{if(c=n(d.inputDate),!c)throw"Invalid Date";if(!d.disableTimepicker&&d.inputTime&&d.inputTime.length&&c){if(f=d.disableTimepicker?"00:00:00":d.inputTime,e=n(""+d.inputDate+" "+f),!e)throw"Invalid Time";c=e}if(!k(g.$viewValue,c)&&!d.selectDate(c,!1))throw"Invalid Date";return a&&d.toggleCalendar(!1),d.inputDateErr=!1,d.inputTimeErr=!1}catch(h){if(b=h,"Invalid Date"===b)return d.inputDateErr=!0;if("Invalid Time"===b)return d.inputTimeErr=!0}},d.onDateInputTab=function(){return d.disableTimepicker&&d.toggleCalendar(!1),!0},d.onTimeInputTab=function(){return d.toggleCalendar(!1),!0},d.nextMonth=function(){return p(new Date(new Date(d.calendarDate).setMonth(d.calendarDate.getMonth()+1))),o()},d.prevMonth=function(){return p(new Date(new Date(d.calendarDate).setMonth(d.calendarDate.getMonth()-1))),o()},d.clear=function(){return d.selectDate(null,!0)},m()},template:"
"}}]),a.directive("ngEnter",function(){return function(a,b,c){return b.bind("keydown keypress",function(b){return 13===b.which?(a.$apply(c.ngEnter),b.preventDefault()):void 0})}}),a.directive("onTab",function(){return{restrict:"A",link:function(a,b,c){return b.bind("keydown keypress",function(b){return 9!==b.which||b.shiftKey?void 0:a.$apply(c.onTab)})}}})}).call(this);
\ No newline at end of file
+(function(){var a;a=angular.module("ngQuickDate",[]),a.provider("ngQuickDateDefaults",function(){return{options:{dateFormat:"M/d/yyyy",timeFormat:"h:mm a",labelFormat:null,placeholder:"Click to Set Date",hoverText:null,buttonIconHtml:null,closeButtonHtml:"×",nextLinkHtml:"Next →",prevLinkHtml:"← Prev",disableTimepicker:!1,disableClearButton:!1,defaultTime:null,dayAbbreviations:["Su","M","Tu","W","Th","F","Sa"],dateFilter:null,parseDateFunction:function(a){var b,c,d;return b=function(a,b){var c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w;for(w=function(a){var b,c;for(b="1234567890",c=0;c=c;){if(e=a.substring(b,b+f),e.length70?1900+(u-0):2e3+(u-0))}else if("MMM"===q||"NNN"===q){for(l=0,h=0;h11)){l=h+1,l>12&&(l-=12),j+=m.length;break}h++}if(1>l||l>12)return 0}else if("EE"===q||"E"===q)for(h=0;hl||l>12)return 0;j+=l.length}else if("dd"===q||"d"===q){if(e=v(a,j,q.length,2),null==e||1>e||e>31)return 0;j+=e.length}else if("hh"===q||"h"===q){if(g=v(a,j,q.length,2),null==g||1>g||g>12)return 0;j+=g.length}else if("HH"===q||"H"===q){if(g=v(a,j,q.length,2),null==g||0>g||g>23)return 0;j+=g.length}else if("KK"===q||"K"===q){if(g=v(a,j,q.length,2),null==g||0>g||g>11)return 0;j+=g.length}else if("kk"===q||"k"===q){if(g=v(a,j,q.length,2),null==g||1>g||g>24)return 0;j+=g.length,g--}else if("mm"===q||"m"===q){if(k=v(a,j,q.length,2),null==k||0>k||k>59)return 0;j+=k.length}else if("ss"===q||"s"===q){if(p=v(a,j,q.length,2),null==p||0>p||p>59)return 0;j+=p.length}else if("a"===q){if("am"===a.substring(j,j+2).toLowerCase())c="AM";else{if("pm"!==a.substring(j,j+2).toLowerCase())return 0;c="PM"}j+=2}else{if(a.substring(j,j+q.length)!==q)return 0;j+=q.length}}if(j!==a.length)return 0;if(2===l)if(u%4===0&&u%100!==0||u%400===0){if(e>29)return 0}else if(e>28)return 0;return(4===l||6===l||9===l||11===l?e>30:void 0)?0:(12>g&&"PM"===c?g=g-0+12:g>11&&"AM"===c&&(g-=12),n=new Date(u,l-1,e,g,k,p),n.getTime())},c=this,d=b(a,c.labelFormat)||Date.parse(a),isNaN(d)?null:new Date(d)}},$get:function(){return this.options},set:function(a,b){var c,d,e;if("object"==typeof a){e=[];for(c in a)d=a[c],e.push(this.options[c]=d);return e}return this.options[a]=b}}}),a.directive("quickDatepicker",["ngQuickDateDefaults","$filter","$sce",function(a,b,c){return{restrict:"E",require:"?ngModel",scope:{dateFilter:"=?",onChange:"&",required:"@"},replace:!0,link:function(d,e,f,g){var h,i,j,k,l,m,n,o,p,q,r,s,t;return m=function(){return q(),d.toggleCalendar(!1),d.weeks=[],d.inputDate=null,d.inputTime=null,d.invalid=!0,"string"==typeof f.initValue&&g.$setViewValue(f.initValue),p(),o()},q=function(){var b,e;for(b in a)e=a[b],b.match(/[Hh]tml/)?d[b]=c.trustAsHtml(a[b]||""):!d[b]&&f[b]?d[b]=f[b]:d[b]||(d[b]=a[b]);return d.labelFormat||(d.labelFormat=d.dateFormat,d.disableTimepicker||(d.labelFormat+=" "+d.timeFormat)),f.iconClass&&f.iconClass.length?d.buttonIconHtml=c.trustAsHtml(""):void 0},i=!1,window.document.addEventListener("click",function(){return d.calendarShown&&!i&&(d.toggleCalendar(!1),d.$apply()),i=!1}),angular.element(e[0])[0].addEventListener("click",function(){return i=!0}),o=function(){var a;return a=g.$modelValue?n(g.$modelValue):null,s(),r(a),d.mainButtonStr=a?b("date")(a,d.labelFormat):d.placeholder,d.invalid=g.$invalid},r=function(a){return null!=a?(d.inputDate=b("date")(a,d.dateFormat),d.inputTime=b("date")(a,d.timeFormat)):(d.inputDate=null,d.inputTime=null)},p=function(a){var b;return null==a&&(a=null),b=null!=a?new Date(a):new Date,"Invalid Date"===b.toString()&&(b=new Date),b.setDate(1),d.calendarDate=new Date(b)},s=function(){var a,b,c,e,f,h,i,k,m,n,o,p,q,r;for(h=d.calendarDate.getDay(),e=l(d.calendarDate.getFullYear(),d.calendarDate.getMonth()),f=Math.ceil((h+e)/7),o=[],a=new Date(d.calendarDate),a.setDate(a.getDate()+-1*h),i=p=0,r=f-1;r>=0?r>=p:p>=r;i=r>=0?++p:--p)for(o.push([]),c=q=0;6>=q;c=++q)b=new Date(a),d.defaultTime&&(m=d.defaultTime.split(":"),b.setHours(m[0]||0),b.setMinutes(m[1]||0),b.setSeconds(m[2]||0)),k=g.$modelValue&&b&&j(b,g.$modelValue),n=j(b,new Date),o[i].push({date:b,selected:k,disabled:"function"==typeof d.dateFilter?!d.dateFilter(b):!1,other:b.getMonth()!==d.calendarDate.getMonth(),today:n}),a.setDate(a.getDate()+1);return d.weeks=o},g.$parsers.push(function(a){return d.required&&null==a?(g.$setValidity("required",!1),null):angular.isDate(a)?(g.$setValidity("required",!0),a):angular.isString(a)?(g.$setValidity("required",!0),d.parseDateFunction(a)):null}),g.$formatters.push(function(a){return angular.isDate(a)?a:angular.isString(a)?d.parseDateFunction(a):void 0}),h=function(a,c){return b("date")(a,c)},t=function(a){return"string"==typeof a?n(a):a},n=function(){return a.parseDateFunction.apply(d,arguments)},j=function(a,b,c){return null==c&&(c=!1),c?a-b===0:(a=t(a),b=t(b),a&&b&&a.getYear()===b.getYear()&&a.getMonth()===b.getMonth()&&a.getDate()===b.getDate())},k=function(a,b){return a&&b?parseInt(a.getTime()/6e4)===parseInt(b.getTime()/6e4):!1},l=function(a,b){return[31,a%4===0&&a%100!==0||a%400===0?29:28,31,30,31,30,31,31,30,31,30,31][b]},g.$render=function(){return p(g.$viewValue),o()},g.$viewChangeListeners.unshift(function(){return p(g.$viewValue),o(),d.onChange?d.onChange():void 0}),d.$watch("calendarShown",function(a){var b;return a?(b=angular.element(e[0].querySelector(".quickdate-date-input"))[0],b.select()):void 0}),d.toggleCalendar=function(a){return d.calendarShown=isFinite(a)?a:!d.calendarShown},d.selectDate=function(a,b){var c;return null==b&&(b=!0),c=!g.$viewValue&&a||g.$viewValue&&!a||a&&g.$viewValue&&a.getTime()!==g.$viewValue.getTime(),"function"!=typeof d.dateFilter||d.dateFilter(a)?(g.$setViewValue(a),b&&d.toggleCalendar(!1),!0):!1},d.selectDateFromInput=function(a){var b,c,e,f;null==a&&(a=!1);try{if(c=n(d.inputDate),!c)throw"Invalid Date";if(!d.disableTimepicker&&d.inputTime&&d.inputTime.length&&c){if(f=d.disableTimepicker?"00:00:00":d.inputTime,e=n(""+d.inputDate+" "+f),!e)throw"Invalid Time";c=e}if(!k(g.$viewValue,c)&&!d.selectDate(c,!1))throw"Invalid Date";return a&&d.toggleCalendar(!1),d.inputDateErr=!1,d.inputTimeErr=!1}catch(h){if(b=h,"Invalid Date"===b)return d.inputDateErr=!0;if("Invalid Time"===b)return d.inputTimeErr=!0}},d.onDateInputTab=function(){return d.disableTimepicker&&d.toggleCalendar(!1),!0},d.onTimeInputTab=function(){return d.toggleCalendar(!1),!0},d.nextMonth=function(){return p(new Date(new Date(d.calendarDate).setMonth(d.calendarDate.getMonth()+1))),o()},d.prevMonth=function(){return p(new Date(new Date(d.calendarDate).setMonth(d.calendarDate.getMonth()-1))),o()},d.clear=function(){return d.selectDate(null,!0)},m()},template:""}}]),a.directive("ngEnter",function(){return function(a,b,c){return b.bind("keydown keypress",function(b){return 13===b.which?(a.$apply(c.ngEnter),b.preventDefault()):void 0})}}),a.directive("onTab",function(){return{restrict:"A",link:function(a,b,c){return b.bind("keydown keypress",function(b){return 9!==b.which||b.shiftKey?void 0:a.$apply(c.onTab)})}}})}).call(this);
\ No newline at end of file
diff --git a/src/ng-quick-date.coffee b/src/ng-quick-date.coffee
index 239bb35..64e10a0 100644
--- a/src/ng-quick-date.coffee
+++ b/src/ng-quick-date.coffee
@@ -28,7 +28,162 @@ app.provider "ngQuickDateDefaults", ->
dayAbbreviations: ["Su", "M", "Tu", "W", "Th", "F", "Sa"],
dateFilter: null
parseDateFunction: (str) ->
- seconds = Date.parse(str)
+ # Parse date helper function
+ # Author: Matt Kruse
+ # WWW: http://www.mattkruse.com/
+ getDateFromFormat = (val, format) ->
+ _isInteger = (val) ->
+ digits = "1234567890"
+ i = 0
+
+ while i < val.length
+ return false if digits.indexOf(val.charAt(i)) is -1
+ i++
+ true
+ _getInt = (str, i, minlength, maxlength) ->
+ x = maxlength
+
+ while x >= minlength
+ token = str.substring(i, i + x)
+ return null if token.length < minlength
+ return token if _isInteger(token)
+ x--
+ null
+ val = val + ""
+ format = format + ""
+ i_val = 0
+ i_format = 0
+ c = ""
+ token = ""
+ token2 = ""
+ x = undefined
+ y = undefined
+ now = new Date()
+ year = now.getYear()
+ month = now.getMonth() + 1
+ date = 1
+ hh = now.getHours()
+ mm = now.getMinutes()
+ ss = now.getSeconds()
+ ampm = ""
+ while i_format < format.length
+
+ # Get next token from format string
+ c = format.charAt(i_format)
+ token = ""
+ token += format.charAt(i_format++) while (format.charAt(i_format) is c) and (i_format < format.length)
+
+ # Extract contents of value based on format token
+ if token is "yyyy" or token is "yy" or token is "y"
+ if token is "yyyy"
+ x = 4
+ y = 4
+ if token is "yy"
+ x = 2
+ y = 2
+ if token is "y"
+ x = 2
+ y = 4
+ year = _getInt(val, i_val, x, y)
+ return 0 unless year?
+ i_val += year.length
+ if year.length is 2
+ if year > 70
+ year = 1900 + (year - 0)
+ else
+ year = 2000 + (year - 0)
+ else if token is "MMM" or token is "NNN"
+ month = 0
+ i = 0
+
+ while i < MONTH_NAMES.length
+ month_name = MONTH_NAMES[i]
+ if val.substring(i_val, i_val + month_name.length).toLowerCase() is month_name.toLowerCase()
+ if token is "MMM" or (token is "NNN" and i > 11)
+ month = i + 1
+ month -= 12 if month > 12
+ i_val += month_name.length
+ break
+ i++
+ return 0 if (month < 1) or (month > 12)
+ else if token is "EE" or token is "E"
+ i = 0
+
+ while i < DAY_NAMES.length
+ day_name = DAY_NAMES[i]
+ if val.substring(i_val, i_val + day_name.length).toLowerCase() is day_name.toLowerCase()
+ i_val += day_name.length
+ break
+ i++
+ else if token is "MM" or token is "M"
+ month = _getInt(val, i_val, token.length, 2)
+ return 0 if not month? or (month < 1) or (month > 12)
+ i_val += month.length
+ else if token is "dd" or token is "d"
+ date = _getInt(val, i_val, token.length, 2)
+ return 0 if not date? or (date < 1) or (date > 31)
+ i_val += date.length
+ else if token is "hh" or token is "h"
+ hh = _getInt(val, i_val, token.length, 2)
+ return 0 if not hh? or (hh < 1) or (hh > 12)
+ i_val += hh.length
+ else if token is "HH" or token is "H"
+ hh = _getInt(val, i_val, token.length, 2)
+ return 0 if not hh? or (hh < 0) or (hh > 23)
+ i_val += hh.length
+ else if token is "KK" or token is "K"
+ hh = _getInt(val, i_val, token.length, 2)
+ return 0 if not hh? or (hh < 0) or (hh > 11)
+ i_val += hh.length
+ else if token is "kk" or token is "k"
+ hh = _getInt(val, i_val, token.length, 2)
+ return 0 if not hh? or (hh < 1) or (hh > 24)
+ i_val += hh.length
+ hh--
+ else if token is "mm" or token is "m"
+ mm = _getInt(val, i_val, token.length, 2)
+ return 0 if not mm? or (mm < 0) or (mm > 59)
+ i_val += mm.length
+ else if token is "ss" or token is "s"
+ ss = _getInt(val, i_val, token.length, 2)
+ return 0 if not ss? or (ss < 0) or (ss > 59)
+ i_val += ss.length
+ else if token is "a"
+ if val.substring(i_val, i_val + 2).toLowerCase() is "am"
+ ampm = "AM"
+ else if val.substring(i_val, i_val + 2).toLowerCase() is "pm"
+ ampm = "PM"
+ else
+ return 0
+ i_val += 2
+ else
+ unless val.substring(i_val, i_val + token.length) is token
+ return 0
+ else
+ i_val += token.length
+
+ # If there are any trailing characters left in the value, it doesn't match
+ return 0 unless i_val is val.length
+
+ # Is date valid for month?
+ if month is 2
+
+ # Check for leap year
+ if ((year % 4 is 0) and (year % 100 isnt 0)) or (year % 400 is 0) # leap year
+ return 0 if date > 29
+ else
+ return 0 if date > 28
+ return 0 if date > 30 if (month is 4) or (month is 6) or (month is 9) or (month is 11)
+
+ # Correct hours value
+ if hh < 12 and ampm is "PM"
+ hh = hh - 0 + 12
+ else hh -= 12 if hh > 11 and ampm is "AM"
+ newdate = new Date(year, month - 1, date, hh, mm, ss)
+ newdate.getTime()
+
+ scope = this
+ seconds = getDateFromFormat(str, scope.labelFormat) || Date.parse(str)
if isNaN(seconds)
return null
else
@@ -202,8 +357,8 @@ app.directive "quickDatepicker", ['ngQuickDateDefaults', '$filter', '$sce', (ngQ
else
date
- parseDateString = ngQuickDateDefaults.parseDateFunction
-
+ parseDateString = () ->
+ ngQuickDateDefaults.parseDateFunction.apply(scope, arguments)
datesAreEqual = (d1, d2, compareTimes=false) ->
if compareTimes
(d1 - d2) == 0