2022-01-09 12:11:24 +01:00
|
|
|
import DateTimeWrapper from './date-time-wrapper.js'
|
2021-04-13 21:10:28 +02:00
|
|
|
|
|
|
|
export default class Formatter {
|
2021-05-23 15:37:29 +02:00
|
|
|
static formatDate({ locale, timeZone, start, end, isShortOffsetNameShown }) {
|
2021-12-09 19:46:19 +01:00
|
|
|
const startDateTime = new DateTimeWrapper({
|
|
|
|
locale,
|
|
|
|
text: start,
|
|
|
|
timeZone,
|
|
|
|
})
|
2021-04-13 21:10:28 +02:00
|
|
|
let dateText = startDateTime.getShortDate()
|
|
|
|
dateText += ' ' + startDateTime.get24Time()
|
2021-12-23 17:16:03 +01:00
|
|
|
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 {
|
|
|
|
dateText += ' - '
|
|
|
|
}
|
|
|
|
dateText += endDateTime.get24Time()
|
2021-05-23 15:37:29 +02:00
|
|
|
if (isShortOffsetNameShown) {
|
2021-12-23 17:16:03 +01:00
|
|
|
dateText += ' (' + endDateTime.getShortOffsetName() + ')'
|
2021-05-23 15:37:29 +02:00
|
|
|
}
|
|
|
|
}
|
2021-04-13 21:10:28 +02:00
|
|
|
return dateText
|
|
|
|
}
|
|
|
|
|
|
|
|
static formatLocation({ description, locality }) {
|
|
|
|
let location = ''
|
2022-01-09 12:54:58 +01:00
|
|
|
if (description && description.trim()) {
|
|
|
|
location += description.trim()
|
2021-04-13 21:10:28 +02:00
|
|
|
}
|
|
|
|
if (location && locality) {
|
|
|
|
location += ', '
|
|
|
|
}
|
|
|
|
if (locality) {
|
|
|
|
location += locality
|
|
|
|
}
|
|
|
|
return location
|
|
|
|
}
|
|
|
|
}
|