2024-02-06 22:58:49 +01:00
|
|
|
import tap from 'tap';
|
|
|
|
import {parseWhen as parse} from '../../parse/when.js';
|
2024-12-07 16:16:31 +00:00
|
|
|
import { parseDateTime } from '../../parse/date-time.js';
|
2019-09-03 15:35:12 +02:00
|
|
|
|
|
|
|
const profile = {
|
2024-12-07 16:16:31 +00:00
|
|
|
parseDateTime: parseDateTime,
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
locale: 'de-DE',
|
2024-02-06 22:58:49 +01:00
|
|
|
};
|
2019-10-20 00:19:11 +02:00
|
|
|
const ctx = {
|
|
|
|
data: {},
|
|
|
|
opt: {},
|
2024-02-06 22:58:49 +01:00
|
|
|
profile,
|
|
|
|
};
|
2019-09-03 15:35:12 +02:00
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
tap.test('parseWhen works correctly', (t) => {
|
2024-12-07 16:16:31 +00:00
|
|
|
const date = null;
|
|
|
|
const timeS = '2019-06-06T16:30:00';
|
|
|
|
const timeR = '2019-06-06T16:31:00';
|
2019-09-03 15:35:12 +02:00
|
|
|
const expected = {
|
2024-12-07 16:16:31 +00:00
|
|
|
when: '2019-06-06T16:31:00+02:00',
|
|
|
|
plannedWhen: '2019-06-06T16:30:00+02:00',
|
|
|
|
delay: 60, // seconds
|
2024-02-06 22:58:49 +01:00
|
|
|
};
|
2019-09-03 15:35:12 +02:00
|
|
|
|
2024-12-07 16:16:31 +00:00
|
|
|
t.same(parse(ctx, date, timeS, timeR), expected);
|
2019-09-03 15:35:12 +02:00
|
|
|
|
|
|
|
// no realtime data
|
2024-12-07 16:16:31 +00:00
|
|
|
t.same(parse(ctx, date, timeS, null), {
|
2024-02-06 22:58:49 +01:00
|
|
|
...expected, when: expected.plannedWhen, delay: null,
|
|
|
|
});
|
2019-09-03 15:35:12 +02:00
|
|
|
|
|
|
|
// cancelled
|
2024-12-07 16:16:31 +00:00
|
|
|
t.same(parse(ctx, date, timeS, timeR, true), {
|
2019-09-03 15:35:12 +02:00
|
|
|
...expected,
|
|
|
|
when: null,
|
2024-02-06 22:58:49 +01:00
|
|
|
prognosedWhen: expected.when,
|
|
|
|
});
|
|
|
|
t.end();
|
|
|
|
});
|