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) const component = new Vue(PopDateRange)
it('should calculate the max start date', () => { 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') const date = new Date('2019-12-31')
expect(component.calcMaxStartDate(date)).toEqual(date) expect(component.calcMaxStartDate(date)).toEqual(date)
}) })
it('should calculate the min end 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') const date = new Date('2020-02-02')
expect(component.calcMinEndDate(date)).toEqual(date) expect(component.calcMinEndDate(date)).toEqual(date)
}) })

View File

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