Add explanation about maxStartDate and minEndDate,
Refactor calc max and min functions
This commit is contained in:
parent
f840bbb941
commit
a8635e8c8b
@ -8,6 +8,12 @@ import { makeTestWrapper } from '../../test_utils/component_test_helpers'
|
|||||||
const PopDateRangeWrapper = makeTestWrapper({
|
const PopDateRangeWrapper = makeTestWrapper({
|
||||||
components: { PopDateRange },
|
components: { PopDateRange },
|
||||||
templatePath: 'pop_date_range.html',
|
templatePath: 'pop_date_range.html',
|
||||||
|
data: function() {
|
||||||
|
return {
|
||||||
|
initialMinStartDate: '2019-09-14',
|
||||||
|
initialMaxEndDate: '2022-09-14',
|
||||||
|
}
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('PopDateRange Test', () => {
|
describe('PopDateRange Test', () => {
|
||||||
|
@ -27,45 +27,51 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
data: function() {
|
data: function() {
|
||||||
var start = !!this.initialStartDate ? new Date(this.initialStartDate) : null
|
let start = !!this.initialStartDate
|
||||||
var end = !!this.initialEndDate ? new Date(this.initialEndDate) : null
|
? new Date(this.initialStartDate)
|
||||||
var contractStart = new Date(this.initialMinStartDate)
|
: false
|
||||||
var contractEnd = new Date(this.initialMaxEndDate)
|
let contractStart = new Date(this.initialMinStartDate)
|
||||||
|
let minEndDate = start && start > contractStart ? start : contractStart
|
||||||
|
|
||||||
|
let end = !!this.initialEndDate ? new Date(this.initialEndDate) : false
|
||||||
|
let contractEnd = new Date(this.initialMaxEndDate)
|
||||||
|
let maxStartDate = end && end < contractEnd ? end : contractEnd
|
||||||
|
|
||||||
|
// the maxStartDate and minEndDate change based on user input:
|
||||||
|
// the latest date the start can be is the PoP end date
|
||||||
|
// the earliest date the end can be is the PoP start date
|
||||||
|
// if the form is initialized with out a PoP, the maxStartDate and minEndDate
|
||||||
|
// default to the contract dates
|
||||||
return {
|
return {
|
||||||
maxStartDate: this.calcMaxStartDate(end, contractEnd),
|
maxStartDate: maxStartDate,
|
||||||
minEndDate: this.calcMinEndDate(start, contractStart),
|
minEndDate: minEndDate,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
handleDateChange: function(event) {
|
handleDateChange: function(event) {
|
||||||
if (event.name.includes(START_DATE)) {
|
if (event.name.includes(START_DATE) && event.valid) {
|
||||||
if (event.valid != undefined && event.valid) {
|
let date = new Date(event.value)
|
||||||
var date = new Date(event.value)
|
|
||||||
this.minEndDate = this.calcMinEndDate(date)
|
this.minEndDate = this.calcMinEndDate(date)
|
||||||
}
|
} else if (event.name.includes(END_DATE) && event.valid) {
|
||||||
} else if (event.name.includes(END_DATE)) {
|
let date = new Date(event.value)
|
||||||
if (event.valid != undefined && event.valid) {
|
|
||||||
var date = new Date(event.value)
|
|
||||||
this.maxStartDate = this.calcMaxStartDate(date)
|
this.maxStartDate = this.calcMaxStartDate(date)
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
calcMaxStartDate: function(date) {
|
||||||
|
if (!!date && date < this.maxStartDate) {
|
||||||
|
return date
|
||||||
|
} else {
|
||||||
|
return this.maxStartDate
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
calcMaxStartDate: function(date, end = this.maxStartDate) {
|
calcMinEndDate: function(date) {
|
||||||
if (!!date && date < end) {
|
if (!!date && date > this.minEndDate) {
|
||||||
return date
|
return date
|
||||||
} else {
|
} else {
|
||||||
return end
|
return this.minEndDate
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
calcMinEndDate: function(date, start = this.minEndDate) {
|
|
||||||
if (!!date && date > start) {
|
|
||||||
return date
|
|
||||||
} else {
|
|
||||||
return start
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user