45 lines
2.5 KiB
JavaScript
45 lines
2.5 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { execFileSync } = require('node:child_process');
|
|
const { parsePrestashopDate } = require('../src/prestashop-date');
|
|
|
|
test('shop-local dates use the date-specific offset, including DST transitions and other shop zones', () => {
|
|
const cases = [
|
|
['2026-09-25 10:53:43', undefined, '2026-09-25T08:53:43.000Z'],
|
|
['2026-01-25 10:53:43', undefined, '2026-01-25T09:53:43.000Z'],
|
|
['2026-03-29 01:59:59', undefined, '2026-03-29T00:59:59.000Z'],
|
|
['2026-03-29 03:00:00', undefined, '2026-03-29T01:00:00.000Z'],
|
|
['2026-10-25 02:30:00', undefined, '2026-10-25T00:30:00.000Z'],
|
|
['2026-10-25 03:00:00', undefined, '2026-10-25T02:00:00.000Z'],
|
|
['2026-09-25 00:00:00.123', undefined, '2026-09-24T22:00:00.123Z'],
|
|
['2026-09-25 10:53:43', 'UTC', '2026-09-25T10:53:43.000Z'],
|
|
['2026-09-25 10:53:43', 'Europe/London', '2026-09-25T09:53:43.000Z'],
|
|
['2026-09-25 10:53:43', 'Asia/Kolkata', '2026-09-25T05:23:43.000Z'],
|
|
['2026-09-25T10:53:43+02:00', 'Europe/London', '2026-09-25T08:53:43.000Z'],
|
|
['2026-09-25T08:53:43Z', undefined, '2026-09-25T08:53:43.000Z'],
|
|
];
|
|
for (const [input, zone, expected] of cases) {
|
|
assert.equal(parsePrestashopDate(input, null, zone).toISOString(), expected, `${input} (${zone})`);
|
|
}
|
|
});
|
|
|
|
test('invalid calendar dates and nonexistent local times use the supplied fallback', () => {
|
|
const fallback = new Date('2026-09-25T09:00:00Z');
|
|
for (const value of [null, '', 'invalid', '0000-00-00 00:00:00', '2026-02-30 10:00:00',
|
|
'2026-09-25 24:00:00', '2026-03-29 02:30:00', new Date(NaN)]) {
|
|
assert.equal(parsePrestashopDate(value, fallback), fallback, String(value));
|
|
}
|
|
assert.equal(parsePrestashopDate(fallback).getTime(), fallback.getTime());
|
|
assert.throws(() => parsePrestashopDate('2026-09-25 10:00:00', null, 'Not/AZone'), RangeError);
|
|
});
|
|
|
|
test('the same PrestaShop date produces the same instant in UTC, Warsaw and US containers', () => {
|
|
const script = `const { parsePrestashopDate } = require(${JSON.stringify(require.resolve('../src/prestashop-date'))});
|
|
process.stdout.write(parsePrestashopDate('2026-09-25 10:53:43').toISOString());`;
|
|
for (const TZ of ['UTC', 'Europe/Warsaw', 'America/New_York']) {
|
|
assert.equal(execFileSync(process.execPath, ['-e', script], {
|
|
env: { ...process.env, TZ }, encoding: 'utf8',
|
|
}), '2026-09-25T08:53:43.000Z');
|
|
}
|
|
});
|