connector-wordpress/source/connector-mobilizon/front/date-time-wrapper.js

39 lines
950 B
JavaScript
Raw Normal View History

2021-05-04 11:16:18 +02:00
import { DateTime } from 'luxon'
2021-01-08 14:08:40 +01:00
2021-04-13 20:50:56 +02:00
export default class DateTimeWrapper {
2021-01-08 14:08:40 +01:00
constructor({ locale = 'en-GB', text, timeZone = 'utc' } = {}) {
if (!timeZone) {
timeZone = 'utc'
}
if (timeZone.includes(':') && timeZone.substring(0, 3).toUpperCase() !== 'UTC') {
timeZone = 'UTC' + timeZone
}
2021-05-05 10:40:46 +02:00
this.dateTime = DateTime.fromISO(text, { locale, zone: timeZone })
2021-01-08 14:08:40 +01:00
}
getShortDate() {
return this.dateTime.toLocaleString(DateTime.DATE_SHORT)
}
getShortOffsetName() {
return this.dateTime.offsetNameShort
}
2021-01-08 14:08:40 +01:00
get24Time() {
return this.dateTime.toLocaleString(DateTime.TIME_24_SIMPLE)
}
equalsDate(other) {
return this.dateTime &&
other.dateTime &&
this.dateTime.day === other.dateTime.day &&
this.dateTime.month === other.dateTime.month &&
this.dateTime.year === other.dateTime.year
}
static getCurrentDatetimeAsString() {
2021-05-04 10:37:30 +02:00
return DateTime.now().toString()
}
2021-01-08 14:08:40 +01:00
}