add in better message for unsupported date format

This commit is contained in:
jasquat 2024-01-03 10:42:54 -05:00
parent 73eb221c17
commit 0da550d412
No known key found for this signature in database
1 changed files with 15 additions and 3 deletions

View File

@ -93,15 +93,27 @@ if (
}
const splitDateFormat = generalDateFormat.split('-');
const supportedDateFormatTypes = ['yyyy', 'MM', 'MMM', 'MMMM', 'dd'];
// https://date-fns.org/v3.0.6/docs/format
const supportedDateFormatTypes = {
yyyy: '2024',
MM: '01',
MMM: 'Jan',
MMMM: 'January',
dd: '01',
};
const unsupportedFormatTypes = splitDateFormat.filter(
(x) => !supportedDateFormatTypes.includes(x)
(x) => !Object.keys(supportedDateFormatTypes).includes(x)
);
const formattedSupportedDateTypes: string[] = [];
Object.entries(supportedDateFormatTypes).forEach(([key, value]) => {
formattedSupportedDateTypes.push(`${key}: ${value}`);
});
if (unsupportedFormatTypes.length > 0) {
throw new Error(
`Given SPIFFWORKFLOW_FRONTEND_RUNTIME_CONFIG_DATE_FORMAT is not supported. Given: ${generalDateFormat} with invalid options: ${unsupportedFormatTypes.join(
', '
)}. Valid options are: ${supportedDateFormatTypes.join(', ')}`
)}. Valid options are: ${formattedSupportedDateTypes.join(', ')}`
);
}
const carbonDateFormat = generalDateFormat