diff --git a/source/changelog.txt b/source/changelog.txt index 2bc9f8c..25355ba 100644 --- a/source/changelog.txt +++ b/source/changelog.txt @@ -9,6 +9,7 @@ #### Deprecated #### Removed #### Fixed +- Fix Invalid DateTime on event end time being null #### Security ### [0.6.2] - 2021-08-24 diff --git a/source/front/formatter-test.js b/source/front/formatter-test.js index e1959c6..c252ed3 100644 --- a/source/front/formatter-test.js +++ b/source/front/formatter-test.js @@ -32,7 +32,24 @@ test('#formatDate two dates with short offset name', (t) => { end: '2021-04-16T15:30:00Z', isShortOffsetNameShown: true, }) - t.is(date, '15/04/2021 10:30 (UTC) - 16/04/2021 15:30 (UTC)') + t.is(date, '15/04/2021 10:30 - 16/04/2021 15:30 (UTC)') +}) + +test('#formatDate second date is null', (t) => { + const date = Formatter.formatDate({ + start: '2021-04-15T10:30:00Z', + end: null, + }) + t.is(date, '15/04/2021 10:30') +}) + +test('#formatDate second date is null with short offset name', (t) => { + const date = Formatter.formatDate({ + start: '2021-04-15T10:30:00Z', + end: null, + isShortOffsetNameShown: true, + }) + t.is(date, '15/04/2021 10:30 (UTC)') }) test('#formatLocation both parameters', (t) => { diff --git a/source/front/formatter.js b/source/front/formatter.js index 279d4b0..220e56f 100644 --- a/source/front/formatter.js +++ b/source/front/formatter.js @@ -7,21 +7,24 @@ export default class Formatter { text: start, timeZone, }) - const endDateTime = new DateTimeWrapper({ locale, text: end, timeZone }) let dateText = startDateTime.getShortDate() dateText += ' ' + startDateTime.get24Time() - if (!startDateTime.equalsDate(endDateTime)) { - if (isShortOffsetNameShown) { - dateText += ' (' + startDateTime.getShortOffsetName() + ')' - } - dateText += ' - ' - dateText += endDateTime.getShortDate() + ' ' - } else { - dateText += ' - ' + if (!end && isShortOffsetNameShown) { + dateText += ' (' + startDateTime.getShortOffsetName() + ')' } - dateText += endDateTime.get24Time() - if (isShortOffsetNameShown) { - dateText += ' (' + endDateTime.getShortOffsetName() + ')' + + if (end) { + const endDateTime = new DateTimeWrapper({ locale, text: end, timeZone }) + if (!startDateTime.equalsDate(endDateTime)) { + dateText += ' - ' + dateText += endDateTime.getShortDate() + ' ' + } else { + dateText += ' - ' + } + dateText += endDateTime.get24Time() + if (isShortOffsetNameShown) { + dateText += ' (' + endDateTime.getShortOffsetName() + ')' + } } return dateText }