Skip to content

Commit

Permalink
fixed batch invalid date
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunlumbcgov committed May 7, 2024
1 parent 32bd705 commit 906162e
Showing 1 changed file with 37 additions and 9 deletions.
46 changes: 37 additions & 9 deletions frontend/src/components/Batch/Batch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1111,15 +1111,29 @@ export default {
return {
gradDateFrom: {
isDateInvalid: helpers.withMessage(
"Enter a valid start date",
"Enter a valid end date",
(value) => {
const regex = /^\d{4}-\d{2}-\d{2}$/;
if (
this.batch.details["gradDate"] == "Date Range" &&
!regex.test(this.gradDateFrom)
this.batch.details["gradDate"] == "Date Range" &&
regex.test(value) // Check if the date format is valid
) {
return false;
} else return true;
// Split the date string into year, month, and day parts
const parts = value.split('-');
const year = parseInt(parts[0]);
const month = parseInt(parts[1]) - 1; // Months are zero-indexed
const day = parseInt(parts[2]);
// Create a Date object and check if it represents a valid date
const date = new Date(year, month, day);
return (
date.getFullYear() === year &&
date.getMonth() === month &&
date.getDate() === day
);
} else {
return false;
}
}
),
isValidFromDate: helpers.withMessage(
Expand All @@ -1144,12 +1158,26 @@ export default {
"Enter a valid end date",
(value) => {
const regex = /^\d{4}-\d{2}-\d{2}$/;
if (
if (
this.batch.details["gradDate"] == "Date Range" &&
!regex.test(value)
) {
regex.test(value) // Check if the date format is valid
) {
// Split the date string into year, month, and day parts
const parts = value.split('-');
const year = parseInt(parts[0]);
const month = parseInt(parts[1]) - 1; // Months are zero-indexed
const day = parseInt(parts[2]);
// Create a Date object and check if it represents a valid date
const date = new Date(year, month, day);
return (
date.getFullYear() === year &&
date.getMonth() === month &&
date.getDate() === day
);
} else {
return false;
} else return true;
}
}
),
isValidFromDate: helpers.withMessage(
Expand Down

0 comments on commit 906162e

Please sign in to comment.