Skip to content

Commit ed1b552

Browse files
Merge pull request charliekassel#289 from g-wilson/master
Classes on Day elements for highlight-start and highlight-end
2 parents a7f468d + 8253224 commit ed1b552

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/components/Datepicker.vue

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ export default {
263263
isSelected: this.isSelectedDate(dObj),
264264
isDisabled: this.isDisabledDate(dObj),
265265
isHighlighted: this.isHighlightedDate(dObj),
266+
isHighlightStart: this.isHighlightStart(dObj),
267+
isHighlightEnd: this.isHighlightEnd(dObj),
266268
isToday: dObj.toDateString() === (new Date()).toDateString(),
267269
isWeekend: dObj.getDay() === 0 || dObj.getDay() === 6,
268270
isSaturday: dObj.getDay() === 6,
@@ -620,6 +622,34 @@ export default {
620622
return highlighted
621623
},
622624
625+
/**
626+
* Whether a day is highlighted and it is the first date
627+
* in the highlighted range of dates
628+
* @param {Date}
629+
* @return {Boolean}
630+
*/
631+
isHighlightStart (date) {
632+
return this.isHighlightedDate(date) &&
633+
(this.highlighted.from instanceof Date) &&
634+
(this.highlighted.from.getFullYear() === date.getFullYear()) &&
635+
(this.highlighted.from.getMonth() === date.getMonth()) &&
636+
(this.highlighted.from.getDate() === date.getDate())
637+
},
638+
639+
/**
640+
* Whether a day is highlighted and it is the first date
641+
* in the highlighted range of dates
642+
* @param {Date}
643+
* @return {Boolean}
644+
*/
645+
isHighlightEnd (date) {
646+
return this.isHighlightedDate(date) &&
647+
(this.highlighted.to instanceof Date) &&
648+
(this.highlighted.to.getFullYear() === date.getFullYear()) &&
649+
(this.highlighted.to.getMonth() === date.getMonth()) &&
650+
(this.highlighted.to.getDate() === date.getDate())
651+
},
652+
623653
/**
624654
* Helper
625655
* @param {mixed} prop
@@ -754,7 +784,9 @@ export default {
754784
'today': day.isToday,
755785
'weekend': day.isWeekend,
756786
'sat': day.isSaturday,
757-
'sun': day.isSunday
787+
'sun': day.isSunday,
788+
'highlight-start': day.isHighlightStart,
789+
'highlight-end': day.isHighlightEnd
758790
}
759791
},
760792

test/unit/specs/Datepicker.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,18 @@ describe('Datepicker highlight date', () => {
476476
expect(vm.isHighlightedDate(new Date(2016, 9, 2))).to.equal(true)
477477
expect(vm.isHighlightedDate(new Date(2016, 9, 3))).to.equal(false)
478478
})
479+
480+
it('should detect the first date of the highlighted dates', () => {
481+
expect(vm.isHighlightStart(new Date(2016, 12, 4))).to.equal(true)
482+
expect(vm.isHighlightStart(new Date(2016, 12, 3))).to.equal(false)
483+
expect(vm.isHighlightStart(new Date(2016, 12, 5))).to.equal(false)
484+
})
485+
486+
it('should detect the last date of the highlighted dates', () => {
487+
expect(vm.isHighlightEnd(new Date(2016, 12, 8))).to.equal(true)
488+
expect(vm.isHighlightEnd(new Date(2016, 12, 6))).to.equal(false)
489+
expect(vm.isHighlightEnd(new Date(2016, 12, 7))).to.equal(false)
490+
})
479491
})
480492

481493
describe('Datepicker with monday as first day of week', () => {

0 commit comments

Comments
 (0)