diff --git a/lib/utils/parseDate.tsx b/lib/utils/parseDate.tsx index aa77847..f159f58 100644 --- a/lib/utils/parseDate.tsx +++ b/lib/utils/parseDate.tsx @@ -1,7 +1,8 @@ /** * Parse Date to a UTC date - * @param dateStr + * @param dateStr + * @returns {Number} */ export const parseDate = (dateStr: string) => { // test dateStr format diff --git a/lib/utils/parseTextExpr.tsx b/lib/utils/parseTextExpr.tsx index e3e61a5..8b5ab4e 100644 --- a/lib/utils/parseTextExpr.tsx +++ b/lib/utils/parseTextExpr.tsx @@ -34,18 +34,19 @@ export const parseTextExpr = (textExpr: string, dimensions: any[]) : string => if (dimension.values.length > 1) { if (dimension.id === 'TIME_PERIOD') { // if concept is TIME_PERIOD, we use the first and last value - const date1Str = dimension.values[0][valueAttribute]; - const date2Str = dimension.values[dimension.values.length - 1][valueAttribute]; - const date1 = new Date(date1Str); - const date2 = new Date(date2Str); + const dateMin = new Date(Math.min(...dimension.values.map((item: any) => new Date(item["start"])))); + const dimValueMin = dimension.values.find((item: any) => new Date(item["start"]).getTime() === dateMin.getTime()); + const dateMax = new Date(Math.max(...dimension.values.map((item: any) => new Date(item["end"])))); + const date1 = new Date(dateMin); + const date2 = new Date(dateMax); let date1Text = `${date1.getFullYear()}`; let date2Text = `${date2.getFullYear()}`; - if (date1Str.split('-').length >= 2) { + if (dimValueMin[valueAttribute].split('-').length >= 2) { // if year and month is provided date1Text = `${date1.toLocaleString('default', { month: 'short' })} ${date1Text}`; date2Text = `${date2.toLocaleString('default', { month: 'short' })} ${date2Text}`; } - if (date1Str.split('-').length >= 3) { + if (dimValueMin[valueAttribute].split('-').length >= 3) { // if year, month and day is provided date1Text = `${date1.getDay()} ${date1Text}`; date2Text = `${date2.getDay()} ${date2Text}`;