From 8dbc5324f437126d21a2208456d0de02a71587d8 Mon Sep 17 00:00:00 2001 From: Thomas Tilak Date: Tue, 14 Jan 2025 16:47:33 +0100 Subject: [PATCH 1/2] fix #14 --- lib/utils/parseDate.tsx | 3 ++- lib/utils/parseTextExpr.tsx | 15 +++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) 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..2df7494 100644 --- a/lib/utils/parseTextExpr.tsx +++ b/lib/utils/parseTextExpr.tsx @@ -1,3 +1,5 @@ +import { parseDate } from "./parseDate"; + /** * Process the "Title" expression provided in yaml. * Example: 'Status in employment {$TIME_PERIOD}, [DIN, 14, Bold, Italics, LEFT]', @@ -34,18 +36,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}`; From 136ecd70d29c4aa9a3819cac0d2e3d6af39189e0 Mon Sep 17 00:00:00 2001 From: Stan Ozier <45051039+stanozr@users.noreply.github.com> Date: Tue, 11 Feb 2025 11:21:29 +0100 Subject: [PATCH 2/2] Remove parseDate import Never used, breaks the build process --- lib/utils/parseTextExpr.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/utils/parseTextExpr.tsx b/lib/utils/parseTextExpr.tsx index 2df7494..8b5ab4e 100644 --- a/lib/utils/parseTextExpr.tsx +++ b/lib/utils/parseTextExpr.tsx @@ -1,5 +1,3 @@ -import { parseDate } from "./parseDate"; - /** * Process the "Title" expression provided in yaml. * Example: 'Status in employment {$TIME_PERIOD}, [DIN, 14, Bold, Italics, LEFT]',