2021-04-04 18:03:05 +02:00
|
|
|
import test from 'ava'
|
2022-01-09 12:11:24 +01:00
|
|
|
import DateTimeWrapper from './date-time-wrapper.js'
|
2021-01-08 14:08:40 +01:00
|
|
|
|
2021-12-09 19:46:19 +01:00
|
|
|
test('#getShortDate usual date', (t) => {
|
2021-05-05 11:36:57 +02:00
|
|
|
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' })
|
2021-01-08 14:08:40 +01:00
|
|
|
t.is(d.getShortDate(), '24/12/2020')
|
|
|
|
})
|
|
|
|
|
2021-12-09 19:46:19 +01:00
|
|
|
test('#getShortDate usual date with timezone string', (t) => {
|
|
|
|
const d = new DateTimeWrapper({
|
|
|
|
text: '2020-12-24T16:45:00Z',
|
|
|
|
timeZone: 'Europe/Rome',
|
|
|
|
})
|
2021-08-24 19:23:57 +02:00
|
|
|
t.is(d.getShortDate(), '24/12/2020')
|
|
|
|
})
|
|
|
|
|
2021-12-09 19:46:19 +01:00
|
|
|
test('#getShortDate usual date with fixed offset', (t) => {
|
|
|
|
const d = new DateTimeWrapper({
|
|
|
|
text: '2020-12-24T16:45:00Z',
|
|
|
|
timeZone: 'UTC+02:00',
|
|
|
|
})
|
2021-08-24 19:23:57 +02:00
|
|
|
t.is(d.getShortDate(), '24/12/2020')
|
|
|
|
})
|
|
|
|
|
2021-12-09 19:46:19 +01:00
|
|
|
test('#getShortDate usual date with fixed offset without UTC prefix', (t) => {
|
|
|
|
const d = new DateTimeWrapper({
|
|
|
|
text: '2020-12-24T16:45:00Z',
|
|
|
|
timeZone: '+02:00',
|
|
|
|
})
|
2021-08-24 19:23:57 +02:00
|
|
|
t.is(d.getShortDate(), '24/12/2020')
|
|
|
|
})
|
|
|
|
|
2021-12-09 19:46:19 +01:00
|
|
|
test('#getShortDate usual date with empty time zone', (t) => {
|
2021-08-24 19:23:57 +02:00
|
|
|
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z', timeZone: '' })
|
|
|
|
t.is(d.getShortDate(), '24/12/2020')
|
|
|
|
})
|
|
|
|
|
2021-12-09 19:46:19 +01:00
|
|
|
test('#get24Time usual time', (t) => {
|
2021-05-05 11:36:57 +02:00
|
|
|
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' })
|
2021-05-05 10:13:16 +02:00
|
|
|
t.is(d.get24Time(), '16:45')
|
2021-01-08 14:08:40 +01:00
|
|
|
})
|
|
|
|
|
2021-12-09 19:46:19 +01:00
|
|
|
test('#equalsDate same date, different time', (t) => {
|
2021-05-05 11:36:57 +02:00
|
|
|
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' })
|
|
|
|
const e = new DateTimeWrapper({ text: '2020-12-24T17:46:01Z' })
|
2021-01-08 14:08:40 +01:00
|
|
|
t.true(d.equalsDate(e))
|
|
|
|
})
|
|
|
|
|
2021-12-09 19:46:19 +01:00
|
|
|
test('#equalsDate different date, different time', (t) => {
|
2021-05-05 11:36:57 +02:00
|
|
|
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' })
|
|
|
|
const e = new DateTimeWrapper({ text: '2021-11-25T17:46:01Z' })
|
2021-01-08 14:08:40 +01:00
|
|
|
t.false(d.equalsDate(e))
|
|
|
|
})
|
|
|
|
|
2021-12-09 19:46:19 +01:00
|
|
|
test('#equalsDate different day, different time', (t) => {
|
2021-05-05 11:36:57 +02:00
|
|
|
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' })
|
|
|
|
const e = new DateTimeWrapper({ text: '2020-12-25T17:46:01Z' })
|
2021-01-08 14:08:40 +01:00
|
|
|
t.false(d.equalsDate(e))
|
|
|
|
})
|
|
|
|
|
2021-12-09 19:46:19 +01:00
|
|
|
test('#equalsDate different month, different time', (t) => {
|
2021-05-05 11:36:57 +02:00
|
|
|
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' })
|
|
|
|
const e = new DateTimeWrapper({ text: '2020-11-24T17:46:01Z' })
|
2021-01-08 14:08:40 +01:00
|
|
|
t.false(d.equalsDate(e))
|
|
|
|
})
|
|
|
|
|
2021-12-09 19:46:19 +01:00
|
|
|
test('#equalsDate different year, different time', (t) => {
|
2021-05-05 11:36:57 +02:00
|
|
|
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' })
|
|
|
|
const e = new DateTimeWrapper({ text: '2021-12-24T17:46:01Z' })
|
2021-01-08 14:08:40 +01:00
|
|
|
t.false(d.equalsDate(e))
|
|
|
|
})
|
2021-01-15 20:30:05 +01:00
|
|
|
|
2021-12-09 19:46:19 +01:00
|
|
|
test('#getCurrentDatetimeAsString correct format', (t) => {
|
2021-01-15 20:30:05 +01:00
|
|
|
const d = DateTimeWrapper.getCurrentDatetimeAsString()
|
|
|
|
t.is(d[4], '-')
|
|
|
|
t.is(d[7], '-')
|
|
|
|
t.is(d[10], 'T')
|
|
|
|
t.is(d[13], ':')
|
|
|
|
t.is(d[16], ':')
|
|
|
|
t.is(d[19], '.')
|
2021-12-09 19:46:19 +01:00
|
|
|
t.is(d[d.length - 3], ':')
|
2021-01-15 20:30:05 +01:00
|
|
|
})
|
2021-05-23 15:37:29 +02:00
|
|
|
|
2021-12-09 19:46:19 +01:00
|
|
|
test('#getShortOffsetName usual time', (t) => {
|
2021-05-23 15:37:29 +02:00
|
|
|
const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' })
|
|
|
|
t.is(d.getShortOffsetName(), 'UTC')
|
|
|
|
})
|