Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukeybooi committed Jul 18, 2023
2 parents 66e65f0 + 73e2dd5 commit c1e7308
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ export const getContent = (content: string, { dataType = 'string', dateFormat, n

export const formatDateStringAndPrefix = (content: string, dateFormat: string) => {
const regex = /^\s*([\S\s]+?)\s+(\d{4}-\d{2}-\d{2})/;
const match = content.match(regex);
const match = content?.match(regex);

if (match) {
if (match && match?.length > 2) {
const prefix = match[1] || '';
const dateString = match[2];
const dateString = match[2] || '';

const formatedDate = moment(dateString).isValid()
? moment(dateString).format(dateFormat || 'DD/MM/YYYY HH:mm')
: dateString;

return `${prefix} ${formatedDate}`;
return `${prefix} ${formatDate(dateString, dateFormat)}`;
} else {
return content;
return formatDate(content, dateFormat);
}
};

const formatDate = (dateText: string, dateFormat: string) => {
return moment(dateText).isValid() ? moment(dateText).format(dateFormat || 'DD/MM/YYYY HH:mm') : dateText;
};

0 comments on commit c1e7308

Please sign in to comment.