default to en-GB locale, fix test failing due to time zone being null
This commit is contained in:
parent
89145fe9ed
commit
054e313a4d
|
@ -2,42 +2,42 @@ import test from 'ava'
|
||||||
import DateTimeWrapper from './date-time-wrapper'
|
import DateTimeWrapper from './date-time-wrapper'
|
||||||
|
|
||||||
test('#getShortDate usual date', t => {
|
test('#getShortDate usual date', t => {
|
||||||
const d = new DateTimeWrapper({ locale: 'en-GB', text: '2020-12-24T16:45:00Z' })
|
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' })
|
||||||
t.is(d.getShortDate(), '24/12/2020')
|
t.is(d.getShortDate(), '24/12/2020')
|
||||||
})
|
})
|
||||||
|
|
||||||
test('#get24Time usual time', t => {
|
test('#get24Time usual time', t => {
|
||||||
const d = new DateTimeWrapper({ locale: 'en-GB', text: '2020-12-24T16:45:00Z' })
|
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' })
|
||||||
t.is(d.get24Time(), '16:45')
|
t.is(d.get24Time(), '16:45')
|
||||||
})
|
})
|
||||||
|
|
||||||
test('#equalsDate same date, different time', t => {
|
test('#equalsDate same date, different time', t => {
|
||||||
const d = new DateTimeWrapper({ locale: 'en-GB', text: '2020-12-24T16:45:00Z' })
|
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' })
|
||||||
const e = new DateTimeWrapper({ locale: 'en-GB', text: '2020-12-24T17:46:01Z' })
|
const e = new DateTimeWrapper({ text: '2020-12-24T17:46:01Z' })
|
||||||
t.true(d.equalsDate(e))
|
t.true(d.equalsDate(e))
|
||||||
})
|
})
|
||||||
|
|
||||||
test('#equalsDate different date, different time', t => {
|
test('#equalsDate different date, different time', t => {
|
||||||
const d = new DateTimeWrapper({ locale: 'en-GB', text: '2020-12-24T16:45:00Z' })
|
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' })
|
||||||
const e = new DateTimeWrapper({ locale: 'en-GB', text: '2021-11-25T17:46:01Z' })
|
const e = new DateTimeWrapper({ text: '2021-11-25T17:46:01Z' })
|
||||||
t.false(d.equalsDate(e))
|
t.false(d.equalsDate(e))
|
||||||
})
|
})
|
||||||
|
|
||||||
test('#equalsDate different day, different time', t => {
|
test('#equalsDate different day, different time', t => {
|
||||||
const d = new DateTimeWrapper({ locale: 'en-GB', text: '2020-12-24T16:45:00Z' })
|
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' })
|
||||||
const e = new DateTimeWrapper({ locale: 'en-GB', text: '2020-12-25T17:46:01Z' })
|
const e = new DateTimeWrapper({ text: '2020-12-25T17:46:01Z' })
|
||||||
t.false(d.equalsDate(e))
|
t.false(d.equalsDate(e))
|
||||||
})
|
})
|
||||||
|
|
||||||
test('#equalsDate different month, different time', t => {
|
test('#equalsDate different month, different time', t => {
|
||||||
const d = new DateTimeWrapper({ locale: 'en-GB', text: '2020-12-24T16:45:00Z' })
|
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' })
|
||||||
const e = new DateTimeWrapper({ locale: 'en-GB', text: '2020-11-24T17:46:01Z' })
|
const e = new DateTimeWrapper({ text: '2020-11-24T17:46:01Z' })
|
||||||
t.false(d.equalsDate(e))
|
t.false(d.equalsDate(e))
|
||||||
})
|
})
|
||||||
|
|
||||||
test('#equalsDate different year, different time', t => {
|
test('#equalsDate different year, different time', t => {
|
||||||
const d = new DateTimeWrapper({ locale: 'en-GB', text: '2020-12-24T16:45:00Z' })
|
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' })
|
||||||
const e = new DateTimeWrapper({ locale: 'en-GB', text: '2021-12-24T17:46:01Z' })
|
const e = new DateTimeWrapper({ text: '2021-12-24T17:46:01Z' })
|
||||||
t.false(d.equalsDate(e))
|
t.false(d.equalsDate(e))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,7 @@ import { DateTime } from 'luxon'
|
||||||
|
|
||||||
export default class DateTimeWrapper {
|
export default class DateTimeWrapper {
|
||||||
|
|
||||||
constructor({ locale, text, timeZone }) {
|
constructor({ locale = 'en-GB', text, timeZone = 'utc' } = {}) {
|
||||||
if (!timeZone) {
|
|
||||||
timeZone = 'utc'
|
|
||||||
}
|
|
||||||
this.dateTime = DateTime.fromISO(text, { locale, zone: timeZone })
|
this.dateTime = DateTime.fromISO(text, { locale, zone: timeZone })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ test.beforeEach(t => {
|
||||||
t.context.list = document.createElement('ul')
|
t.context.list = document.createElement('ul')
|
||||||
t.context.list.setAttribute('data-locale', 'en-GB')
|
t.context.list.setAttribute('data-locale', 'en-GB')
|
||||||
t.context.list.setAttribute('data-maximum', '2')
|
t.context.list.setAttribute('data-maximum', '2')
|
||||||
|
t.context.list.setAttribute('data-time-zone', 'utc')
|
||||||
const listElement = document.createElement('li')
|
const listElement = document.createElement('li')
|
||||||
listElement.setAttribute('style', 'display: none;')
|
listElement.setAttribute('style', 'display: none;')
|
||||||
t.context.list.appendChild(listElement)
|
t.context.list.appendChild(listElement)
|
||||||
|
|
|
@ -2,12 +2,12 @@ import test from 'ava'
|
||||||
import Formatter from './formatter'
|
import Formatter from './formatter'
|
||||||
|
|
||||||
test('#formatDate one date', t => {
|
test('#formatDate one date', t => {
|
||||||
const date = Formatter.formatDate({ locale: 'en-GB', start: '2021-04-15T10:30:00Z', end: '2021-04-15T15:30:00Z' })
|
const date = Formatter.formatDate({ start: '2021-04-15T10:30:00Z', end: '2021-04-15T15:30:00Z' })
|
||||||
t.is(date, '15/04/2021 10:30 - 15:30')
|
t.is(date, '15/04/2021 10:30 - 15:30')
|
||||||
})
|
})
|
||||||
|
|
||||||
test('#formatDate two dates', t => {
|
test('#formatDate two dates', t => {
|
||||||
const date = Formatter.formatDate({ locale: 'en-GB', start: '2021-04-15T10:30:00Z', end: '2021-04-16T15:30:00Z' })
|
const date = Formatter.formatDate({ start: '2021-04-15T10:30:00Z', end: '2021-04-16T15:30:00Z' })
|
||||||
t.is(date, '15/04/2021 10:30 - 16/04/2021 15:30')
|
t.is(date, '15/04/2021 10:30 - 16/04/2021 15:30')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue