Get rid of unnecessary data in pop date range

This commit is contained in:
leigh-mil 2019-09-25 16:07:31 -04:00
parent c03820e53a
commit df5f4b9d3e
2 changed files with 10 additions and 18 deletions

View File

@ -14,13 +14,13 @@ describe('PopDateRange Test', () => {
const component = new Vue(PopDateRange)
it('should calculate the max start date', () => {
component.contractEnd = new Date('2020-01-01')
component.maxStartDate = new Date('2020-01-01')
const date = new Date('2019-12-31')
expect(component.calcMaxStartDate(date)).toEqual(date)
})
it('should calculate the min end date', () => {
component.contractStart = new Date('2020-01-01')
component.minEndDate = new Date('2020-01-01')
const date = new Date('2020-02-02')
expect(component.calcMinEndDate(date)).toEqual(date)
})

View File

@ -33,35 +33,27 @@ export default {
var contractEnd = new Date(this.initialMaxEndDate)
return {
startDate: start,
endDate: end,
startValid: false,
endValid: false,
maxStartDate: this.calcMaxStartDate(end, contractEnd),
minEndDate: this.calcMinEndDate(start, contractStart),
contractStart: contractStart,
contractEnd: contractEnd,
}
},
methods: {
handleDateChange: function(event) {
if (event.name.includes(START_DATE)) {
if (!!event.value) this.startDate = new Date(event.value)
if (event.valid != undefined) this.startValid = event.valid
if (this.startValid) {
this.minEndDate = this.calcMinEndDate(this.startDate)
if (event.valid != undefined && event.valid) {
var date = new Date(event.value)
this.minEndDate = this.calcMinEndDate(date)
}
} else if (event.name.includes(END_DATE)) {
if (!!event.value) this.endDate = new Date(event.value)
if (event.valid != undefined) this.endValid = event.valid
if (this.endValid) {
this.maxStartDate = this.calcMaxStartDate(this.endDate)
if (event.valid != undefined && event.valid ) {
var date = new Date(event.value)
this.maxStartDate = this.calcMaxStartDate(date)
}
}
},
calcMaxStartDate: function(date, end = this.contractEnd) {
calcMaxStartDate: function(date, end = this.maxStartDate) {
if (!!date && date < end) {
return date
} else {
@ -69,7 +61,7 @@ export default {
}
},
calcMinEndDate: function(date, start = this.contractStart) {
calcMinEndDate: function(date, start = this.minEndDate) {
if (!!date && date > start) {
return date
} else {