Skip to content

Commit

Permalink
Enhance validation
Browse files Browse the repository at this point in the history
  • Loading branch information
insmac committed Jan 8, 2025
1 parent 4b6f2f8 commit 171b95d
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ export const DateTimePicker = ({
"string.empty": "Please enter a date or duration",
"string.invalidDate": "Date format or duration is invalid",
"string.toIsBeforeFrom": "To date must be after From date",
"string.dateInFuture": "Date cannot be in the future",
"string.dateInFuture": "Please set a date in the past or use `now`",
"string.fromIsAfterTo": "From date must be before To date",
}

const schema = Joi.object({
Expand All @@ -199,7 +200,9 @@ export const DateTimePicker = ({
return helpers.error("string.invalidDate")
} else if (
new Date(dateValue).getTime() >=
new Date(helpers.state.ancestors[0].dateTo).getTime()
new Date(
durationTokenToDate(helpers.state.ancestors[0].dateTo),
).getTime()
) {
return helpers.error("string.fromIsAfterTo")
} else if (new Date(dateValue).getTime() > new Date().getTime()) {
Expand All @@ -216,7 +219,9 @@ export const DateTimePicker = ({
return helpers.error("string.invalidDate")
} else if (
new Date(dateValue).getTime() <=
new Date(helpers.state.ancestors[0].dateFrom).getTime()
new Date(
durationTokenToDate(helpers.state.ancestors[0].dateFrom),
).getTime()
) {
return helpers.error("string.toIsBeforeFrom")
} else if (new Date(dateValue).getTime() > new Date().getTime()) {
Expand Down

0 comments on commit 171b95d

Please sign in to comment.