move date validationto helper in DonationBar validation

This commit is contained in:
mahula 2025-11-12 12:57:18 +01:00
parent 5f4e1d4434
commit 2254f25a16

View File

@ -68,29 +68,20 @@ if (props.target <= 0) {
throwError(`[DonationBar] Prop "target" must be > 0, received: ${props.target}`) throwError(`[DonationBar] Prop "target" must be > 0, received: ${props.target}`)
} }
const startDateRegex = /^\d{4}-\d{2}-\d{2}$/ const ISO_DATE_REGEX = /^\d{4}-\d{2}-\d{2}$/
if (!startDateRegex.test(props.startDate)) {
throwError(`[DonationBar] Prop "startDate" must be in ISO 8601 format (YYYY-MM-DD), received: ${props.startDate}`) const validateDate = (value, propName) => {
} if (!ISO_DATE_REGEX.test(value)) {
if (isNaN(new Date(props.startDate).getTime())) { throwError(`[DonationBar] Prop "${propName}" must be in ISO 8601 format (YYYY-MM-DD), received: ${value}`)
throwError(`[DonationBar] Prop "startDate" has invalid date value: ${props.startDate}`) }
if (isNaN(new Date(value).getTime())) {
throwError(`[DonationBar] Prop "${propName}" has invalid date value: ${value}`)
}
} }
const endDateRegex = /^\d{4}-\d{2}-\d{2}$/ validateDate(props.startDate, 'startDate')
if (!endDateRegex.test(props.endDate)) { validateDate(props.endDate, 'endDate')
throwError(`[DonationBar] Prop "endDate" must be in ISO 8601 format (YYYY-MM-DD), received: ${props.endDate}`) validateDate(props.asOfDate, 'asOfDate')
}
if (isNaN(new Date(props.endDate).getTime())) {
throwError(`[DonationBar] Prop "endDate" has invalid date value: ${props.endDate}`)
}
const asOfDateRegex = /^\d{4}-\d{2}-\d{2}$/
if (!asOfDateRegex.test(props.asOfDate)) {
throwError(`[DonationBar] Prop "asOfDate" must be in ISO 8601 format (YYYY-MM-DD), received: ${props.asOfDate}`)
}
if (isNaN(new Date(props.asOfDate).getTime())) {
throwError(`[DonationBar] Prop "asOfDate" has invalid date value: ${props.asOfDate}`)
}
const title = computed(() => { const title = computed(() => {
switch (locale) { switch (locale) {