From b3f4c692e7a0bd3b579b8c2fa4bc3ca92dd3f5f0 Mon Sep 17 00:00:00 2001 From: Alex Wilks Date: Fri, 24 Jul 2015 22:25:48 +0100 Subject: [PATCH 1/2] Update directive.js Return the custom date object rather than a javascript date object in the checkDate function. Add months in order rather than reversed. Update the original model on date change. Allow for a calculation in the "startYear" attribute. My Angular skills are limited as I am new to this but the fixes implemented resolve my personal needs - maybe someone smarter can fix this properly. There is also a bug on line 38 where "!date.month" will evaluate to true in the event that month is 0 (which it will be if January is selected) and that will cause the checkDate function to return false. I will resolve this shortly. --- directive.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/directive.js b/directive.js index 5713f00..88ae099 100644 --- a/directive.js +++ b/directive.js @@ -40,7 +40,7 @@ d = new Date(Date.UTC(date.year, date.month, date.day)); if (d && (d.getMonth() === date.month && d.getDate() === Number(date.day))) { - return d; + return date; } return this.checkDate(changeDate(date)); @@ -54,13 +54,14 @@ }()), months: (function () { var lst = [], - mLen = months.length; + i = 0; - while (mLen--) { + while (i < months.length) { lst.push({ - value: mLen, - name: months[mLen] + value: i, + name: months[i] }); + i++; } return lst; }()) @@ -91,6 +92,8 @@ var date = rsmDateUtils.checkDate($scope.dateFields); if (date) { $scope.dateFields = date; + // Update the original model + $scope.model = new Date(Date.UTC(date.year, date.month, date.day)); } }; }], @@ -108,7 +111,7 @@ ' ' + '', link: function (scope, element, attrs, ctrl) { - var currentYear = parseInt(attrs.startingYear, 10) || new Date().getFullYear(), + var currentYear = parseInt(attrs.startingYear, 10) || parseInt(eval(attrs.startingYear), 10) || new Date().getFullYear(), // Add eval() test to allow for calculated dates numYears = parseInt(attrs.numYears,10) || 100, oldestYear = currentYear - numYears, overridable = [ @@ -167,4 +170,4 @@ } }; }]); -}()); \ No newline at end of file +}()); From ab58203d8fe7d844a1ade451fdded2d09fe577a7 Mon Sep 17 00:00:00 2001 From: Alex Wilks Date: Fri, 24 Jul 2015 22:49:38 +0100 Subject: [PATCH 2/2] Update directive.js Additional update to fix checkDate bug where January would return an invalid date --- directive.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/directive.js b/directive.js index 88ae099..8301ef4 100644 --- a/directive.js +++ b/directive.js @@ -35,7 +35,7 @@ return { checkDate: function (date) { var d; - if (!date.day || !date.month || !date.year) return false; + if (!date.day || !(date.month === 0 || date.month) || !date.year) return false; d = new Date(Date.UTC(date.year, date.month, date.day)); @@ -61,7 +61,7 @@ value: i, name: months[i] }); - i++; + i++; } return lst; }())