Browse Source

Add workaround support for yyyyMMdd format

pull/2362/head
Frane Caleta 2 years ago
committed by Thomas
parent
commit
eb4fb04653
  1. 13
      libs/common/src/lib/helper.ts

13
libs/common/src/lib/helper.ts

@ -299,11 +299,22 @@ const DATE_FORMATS = [
'dd.MM.yyyy',
'yyyy-MM-dd',
'yyyy.MM.dd',
'yyyy/MM/dd'
'yyyy/MM/dd',
'yyyyMMdd'
];
// Helper function to parse a date string
export function parseDate(date: string): Date | null {
// Transform 'yyyyMMdd' format to supported format by parse function
if (`${date}`.length == 8) {
date = date.toString();
const match = date.match(/^(\d{4})(\d{2})(\d{2})$/);
if (match) {
const [, year, month, day] = match;
date = `${year}-${month}-${day}`;
}
}
const matchingFormat = DATE_FORMATS.find(
(format) => isMatch(date, format) && date.length === format.length
);

Loading…
Cancel
Save