mirror of
https://github.com/strapi/strapi.git
synced 2025-12-27 07:03:38 +00:00
change error message to a deprecated message
This commit is contained in:
parent
ca910fe92c
commit
82e68fca93
@ -99,6 +99,7 @@ class BigIntegerField extends NumberField {
|
||||
|
||||
const timeRegex = new RegExp('^(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(.[0-9]{1,3})?$');
|
||||
const dateRegex = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/;
|
||||
const partialDateRegex = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])/g;
|
||||
|
||||
const parseTime = value => {
|
||||
if (dateFns.isDate(value)) return dateFns.format(value, 'HH:mm:ss.SSS');
|
||||
@ -119,16 +120,23 @@ const parseTime = value => {
|
||||
};
|
||||
|
||||
const parseDate = value => {
|
||||
if (!dateRegex.test(value)) {
|
||||
throw new InvalidDateError(`Invalid format, expected yyyy-MM-dd`);
|
||||
const found = _.isString(value) ? value.match(partialDateRegex) : [];
|
||||
const extractedValue = found[0];
|
||||
|
||||
if (extractedValue && !dateRegex.test(value)) {
|
||||
// TODO V5: throw an error when format yyyy-MM-dd is not respected
|
||||
// throw new InvalidDateError(`Invalid format, expected yyyy-MM-dd`);
|
||||
process.emitWarning(
|
||||
`[deprecated] Using a date format other than yyyy-MM-dd will be deprecated. Use format yyyy-MM-dd instead. Value found: ${value}. Date kept: ${extractedValue}.`
|
||||
);
|
||||
}
|
||||
|
||||
let date = dateFns.parseISO(value);
|
||||
let date = dateFns.parseISO(extractedValue);
|
||||
if (!dateFns.isValid(date)) {
|
||||
throw new InvalidDateError(`Invalid date`);
|
||||
}
|
||||
|
||||
return value;
|
||||
return extractedValue;
|
||||
};
|
||||
|
||||
const parseDateTimeOrTimestamp = value => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user