-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
103 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import moment from 'moment'; | ||
import * as yup from 'yup'; | ||
|
||
const getBaseDateStringValidator = () => { | ||
return yup.string().test('is-valid-date', 'Invalid date', (value) => { | ||
if (!value) { | ||
return true; | ||
} | ||
|
||
return moment(value, 'YYYY-MM-DD', true).isValid(); | ||
}); | ||
}; | ||
|
||
export const getStartDateStringValidator = () => { | ||
return getBaseDateStringValidator(); | ||
}; | ||
|
||
export const getEndDateStringValidator = (startDateName: string) => { | ||
return getBaseDateStringValidator().test( | ||
'is-end-date-after-start-date', | ||
'End Date is before Start Date', | ||
function (value) { | ||
if (!value) { | ||
// end date is null, no validation required | ||
return true; | ||
} | ||
|
||
if (!moment(this.parent[startDateName], 'YYYY-MM-DD', true).isValid()) { | ||
// cant validate end_date if start_date is invalid | ||
return true; | ||
} | ||
|
||
// compare valid start and end dates | ||
return moment(this.parent.start_date, 'YYYY-MM-DD').isBefore(moment(value, 'YYYY-MM-DD')); | ||
} | ||
); | ||
}; |