2021-04-13 21:10:28 +02:00
|
|
|
import DateTimeWrapper from './date-time-wrapper'
|
|
|
|
|
|
|
|
export default class Formatter {
|
|
|
|
|
2021-05-23 15:37:29 +02:00
|
|
|
static formatDate({ locale, timeZone, start, end, isShortOffsetNameShown }) {
|
2021-05-05 10:40:46 +02:00
|
|
|
const startDateTime = new DateTimeWrapper({ locale, text: start, timeZone })
|
|
|
|
const endDateTime = new DateTimeWrapper({ locale, text: end, timeZone })
|
2021-04-13 21:10:28 +02:00
|
|
|
let dateText = startDateTime.getShortDate()
|
|
|
|
dateText += ' ' + startDateTime.get24Time()
|
|
|
|
if (!startDateTime.equalsDate(endDateTime)) {
|
2021-05-23 15:37:29 +02:00
|
|
|
if (isShortOffsetNameShown) {
|
|
|
|
dateText += ' (' + startDateTime.getShortOffsetName() + ')'
|
|
|
|
}
|
|
|
|
dateText += ' - '
|
2021-04-13 21:10:28 +02:00
|
|
|
dateText += endDateTime.getShortDate() + ' '
|
2021-05-23 15:37:29 +02:00
|
|
|
} else {
|
|
|
|
dateText += ' - '
|
2021-04-13 21:10:28 +02:00
|
|
|
}
|
|
|
|
dateText += endDateTime.get24Time()
|
2021-05-23 15:37:29 +02:00
|
|
|
if (isShortOffsetNameShown) {
|
|
|
|
dateText += ' (' + endDateTime.getShortOffsetName() + ')'
|
|
|
|
}
|
2021-04-13 21:10:28 +02:00
|
|
|
return dateText
|
|
|
|
}
|
|
|
|
|
|
|
|
static formatLocation({ description, locality }) {
|
|
|
|
let location = ''
|
|
|
|
if (description) {
|
|
|
|
location += description
|
|
|
|
}
|
|
|
|
if (location && locality) {
|
|
|
|
location += ', '
|
|
|
|
}
|
|
|
|
if (locality) {
|
|
|
|
location += locality
|
|
|
|
}
|
|
|
|
return location
|
|
|
|
}
|
|
|
|
}
|