From 3b7229cb16b2dcc40dd26a842ec5b81ec7fb6cec Mon Sep 17 00:00:00 2001 From: Barbara Post Date: Wed, 14 Jun 2017 13:25:42 +0200 Subject: [PATCH] Working on #7: adjustment of the selected day of target month to the available days of target month OK. Last thing to fix: the available months should change when the year changes (added a test case for this). --- dist/ionic-datepicker.bundle.min.js | 2 +- src/ionic-datepicker.provider.js | 59 +++++++++++++++++-- test/www/index.html | 3 + test/www/js/controllers.js | 6 +- test_original_datepicker/www/index.html | 3 + .../www/js/controllers.js | 6 +- 6 files changed, 71 insertions(+), 8 deletions(-) diff --git a/dist/ionic-datepicker.bundle.min.js b/dist/ionic-datepicker.bundle.min.js index 4439524..8146054 100755 --- a/dist/ionic-datepicker.bundle.min.js +++ b/dist/ionic-datepicker.bundle.min.js @@ -1 +1 @@ -!function(e,t){var n=e.createElement("style");if(e.getElementsByTagName("head")[0].appendChild(n),n.styleSheet)n.styleSheet.disabled||(n.styleSheet.cssText=t);else try{n.innerHTML=t}catch(e){n.innerText=t}}(document,"/**/\n.padding_zero {\n padding: 0;\n}\n\n.ionic_datepicker_popup .font_bold {\n font-weight: bold;\n}\n\n.ionic_datepicker_popup .padding_top_zero {\n padding-top: 0;\n}\n\n.ionic_datepicker_popup .padding_left_5px {\n padding-left: 5px;\n}\n\n.ionic_datepicker_popup .padding_right_5px {\n padding-right: 5px;\n}\n\n.ionic_datepicker_popup .month_year_section {\n padding: 5px 0;\n}\n\n.ionic_datepicker_popup .calendar_grid {\n height: 215px;\n}\n\n.ionic_datepicker_popup .calendar_grid .weeks_row {\n padding: 0;\n}\n\n.ionic_datepicker_popup .today {\n border: 1px solid #009688;\n border-radius: 50%;\n}\n\n.ionic_datepicker_popup .selected_date {\n background-color: #009688;\n border-radius: 50%;\n color: #ffffff;\n font-weight: bold;\n}\n\n.ionic_datepicker_popup .popup-head {\n background-color: #009688;\n display: none;\n}\n\n.ionic_datepicker_popup .popup-head .popup-title {\n color: #ffffff;\n}\n\n.ionic_datepicker_popup .popup-head .popup-sub-title {\n color: #ffffff;\n}\n\n.ionic_datepicker_popup .popup-body {\n background-color: #ffffff;\n}\n\n.ionic_datepicker_popup .popup-body .selected_date_full {\n background-color: #009688;\n margin: -10px -10px 0 -10px;\n height: 45px;\n text-align: center;\n font-weight: bold;\n color: #ffffff;\n line-height: 45px;\n font-size: 18px;\n}\n\n.ionic_datepicker_popup .popup-body .select_section {\n padding: 1px 5px;\n}\n\n.ionic_datepicker_popup .popup-body .pointer_events_none {\n pointer-events: none;\n color: #aaaaaa !important;\n}\n\n.ionic_datepicker_popup .popup-body .month_select, .ionic_datepicker_popup .popup-body .year_select {\n border: none;\n border-bottom: 1px solid #009688;\n padding: 0;\n}\n\n.ionic_datepicker_popup .popup-body .month_select .input-label, .ionic_datepicker_popup .popup-body .year_select .input-label {\n padding: 2px 0;\n width: 0;\n}\n\n.ionic_datepicker_popup .popup-body .month_select select, .ionic_datepicker_popup .popup-body .year_select select {\n left: 10px;\n border: none;\n padding: 0;\n}\n\n.ionic_datepicker_popup .popup-body .month_select:after, .ionic_datepicker_popup .popup-body .year_select:after {\n right: 5px;\n color: #009688;\n}\n\n.ionic_datepicker_popup .popup-body .show_nav {\n padding: 5px 0 0 0;\n}\n\n.ionic_datepicker_popup .popup-body .show_nav .prev_btn_section {\n padding: 5px 0;\n text-align: left;\n}\n\n.ionic_datepicker_popup .popup-body .show_nav .prev_btn_section button {\n padding: 0;\n}\n\n.ionic_datepicker_popup .popup-body .show_nav .next_btn_section {\n padding: 5px 0;\n text-align: right;\n}\n\n.ionic_datepicker_popup .popup-body .show_nav .next_btn_section button {\n padding: 0;\n}\n\n.ionic_datepicker_popup .popup-body .button-clear {\n color: #009688;\n}\n\n.ionic_datepicker_popup .popup-buttons {\n padding: 0;\n min-height: 45px;\n}\n\n.ionic_datepicker_popup .popup-buttons button {\n background-color: #009688;\n border-radius: 0;\n margin-right: 1px;\n color: #ffffff;\n}\n\n.ionic_datepicker_popup .row + .row {\n padding: 0;\n}\n\n.ionic_datepicker_modal .header, .ionic_datepicker_modal .footer {\n background-color: #009688;\n}\n\n.ionic_datepicker_modal .header .title, .ionic_datepicker_modal .header .button, .ionic_datepicker_modal .footer .title, .ionic_datepicker_modal .footer .button {\n color: #ffffff;\n}\n\n.ionic_datepicker_modal .footer .button-block {\n margin: 0;\n}\n\n.ionic_datepicker_modal .today {\n border: 1px solid #009688;\n}\n\n.ionic_datepicker_modal .selected_date {\n background-color: #009688;\n color: #ffffff;\n font-weight: bold;\n}\n\n.ionic_datepicker_modal .pointer_events_none {\n pointer-events: none;\n color: #aaaaaa !important;\n}\n\n.ionic_datepicker_modal .select_section {\n padding: 1px 5px;\n}\n\n.ionic_datepicker_modal .button-clear {\n color: #009688;\n}\n\n.ionic_datepicker_modal .month_select, .ionic_datepicker_modal .year_select {\n border: none;\n border-bottom: 1px solid #009688;\n padding: 0;\n}\n\n.ionic_datepicker_modal .month_select .input-label, .ionic_datepicker_modal .year_select .input-label {\n padding: 2px 0;\n width: 0;\n}\n\n.ionic_datepicker_modal .month_select select, .ionic_datepicker_modal .year_select select {\n left: 10px;\n border: none;\n padding: 0 10px;\n}\n\n.ionic_datepicker_modal .month_select:after, .ionic_datepicker_modal .year_select:after {\n right: 5px;\n color: #009688;\n}\n\n.ionic_datepicker_modal .padding_left_5px {\n padding-left: 5px;\n}\n\n.ionic_datepicker_modal .padding_right_5px {\n padding-right: 5px;\n}\n\n.ionic_datepicker_modal .date_col {\n height: 50px;\n line-height: 50px;\n}\n\n.ionic_datepicker_modal .font_bold {\n font-weight: bold;\n}\n\n.ionic_datepicker_modal .font_22px {\n font-size: 22px;\n}\n\n.platform-android .ionic_datepicker_modal .bar .title.title-left {\n text-align: center;\n}\n\n.platform-android .ionic_datepicker_modal select {\n left: 25%;\n}\n\n.platform-ios .ionic_datepicker_modal select {\n left: 5%;\n}\n\n.date_col {\n cursor: pointer;\n}"),function(e){try{e=angular.module("ionic-datepicker.templates")}catch(t){e=angular.module("ionic-datepicker.templates",[])}e.run(["$templateCache",function(e){e.put("ionic-datepicker-modal.html",'

{{mainObj.titleLabel || selctedDateEpoch | date : mainObj.dateFormat}}

{{dayList[row + col].date}}
')}])}(),function(e){try{e=angular.module("ionic-datepicker.templates")}catch(t){e=angular.module("ionic-datepicker.templates",[])}e.run(["$templateCache",function(e){e.put("ionic-datepicker-popup.html",'
{{mainObj.titleLabel || selctedDateEpoch | date : mainObj.dateFormat}}
{{dayList[row + col].date}}
')}])}(),angular.module("ionic-datepicker",["ionic","ionic-datepicker.service","ionic-datepicker.provider","ionic-datepicker.templates"]),angular.module("ionic-datepicker.provider",[]).provider("ionicDatePicker",function(){var e={titleLabel:null,setLabel:"Set",todayLabel:"Today",closeLabel:"Close",inputDate:new Date,mondayFirst:!0,weeksList:["S","M","T","W","T","F","S"],monthsList:["Jan","Feb","March","April","May","June","July","Aug","Sept","Oct","Nov","Dec"],templateType:"popup",showTodayButton:!1,closeOnSelect:!1,disableWeekdays:[],selectMode:"day"};this.configDatePicker=function(t){angular.extend(e,t)},this.$get=["$rootScope","$ionicPopup","$ionicModal","IonicDatepickerService",function(t,n,a,o){function i(e){return e.setHours(0),e.setMinutes(0),e.setSeconds(0),e.setMilliseconds(0),e}function c(e){e.disabledDates&&0!==e.disabledDates.length?(u.disabledDates=[],angular.forEach(e.disabledDates,function(e,t){e=i(new Date(e)),u.disabledDates.push(e.getTime())})):u.disabledDates=[]}function d(e){e=i(e),u.currentDate=angular.copy(e);var t=new Date(e.getFullYear(),e.getMonth(),1).getDate(),n=new Date(e.getFullYear(),e.getMonth()+1,0).getDate();u.monthsNames=o.getMonthsNames(u.mainObj.monthsList),u.monthsList=o.getMonthsList(u.monthsNames,u.mainObj.from,u.mainObj.to),u.yearsList=o.getYearsList(u.mainObj.from,u.mainObj.to),u.dayList=[];var a,c;u.firstDayEpoch=i(new Date(e.getFullYear(),e.getMonth(),t)).getTime(),u.lastDayEpoch=i(new Date(e.getFullYear(),e.getMonth(),n)).getTime();for(var d=t;d<=n;d++)a=new Date(e.getFullYear(),e.getMonth(),d),c=a.getTime()u.toDate||u.mainObj.disableWeekdays.indexOf(a.getDay())>=0,u.dayList.push({date:a.getDate(),month:a.getMonth(),year:a.getFullYear(),day:a.getDay(),epoch:a.getTime(),disabled:c});var r=u.dayList[0].day-u.mainObj.mondayFirst;r=r<0?6:r;for(var l=0;la.getFullYear()||n.getFullYear()==a.getFullYear()&&n.getMonth()>a.getMonth()||(n.getFullYear()==a.getFullYear()&&n.getMonth()==a.getMonth()&&n.getDate()>a.getDate()&&n.setDate(a.getDate()),u.currentDate=n,u.data.currentMonth=g(u.currentDate.getMonth(),u.monthsList),u.data.currentYear=u.currentDate.getFullYear(),u.adjustSelctedDateEpoch(u.currentDate,!0),d(u.currentDate))};var g=function(e,t){for(var n=0;na&&(e=a),e};return u.dateSelected=function(e){e&&0!==Object.keys(e).length&&(u.adjustSelctedDateEpoch(e,!1),u.mainObj.closeOnSelect&&(u.mainObj.callback("day"==u.mainObj.selectMode?u.selctedDateEpoch:{start:u.selctedDateEpoch,end:u.selctedDateEpochEndWeek}),"popup"==u.mainObj.templateType.toLowerCase()?u.popup.close():p()))},u.setIonicDatePickerTodayDate=function(){var e=i(new Date);u.adjustSelctedDateEpoch(e,!0),d(e)},u.setIonicDatePickerDate=function(){u.mainObj.callback("day"==u.mainObj.selectMode?u.selctedDateEpoch:{start:u.selctedDateEpoch,end:u.selctedDateEpochEndWeek}),p()},u.adjustSelctedDateEpoch=function(e,t){var n,a=t?e.getTime():e.epoch;if("week"==u.mainObj.selectMode)n=new Date(a),u.mainObj.mondayFirst?n.setDate(n.getDate()-new Date(a).getDay()+1):n.setDate(n.getDate()-new Date(a).getDay()),a=n.getTime(),n.setDate(n.getDate()+6),u.selctedDateEpochEndWeek=n.getTime();else if("month"==u.mainObj.selectMode){n=new Date(a),n.setDate(1),a=n.getTime();var o=new Date(n.getYear(),n.getMonth()+1,0).getDate();n=new Date(n.getFullYear(),n.getMonth(),o),u.selctedDateEpochEndWeek=n.getTime()}u.selctedDateEpoch=a},u.monthChanged=function(e){var t=new Date(u.selctedDateEpoch),n=_(t.getDate(),e,t.getFullYear());u.currentDate=i(new Date(u.currentDate.getFullYear(),e,n)),u.adjustSelctedDateEpoch(u.currentDate,!0),d(u.currentDate)},u.yearChanged=function(e){var t=new Date(u.selctedDateEpoch),n=_(t.getDate(),t.getMonth(),e);u.currentDate=i(new Date(e,u.currentDate.getMonth(),n)),u.adjustSelctedDateEpoch(u.currentDate,!0),d(u.currentDate)},a.fromTemplateUrl("ionic-datepicker-modal.html",{scope:u,animation:"slide-in-up"}).then(function(e){u.modal=e}),u.$on("$destroy",function(){u.modal.remove()}),u.closeIonicDatePickerModal=function(){p()},s.openDatePicker=function(t){var a=[];delete u.fromDate,delete u.toDate,u.mainObj=angular.extend({},e,t),u.mainObj.from&&(u.fromDate=i(new Date(u.mainObj.from)).getTime()),u.mainObj.to&&(u.toDate=i(new Date(u.mainObj.to)).getTime()),t.disableWeekdays&&e.disableWeekdays&&(u.mainObj.disableWeekdays=t.disableWeekdays.concat(e.disableWeekdays)),r(u.mainObj),a=[{text:u.mainObj.closeLabel,type:"button_close",onTap:function(e){console.log("ionic-datepicker popup closed.")}}],u.mainObj.showTodayButton&&a.push({text:u.mainObj.todayLabel,type:"button_today",onTap:function(e){var t=i(new Date);u.adjustSelctedDateEpoch(t,!0),d(t),e.preventDefault()}}),u.mainObj.closeOnSelect||a.push({text:u.mainObj.setLabel,type:"button_set",onTap:function(e){u.mainObj.callback("day"==u.mainObj.selectMode?u.selctedDateEpoch:{start:u.selctedDateEpoch,end:u.selctedDateEpochEndWeek})}}),"popup"==u.mainObj.templateType.toLowerCase()?u.popup=n.show({templateUrl:"ionic-datepicker-popup.html",scope:u,cssClass:"ionic_datepicker_popup",buttons:a}):l()},s}]}),angular.module("ionic-datepicker.service",[]).service("IonicDatepickerService",function(){this.getYearsList=function(e,t){var n=[],a=1900,o=2100;a=e?new Date(e).getFullYear():a,o=t?new Date(t).getFullYear():o;for(var i=a;i<=o;i++)n.push(i);return n},this.getMonthsList=function(e,t,n){var a=[],o=0,i=11;o=t?new Date(t).getMonth():o,i=n?new Date(n).getMonth():i;for(var c=0;c<=11;c++)c>=o&&c<=i&&a.push({value:c,text:e[c]});return a},this.getMonthsNames=function(e){return e&&12===e.length?e:["January","February","March","April","May","June","July","August","September","October","November","December"]}}); \ No newline at end of file +!function(e,t){var n=e.createElement("style");if(e.getElementsByTagName("head")[0].appendChild(n),n.styleSheet)n.styleSheet.disabled||(n.styleSheet.cssText=t);else try{n.innerHTML=t}catch(e){n.innerText=t}}(document,"/**/\n.padding_zero {\n padding: 0;\n}\n\n.ionic_datepicker_popup .font_bold {\n font-weight: bold;\n}\n\n.ionic_datepicker_popup .padding_top_zero {\n padding-top: 0;\n}\n\n.ionic_datepicker_popup .padding_left_5px {\n padding-left: 5px;\n}\n\n.ionic_datepicker_popup .padding_right_5px {\n padding-right: 5px;\n}\n\n.ionic_datepicker_popup .month_year_section {\n padding: 5px 0;\n}\n\n.ionic_datepicker_popup .calendar_grid {\n height: 215px;\n}\n\n.ionic_datepicker_popup .calendar_grid .weeks_row {\n padding: 0;\n}\n\n.ionic_datepicker_popup .today {\n border: 1px solid #009688;\n border-radius: 50%;\n}\n\n.ionic_datepicker_popup .selected_date {\n background-color: #009688;\n border-radius: 50%;\n color: #ffffff;\n font-weight: bold;\n}\n\n.ionic_datepicker_popup .popup-head {\n background-color: #009688;\n display: none;\n}\n\n.ionic_datepicker_popup .popup-head .popup-title {\n color: #ffffff;\n}\n\n.ionic_datepicker_popup .popup-head .popup-sub-title {\n color: #ffffff;\n}\n\n.ionic_datepicker_popup .popup-body {\n background-color: #ffffff;\n}\n\n.ionic_datepicker_popup .popup-body .selected_date_full {\n background-color: #009688;\n margin: -10px -10px 0 -10px;\n height: 45px;\n text-align: center;\n font-weight: bold;\n color: #ffffff;\n line-height: 45px;\n font-size: 18px;\n}\n\n.ionic_datepicker_popup .popup-body .select_section {\n padding: 1px 5px;\n}\n\n.ionic_datepicker_popup .popup-body .pointer_events_none {\n pointer-events: none;\n color: #aaaaaa !important;\n}\n\n.ionic_datepicker_popup .popup-body .month_select, .ionic_datepicker_popup .popup-body .year_select {\n border: none;\n border-bottom: 1px solid #009688;\n padding: 0;\n}\n\n.ionic_datepicker_popup .popup-body .month_select .input-label, .ionic_datepicker_popup .popup-body .year_select .input-label {\n padding: 2px 0;\n width: 0;\n}\n\n.ionic_datepicker_popup .popup-body .month_select select, .ionic_datepicker_popup .popup-body .year_select select {\n left: 10px;\n border: none;\n padding: 0;\n}\n\n.ionic_datepicker_popup .popup-body .month_select:after, .ionic_datepicker_popup .popup-body .year_select:after {\n right: 5px;\n color: #009688;\n}\n\n.ionic_datepicker_popup .popup-body .show_nav {\n padding: 5px 0 0 0;\n}\n\n.ionic_datepicker_popup .popup-body .show_nav .prev_btn_section {\n padding: 5px 0;\n text-align: left;\n}\n\n.ionic_datepicker_popup .popup-body .show_nav .prev_btn_section button {\n padding: 0;\n}\n\n.ionic_datepicker_popup .popup-body .show_nav .next_btn_section {\n padding: 5px 0;\n text-align: right;\n}\n\n.ionic_datepicker_popup .popup-body .show_nav .next_btn_section button {\n padding: 0;\n}\n\n.ionic_datepicker_popup .popup-body .button-clear {\n color: #009688;\n}\n\n.ionic_datepicker_popup .popup-buttons {\n padding: 0;\n min-height: 45px;\n}\n\n.ionic_datepicker_popup .popup-buttons button {\n background-color: #009688;\n border-radius: 0;\n margin-right: 1px;\n color: #ffffff;\n}\n\n.ionic_datepicker_popup .row + .row {\n padding: 0;\n}\n\n.ionic_datepicker_modal .header, .ionic_datepicker_modal .footer {\n background-color: #009688;\n}\n\n.ionic_datepicker_modal .header .title, .ionic_datepicker_modal .header .button, .ionic_datepicker_modal .footer .title, .ionic_datepicker_modal .footer .button {\n color: #ffffff;\n}\n\n.ionic_datepicker_modal .footer .button-block {\n margin: 0;\n}\n\n.ionic_datepicker_modal .today {\n border: 1px solid #009688;\n}\n\n.ionic_datepicker_modal .selected_date {\n background-color: #009688;\n color: #ffffff;\n font-weight: bold;\n}\n\n.ionic_datepicker_modal .pointer_events_none {\n pointer-events: none;\n color: #aaaaaa !important;\n}\n\n.ionic_datepicker_modal .select_section {\n padding: 1px 5px;\n}\n\n.ionic_datepicker_modal .button-clear {\n color: #009688;\n}\n\n.ionic_datepicker_modal .month_select, .ionic_datepicker_modal .year_select {\n border: none;\n border-bottom: 1px solid #009688;\n padding: 0;\n}\n\n.ionic_datepicker_modal .month_select .input-label, .ionic_datepicker_modal .year_select .input-label {\n padding: 2px 0;\n width: 0;\n}\n\n.ionic_datepicker_modal .month_select select, .ionic_datepicker_modal .year_select select {\n left: 10px;\n border: none;\n padding: 0 10px;\n}\n\n.ionic_datepicker_modal .month_select:after, .ionic_datepicker_modal .year_select:after {\n right: 5px;\n color: #009688;\n}\n\n.ionic_datepicker_modal .padding_left_5px {\n padding-left: 5px;\n}\n\n.ionic_datepicker_modal .padding_right_5px {\n padding-right: 5px;\n}\n\n.ionic_datepicker_modal .date_col {\n height: 50px;\n line-height: 50px;\n}\n\n.ionic_datepicker_modal .font_bold {\n font-weight: bold;\n}\n\n.ionic_datepicker_modal .font_22px {\n font-size: 22px;\n}\n\n.platform-android .ionic_datepicker_modal .bar .title.title-left {\n text-align: center;\n}\n\n.platform-android .ionic_datepicker_modal select {\n left: 25%;\n}\n\n.platform-ios .ionic_datepicker_modal select {\n left: 5%;\n}\n\n.date_col {\n cursor: pointer;\n}"),function(e){try{e=angular.module("ionic-datepicker.templates")}catch(t){e=angular.module("ionic-datepicker.templates",[])}e.run(["$templateCache",function(e){e.put("ionic-datepicker-modal.html",'

{{mainObj.titleLabel || selctedDateEpoch | date : mainObj.dateFormat}}

{{dayList[row + col].date}}
')}])}(),function(e){try{e=angular.module("ionic-datepicker.templates")}catch(t){e=angular.module("ionic-datepicker.templates",[])}e.run(["$templateCache",function(e){e.put("ionic-datepicker-popup.html",'
{{mainObj.titleLabel || selctedDateEpoch | date : mainObj.dateFormat}}
{{dayList[row + col].date}}
')}])}(),angular.module("ionic-datepicker",["ionic","ionic-datepicker.service","ionic-datepicker.provider","ionic-datepicker.templates"]),angular.module("ionic-datepicker.provider",[]).provider("ionicDatePicker",function(){var e={titleLabel:null,setLabel:"Set",todayLabel:"Today",closeLabel:"Close",inputDate:new Date,mondayFirst:!0,weeksList:["S","M","T","W","T","F","S"],monthsList:["Jan","Feb","March","April","May","June","July","Aug","Sept","Oct","Nov","Dec"],templateType:"popup",showTodayButton:!1,closeOnSelect:!1,disableWeekdays:[],selectMode:"day"};this.configDatePicker=function(t){angular.extend(e,t)},this.$get=["$rootScope","$ionicPopup","$ionicModal","IonicDatepickerService",function(t,n,a,o){function i(e){return e.setHours(0),e.setMinutes(0),e.setSeconds(0),e.setMilliseconds(0),e}function c(e){e.disabledDates&&0!==e.disabledDates.length?(u.disabledDates=[],angular.forEach(e.disabledDates,function(e,t){e=i(new Date(e)),u.disabledDates.push(e.getTime())})):u.disabledDates=[]}function l(e){e=i(e),u.currentDate=angular.copy(e);var t=new Date(e.getFullYear(),e.getMonth(),1).getDate(),n=new Date(e.getFullYear(),e.getMonth()+1,0).getDate();u.monthsNames=o.getMonthsNames(u.mainObj.monthsList),u.monthsList=o.getMonthsList(u.monthsNames,u.mainObj.from,u.mainObj.to),u.yearsList=o.getYearsList(u.mainObj.from,u.mainObj.to),u.dayList=[];var a,c;u.firstDayEpoch=i(new Date(e.getFullYear(),e.getMonth(),t)).getTime(),u.lastDayEpoch=i(new Date(e.getFullYear(),e.getMonth(),n)).getTime();for(var l=t;l<=n;l++)a=new Date(e.getFullYear(),e.getMonth(),l),c=a.getTime()u.toDate||u.mainObj.disableWeekdays.indexOf(a.getDay())>=0,u.dayList.push({date:a.getDate(),month:a.getMonth(),year:a.getFullYear(),day:a.getDay(),epoch:a.getTime(),disabled:c});var d=u.dayList[0].day-u.mainObj.mondayFirst;d=d<0?6:d;for(var r=0;ra.getFullYear()||n.getFullYear()==a.getFullYear()&&n.getMonth()>a.getMonth()||(n.getFullYear()==a.getFullYear()&&n.getMonth()==a.getMonth()&&n.getDate()>a.getDate()&&n.setDate(a.getDate()),u.currentDate=n,u.data.currentMonth=g(u.currentDate.getMonth(),u.monthsList),u.data.currentYear=u.currentDate.getFullYear(),u.adjustSelctedDateEpoch(u.currentDate,!0),l(u.currentDate))};var g=function(e,t){for(var n=0;na&&(e=a),e};return u.dateSelected=function(e){e&&0!==Object.keys(e).length&&(u.adjustSelctedDateEpoch(e,!1),u.mainObj.closeOnSelect&&(u.mainObj.callback("day"==u.mainObj.selectMode?u.selctedDateEpoch:{start:u.selctedDateEpoch,end:u.selctedDateEpochEndWeek}),"popup"==u.mainObj.templateType.toLowerCase()?u.popup.close():p()))},u.setIonicDatePickerTodayDate=function(){var e=i(new Date);u.adjustSelctedDateEpoch(e,!0),l(e)},u.setIonicDatePickerDate=function(){u.mainObj.callback("day"==u.mainObj.selectMode?u.selctedDateEpoch:{start:u.selctedDateEpoch,end:u.selctedDateEpochEndWeek}),p()},u.adjustSelctedDateEpoch=function(e,t){var n,a=t?e.getTime():e.epoch;if("week"==u.mainObj.selectMode)n=new Date(a),u.mainObj.mondayFirst?n.setDate(n.getDate()-new Date(a).getDay()+1):n.setDate(n.getDate()-new Date(a).getDay()),a=n.getTime(),n.setDate(n.getDate()+6),u.selctedDateEpochEndWeek=n.getTime();else if("month"==u.mainObj.selectMode){n=new Date(a),n.setDate(1),a=n.getTime();var o=new Date(n.getYear(),n.getMonth()+1,0).getDate();n=new Date(n.getFullYear(),n.getMonth(),o),u.selctedDateEpochEndWeek=n.getTime()}u.selctedDateEpoch=a},u.monthChanged=function(e){var t=new Date(u.selctedDateEpoch),n=_(t.getDate(),e,t.getFullYear()),a=i(new Date(u.currentDate.getFullYear(),e,n)),o=new Date(u.toDate);if(!(a.getFullYear()>o.getFullYear()||a.getFullYear()==o.getFullYear()&&a.getMonth()>o.getMonth())){a.getFullYear()==o.getFullYear()&&a.getMonth()==o.getMonth()&&a.getDate()>o.getDate()&&a.setDate(o.getDate());var c=new Date(u.fromDate);a.getFullYear()o.getFullYear()||a.getFullYear()==o.getFullYear()&&a.getMonth()>o.getMonth())){a.getFullYear()==o.getFullYear()&&a.getMonth()==o.getMonth()&&a.getDate()>o.getDate()&&a.setDate(o.getDate());var c=new Date(u.fromDate);a.getFullYear()=o&&c<=i&&a.push({value:c,text:e[c]});return a},this.getMonthsNames=function(e){return e&&12===e.length?e:["January","February","March","April","May","June","July","August","September","October","November","December"]}}); \ No newline at end of file diff --git a/src/ionic-datepicker.provider.js b/src/ionic-datepicker.provider.js index 3906b49..3cd4cd0 100644 --- a/src/ionic-datepicker.provider.js +++ b/src/ionic-datepicker.provider.js @@ -245,19 +245,68 @@ angular.module('ionic-datepicker.provider', []) var newDay = getAcceptableDay(selectedDate.getDate(), monthNumber, selectedDate.getFullYear()); - $scope.currentDate = resetHMSM(new Date($scope.currentDate.getFullYear(), monthNumber, newDay)); + + var newDate = resetHMSM(new Date($scope.currentDate.getFullYear(), monthNumber, newDay)); + + var toDateTmp = new Date($scope.toDate); + if (newDate.getFullYear() > toDateTmp.getFullYear() + || (newDate.getFullYear() == toDateTmp.getFullYear() && newDate.getMonth() > toDateTmp.getMonth())) + return; + + if((newDate.getFullYear() == toDateTmp.getFullYear() && newDate.getMonth() == toDateTmp.getMonth())) { + if(newDate.getDate() > toDateTmp.getDate()) { + newDate.setDate(toDateTmp.getDate()); + } + } + + var fromDateTmp = new Date($scope.fromDate); + if (newDate.getFullYear() < fromDateTmp.getFullYear() + || (newDate.getFullYear() == fromDateTmp.getFullYear() && newDate.getMonth() < fromDateTmp.getMonth())) + return; + + if((newDate.getFullYear() == fromDateTmp.getFullYear() && newDate.getMonth() == fromDateTmp.getMonth())) { + if(newDate.getDate() < fromDateTmp.getDate()) { + newDate.setDate(fromDateTmp.getDate()); + } + } + + $scope.currentDate = newDate; $scope.adjustSelctedDateEpoch($scope.currentDate, true); refreshDateList($scope.currentDate); }; //Year changed $scope.yearChanged = function (year) { - var selectedDate = new Date($scope.selctedDateEpoch); - var newDay = getAcceptableDay(selectedDate.getDate(), + var selectedDate = new Date($scope.selctedDateEpoch); + var newDay = getAcceptableDay(selectedDate.getDate(), selectedDate.getMonth(), year); - $scope.currentDate = resetHMSM(new Date(year, $scope.currentDate.getMonth(), newDay)); - $scope.adjustSelctedDateEpoch($scope.currentDate, true); + + var newDate = resetHMSM(new Date(year, $scope.currentDate.getMonth(), newDay)); + + var toDateTmp = new Date($scope.toDate); + if (newDate.getFullYear() > toDateTmp.getFullYear() + || (newDate.getFullYear() == toDateTmp.getFullYear() && newDate.getMonth() > toDateTmp.getMonth())) + return; + + if((newDate.getFullYear() == toDateTmp.getFullYear() && newDate.getMonth() == toDateTmp.getMonth())) { + if(newDate.getDate() > toDateTmp.getDate()) { + newDate.setDate(toDateTmp.getDate()); + } + } + + var fromDateTmp = new Date($scope.fromDate); + if (newDate.getFullYear() < fromDateTmp.getFullYear() + || (newDate.getFullYear() == fromDateTmp.getFullYear() && newDate.getMonth() < fromDateTmp.getMonth())) + return; + + if((newDate.getFullYear() == fromDateTmp.getFullYear() && newDate.getMonth() == fromDateTmp.getMonth())) { + if(newDate.getDate() < fromDateTmp.getDate()) { + newDate.setDate(fromDateTmp.getDate()); + } + } + + $scope.currentDate = newDate;$scope.adjustSelctedDateEpoch($scope.currentDate, true); refreshDateList($scope.currentDate); }; diff --git a/test/www/index.html b/test/www/index.html index 4509800..d0c747b 100644 --- a/test/www/index.html +++ b/test/www/index.html @@ -107,6 +107,9 @@

Test of ionic date picker

Enable from March 12, 2017 to October 18, 2017
+
+ Enable from March 12, 2017 to October 18, 2018 +
diff --git a/test/www/js/controllers.js b/test/www/js/controllers.js index 8268562..f2f0176 100644 --- a/test/www/js/controllers.js +++ b/test/www/js/controllers.js @@ -41,10 +41,14 @@ angular.module('starter.controllers', []) // from 03-01-2017 to 08-31-2017 ipObj1.from = new Date(2017, 2, 1); ipObj1.to = new Date(2017, 7, 31); - } else { + } else if($scope.options.disableDates == "special") { // from 03-12-2017 to 10-18-2017 ipObj1.from = new Date(2017, 2, 12); ipObj1.to = new Date(2017, 9, 18); + } else if($scope.options.disableDates == "special2") { + // from 03-12-2017 to 10-18-2018 + ipObj1.from = new Date(2017, 2, 12); + ipObj1.to = new Date(2018, 9, 18); } ionicDatePicker.openDatePicker(ipObj1); diff --git a/test_original_datepicker/www/index.html b/test_original_datepicker/www/index.html index bbe22ff..3709494 100644 --- a/test_original_datepicker/www/index.html +++ b/test_original_datepicker/www/index.html @@ -107,6 +107,9 @@

Test of original project's ionic date picker

Enable from March 12, 2017 to October 18, 2017
+
+ Enable from March 12, 2017 to October 18, 2018 +
diff --git a/test_original_datepicker/www/js/controllers.js b/test_original_datepicker/www/js/controllers.js index 8268562..f2f0176 100644 --- a/test_original_datepicker/www/js/controllers.js +++ b/test_original_datepicker/www/js/controllers.js @@ -41,10 +41,14 @@ angular.module('starter.controllers', []) // from 03-01-2017 to 08-31-2017 ipObj1.from = new Date(2017, 2, 1); ipObj1.to = new Date(2017, 7, 31); - } else { + } else if($scope.options.disableDates == "special") { // from 03-12-2017 to 10-18-2017 ipObj1.from = new Date(2017, 2, 12); ipObj1.to = new Date(2017, 9, 18); + } else if($scope.options.disableDates == "special2") { + // from 03-12-2017 to 10-18-2018 + ipObj1.from = new Date(2017, 2, 12); + ipObj1.to = new Date(2018, 9, 18); } ionicDatePicker.openDatePicker(ipObj1);