connector-wordpress/source/front/formatter.js

46 lines
1.2 KiB
JavaScript
Raw Normal View History

import DateTimeWrapper from './date-time-wrapper.js'
2021-04-13 21:10:28 +02:00
export default class Formatter {
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()
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()
if (isShortOffsetNameShown) {
dateText += ' (' + endDateTime.getShortOffsetName() + ')'
}
}
2021-04-13 21:10:28 +02:00
return dateText
}
static formatLocation({ description, locality }) {
let location = ''
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
}
}