Skip to content

Commit

Permalink
update date detection functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
mdickson-adbe committed Dec 11, 2023
1 parent 4a059b7 commit 119b4af
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions scripts/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,19 +338,21 @@ const DATA_TYPES = {
function isDateValue(value) {
if (typeof value === 'object' && value instanceof Date) {
return true;
} if (typeof value === 'string') {
return !Number.isNaN(Date.parse(value)) || false;
} if (typeof value === 'number') {
try {
const date = new Date(value);
return !Number.isNaN(date.getTime());
} catch (e) {
return false;
}
} if (typeof value === 'string' || typeof value === 'number') {
return isISODate(value);
}
return false;
}

function isISODate(value) {
const dateObj = new Date(value);
try {
return (dateObj !== 'Invalid Date' && !Number.isNaN(dateObj) && (value === dateObj.toISOString())) || false;
} catch (e) {
return false;
}
}

export function isDate(propertyName, propertyValue) {
return DATE_FIELDS.includes(propertyName)
|| (propertyValue !== undefined && isDateValue(propertyValue));
Expand Down Expand Up @@ -398,7 +400,7 @@ export function formatAssetMetadata(propertyName, metadataValue) {
}

// check if string is a date
if (Date.parse(metadataValue)) {
if (isISODate(metadataValue)) {
return formatDate(metadataValue);
}

Expand Down

0 comments on commit 119b4af

Please sign in to comment.