Fix Invalid DateTime on event end time being null

This commit is contained in:
Daniel Waxweiler 2021-12-23 17:16:03 +01:00
parent 688868cbe9
commit a287d93b9f
3 changed files with 34 additions and 13 deletions

View File

@ -9,6 +9,7 @@
#### Deprecated
#### Removed
#### Fixed
- Fix Invalid DateTime on event end time being null
#### Security
### [0.6.2] - 2021-08-24

View File

@ -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) => {

View File

@ -7,13 +7,15 @@ 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) {
if (!end && isShortOffsetNameShown) {
dateText += ' (' + startDateTime.getShortOffsetName() + ')'
}
if (end) {
const endDateTime = new DateTimeWrapper({ locale, text: end, timeZone })
if (!startDateTime.equalsDate(endDateTime)) {
dateText += ' - '
dateText += endDateTime.getShortDate() + ' '
} else {
@ -23,6 +25,7 @@ export default class Formatter {
if (isShortOffsetNameShown) {
dateText += ' (' + endDateTime.getShortOffsetName() + ')'
}
}
return dateText
}