Skip to content
This repository was archived by the owner on Mar 14, 2024. It is now read-only.

Commit 0be4bf2

Browse files
author
Irfan Maulana
committed
📆 fix year that wrong when click next, issue bliblidotcom#25, bliblidotcom#26
1 parent 2a3c712 commit 0be4bf2

File tree

7 files changed

+127
-83
lines changed

7 files changed

+127
-83
lines changed

dist/vue-rangedate-picker.common.js

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* vue-rangedate-picker v0.2.3
2+
* vue-rangedate-picker v0.2.4
33
* (c) 2017 hidayat.febiansyah
44
* Released under the MIT License.
55
*/
@@ -537,14 +537,22 @@ var __vue_module__ = {
537537
isOpen: false,
538538
presetActive: '',
539539
showMonth: false,
540-
activeMonthStart: this.startActiveMonth
540+
activeMonthStart: this.startActiveMonth,
541+
activeYearStart: this.startActiveYear,
542+
activeYearEnd: this.startActiveYear
541543
}
542544
},
543545
created: function created () {
544546
this.range = this.initRange || null;
545547
if (this.isCompact) {
546548
this.isOpen = true;
547549
}
550+
if (this.activeMonthStart === 11) { this.activeYearEnd += 1; }
551+
},
552+
watch: {
553+
startNextActiveMonth: function (value) {
554+
if (value === 0) { this.activeYearEnd += 1; }
555+
}
548556
},
549557
computed: {
550558
monthsLocale: function () {
@@ -557,16 +565,16 @@ var __vue_module__ = {
557565
return Object.assign({}, defaultStyle, this.style)
558566
},
559567
startMonthDay: function () {
560-
return new Date(this.startActiveYear, this.activeMonthStart, 1).getDay()
568+
return new Date(this.activeYearStart, this.activeMonthStart, 1).getDay()
561569
},
562570
startNextMonthDay: function () {
563-
return new Date(this.startActiveYear, this.startNextActiveMonth, 1).getDay()
571+
return new Date(this.activeYearStart, this.startNextActiveMonth, 1).getDay()
564572
},
565573
endMonthDate: function () {
566-
return new Date(this.startActiveYear, this.startNextActiveMonth, 0).getDate()
574+
return new Date(this.activeYearEnd, this.startNextActiveMonth, 0).getDate()
567575
},
568576
endNextMonthDate: function () {
569-
return new Date(this.startActiveYear, this.activeMonthStart + 2, 0).getDate()
577+
return new Date(this.activeYearEnd, this.activeMonthStart + 2, 0).getDate()
570578
},
571579
startNextActiveMonth: function () {
572580
return this.activeMonthStart >= 11 ? 0 : this.activeMonthStart + 1
@@ -627,7 +635,7 @@ var __vue_module__ = {
627635
} else {
628636
newData['end'] = null;
629637
}
630-
var resultDate = new Date(this.startActiveYear, activeMonth, result);
638+
var resultDate = new Date(this.activeYearStart, activeMonth, result);
631639
if (!this.isFirstChoice && resultDate < this.dateRange.start) {
632640
this.isFirstChoice = false;
633641
return { start: resultDate }
@@ -661,9 +669,9 @@ var __vue_module__ = {
661669

662670
var currDate = null;
663671
if (key === 'first') {
664-
currDate = new Date(this.startActiveYear, this.activeMonthStart, result);
672+
currDate = new Date(this.activeYearStart, this.activeMonthStart, result);
665673
} else {
666-
currDate = new Date(this.startActiveYear, this.startNextActiveMonth, result);
674+
currDate = new Date(this.activeYearEnd, this.startNextActiveMonth, result);
667675
}
668676
return (this.dateRange.start && this.dateRange.start.getTime() === currDate.getTime()) ||
669677
(this.dateRange.end && this.dateRange.end.getTime() === currDate.getTime())
@@ -674,29 +682,32 @@ var __vue_module__ = {
674682

675683
var currDate = null;
676684
if (key === 'first') {
677-
currDate = new Date(this.startActiveYear, this.activeMonthStart, result);
685+
currDate = new Date(this.activeYearStart, this.activeMonthStart, result);
678686
} else {
679-
currDate = new Date(this.startActiveYear, this.startNextActiveMonth, result);
687+
currDate = new Date(this.activeYearEnd, this.startNextActiveMonth, result);
680688
}
681689
return (this.dateRange.start && this.dateRange.start.getTime() < currDate.getTime()) &&
682690
(this.dateRange.end && this.dateRange.end.getTime() > currDate.getTime())
683691
},
684692
goPrevMonth: function goPrevMonth () {
685-
var prevMonth = new Date(this.startActiveYear, this.activeMonthStart, 0);
693+
var prevMonth = new Date(this.activeYearStart, this.activeMonthStart, 0);
686694
this.activeMonthStart = prevMonth.getMonth();
687-
this.startActiveYear = prevMonth.getFullYear();
695+
this.activeYearStart = prevMonth.getFullYear();
696+
this.activeYearEnd = prevMonth.getFullYear();
688697
},
689698
goNextMonth: function goNextMonth () {
690-
var nextMonth = new Date(this.startActiveYear, this.startNextActiveMonth, 1);
699+
var nextMonth = new Date(this.activeYearEnd, this.startNextActiveMonth, 1);
691700
this.activeMonthStart = nextMonth.getMonth();
692-
this.startActiveYear = nextMonth.getFullYear();
701+
this.activeYearStart = nextMonth.getFullYear();
702+
this.activeYearEnd = nextMonth.getFullYear();
693703
},
694704
updatePreset: function updatePreset (item) {
695705
this.presetActive = item.label;
696706
this.dateRange = item.dateRange;
697707
// update start active month
698708
this.activeMonthStart = this.dateRange.start.getMonth();
699-
this.startActiveYear = this.dateRange.start.getFullYear();
709+
this.activeYearStart = this.dateRange.start.getFullYear();
710+
this.activeYearEnd = this.dateRange.end.getFullYear();
700711
},
701712
setDateValue: function () {
702713
this.$emit('selected', this.dateRange);
@@ -707,8 +718,8 @@ var __vue_module__ = {
707718
}
708719
};
709720

710-
var __$__vue_module__ = Object.assign(__vue_module__, {render: function(){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"calendar-root"},[_c('div',{staticClass:"input-date",on:{"click":function($event){_vm.toggleCalendar();}}},[_vm._v(" "+_vm._s(_vm.getDateString(_vm.dateRange.start))+" - "+_vm._s(_vm.getDateString(_vm.dateRange.end)))]),_vm._v(" "),(_vm.isOpen)?_c('div',{staticClass:"calendar",class:{'calendar-mobile ': _vm.isCompact, 'calendar-right-to-left': _vm.isRighttoLeft}},[(!_vm.isCompact)?_c('div',{staticClass:"calendar-head"},[_c('h2',[_vm._v(_vm._s(_vm.captions.title))]),_vm._v(" "),_c('i',{staticClass:"close",on:{"click":function($event){_vm.toggleCalendar();}}})]):_vm._e(),_vm._v(" "),_c('div',{staticClass:"calendar-wrap"},[(_vm.showMonth)?_c('div',{staticClass:"calendar_month_left",class:{'calendar-left-mobile': _vm.isCompact}},[_c('div',{staticClass:"months-text"},[_c('i',{staticClass:"left",on:{"click":_vm.goPrevMonth}}),_vm._v(" "),(_vm.isCompact)?_c('i',{staticClass:"right",on:{"click":_vm.goNextMonth}}):_vm._e(),_vm._v(" "+_vm._s(_vm.monthsLocale[_vm.activeMonthStart] +' '+ _vm.startActiveYear))]),_vm._v(" "),_c('ul',{class:_vm.s.daysWeeks},_vm._l((_vm.shortDaysLocale),function(item){return _c('li',[_vm._v(_vm._s(item))])})),_vm._v(" "),_vm._l((6),function(r){return _c('ul',{class:[_vm.s.days]},_vm._l((_vm.numOfDays),function(i){return _c('li',{class:[( obj = {}, obj[_vm.s.daysSelected] = _vm.isDateSelected(r, i, 'first', _vm.startMonthDay, _vm.endMonthDate), obj[_vm.s.daysInRange] = _vm.isDateInRange(r, i, 'first', _vm.startMonthDay, _vm.endMonthDate), obj )],domProps:{"innerHTML":_vm._s(_vm.getDayCell(r, i, _vm.startMonthDay, _vm.endMonthDate))},on:{"click":function($event){_vm.selectFirstItem(r, i);}}})
711-
var obj;}))})],2):_vm._e(),_vm._v(" "),(!_vm.isCompact)?_c('div',{staticClass:"calendar_month_right"},[_c('div',{staticClass:"months-text"},[_vm._v(" "+_vm._s(_vm.monthsLocale[_vm.startNextActiveMonth] +' '+ _vm.startActiveYear)+" "),_c('i',{staticClass:"right",on:{"click":_vm.goNextMonth}})]),_vm._v(" "),_c('ul',{class:_vm.s.daysWeeks},_vm._l((_vm.shortDaysLocale),function(item){return _c('li',[_vm._v(_vm._s(item))])})),_vm._v(" "),_vm._l((6),function(r){return _c('ul',{class:[_vm.s.days]},_vm._l((_vm.numOfDays),function(i){return _c('li',{class:[( obj = {}, obj[_vm.s.daysSelected] = _vm.isDateSelected(r, i, 'second', _vm.startNextMonthDay, _vm.endNextMonthDate), obj[_vm.s.daysInRange] = _vm.isDateInRange(r, i, 'second', _vm.startNextMonthDay, _vm.endNextMonthDate), obj )],domProps:{"innerHTML":_vm._s(_vm.getDayCell(r, i, _vm.startNextMonthDay, _vm.endNextMonthDate))},on:{"click":function($event){_vm.selectSecondItem(r, i);}}})
721+
var __$__vue_module__ = Object.assign(__vue_module__, {render: function(){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"calendar-root"},[_c('div',{staticClass:"input-date",on:{"click":function($event){_vm.toggleCalendar();}}},[_vm._v(" "+_vm._s(_vm.getDateString(_vm.dateRange.start))+" - "+_vm._s(_vm.getDateString(_vm.dateRange.end)))]),_vm._v(" "),(_vm.isOpen)?_c('div',{staticClass:"calendar",class:{'calendar-mobile ': _vm.isCompact, 'calendar-right-to-left': _vm.isRighttoLeft}},[(!_vm.isCompact)?_c('div',{staticClass:"calendar-head"},[_c('h2',[_vm._v(_vm._s(_vm.captions.title))]),_vm._v(" "),_c('i',{staticClass:"close",on:{"click":function($event){_vm.toggleCalendar();}}})]):_vm._e(),_vm._v(" "),_c('div',{staticClass:"calendar-wrap"},[(_vm.showMonth)?_c('div',{staticClass:"calendar_month_left",class:{'calendar-left-mobile': _vm.isCompact}},[_c('div',{staticClass:"months-text"},[_c('i',{staticClass:"left",on:{"click":_vm.goPrevMonth}}),_vm._v(" "),(_vm.isCompact)?_c('i',{staticClass:"right",on:{"click":_vm.goNextMonth}}):_vm._e(),_vm._v(" "+_vm._s(_vm.monthsLocale[_vm.activeMonthStart] +' '+ _vm.activeYearStart))]),_vm._v(" "),_c('ul',{class:_vm.s.daysWeeks},_vm._l((_vm.shortDaysLocale),function(item){return _c('li',{key:item},[_vm._v(_vm._s(item))])})),_vm._v(" "),_vm._l((6),function(r){return _c('ul',{key:r,class:[_vm.s.days]},_vm._l((_vm.numOfDays),function(i){return _c('li',{key:i,class:[( obj = {}, obj[_vm.s.daysSelected] = _vm.isDateSelected(r, i, 'first', _vm.startMonthDay, _vm.endMonthDate), obj[_vm.s.daysInRange] = _vm.isDateInRange(r, i, 'first', _vm.startMonthDay, _vm.endMonthDate), obj )],domProps:{"innerHTML":_vm._s(_vm.getDayCell(r, i, _vm.startMonthDay, _vm.endMonthDate))},on:{"click":function($event){_vm.selectFirstItem(r, i);}}})
722+
var obj;}))})],2):_vm._e(),_vm._v(" "),(!_vm.isCompact)?_c('div',{staticClass:"calendar_month_right"},[_c('div',{staticClass:"months-text"},[_vm._v(" "+_vm._s(_vm.monthsLocale[_vm.startNextActiveMonth] +' '+ _vm.activeYearEnd)+" "),_c('i',{staticClass:"right",on:{"click":_vm.goNextMonth}})]),_vm._v(" "),_c('ul',{class:_vm.s.daysWeeks},_vm._l((_vm.shortDaysLocale),function(item){return _c('li',{key:item},[_vm._v(_vm._s(item))])})),_vm._v(" "),_vm._l((6),function(r){return _c('ul',{key:r,class:[_vm.s.days]},_vm._l((_vm.numOfDays),function(i){return _c('li',{key:i,class:[( obj = {}, obj[_vm.s.daysSelected] = _vm.isDateSelected(r, i, 'second', _vm.startNextMonthDay, _vm.endNextMonthDate), obj[_vm.s.daysInRange] = _vm.isDateInRange(r, i, 'second', _vm.startNextMonthDay, _vm.endNextMonthDate), obj )],domProps:{"innerHTML":_vm._s(_vm.getDayCell(r, i, _vm.startNextMonthDay, _vm.endNextMonthDate))},on:{"click":function($event){_vm.selectSecondItem(r, i);}}})
712723
var obj;}))})],2):_vm._e()]),_vm._v(" "),(!_vm.showMonth || !_vm.isCompact)?_c('div',{staticClass:"calendar-range",class:{'calendar-range-mobile ': _vm.isCompact}},[_c('ul',{staticClass:"calendar_preset"},[_vm._l((_vm.finalPresetRanges),function(item,idx){return _c('li',{key:idx,staticClass:"calendar_preset-ranges",class:{'active-preset': _vm.presetActive === item.label},on:{"click":function($event){_vm.updatePreset(item);}}},[_vm._v(" "+_vm._s(item.label)+" ")])}),_vm._v(" "),_c('li',[_c('button',{staticClass:"calendar-btn-apply",on:{"click":function($event){_vm.setDateValue();}}},[_vm._v(_vm._s(_vm.captions.ok_button))])])],2)]):_vm._e()]):_vm._e()])},staticRenderFns: [],_scopeId: 'data-v-5e837f70',});
713724
__$__vue_module__.prototype = __vue_module__.prototype;
714725

@@ -721,7 +732,7 @@ if (typeof window !== 'undefined' && window.Vue) {
721732
window.Vue.use(plugin);
722733
}
723734

724-
var version = '0.2.3';
735+
var version = '0.2.4';
725736

726737
exports['default'] = plugin;
727738
exports.RangedatePicker = __$__vue_module__;

0 commit comments

Comments
 (0)