connector-wordpress/source/connector-mobilizon/front/formatter.js

40 lines
1.1 KiB
JavaScript
Raw Normal View History

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