49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { formatInTimeZone } from "date-fns-tz";
|
|
import {
|
|
DEFAULT_TIMEZONE,
|
|
combineDateAndTime,
|
|
zonedDateOnlyToUtc,
|
|
atStartOfDayInZone,
|
|
atEndOfDayInZone
|
|
} from "../lib/date";
|
|
|
|
function minutesBetween(a: Date, b: Date) {
|
|
return Math.round((b.getTime() - a.getTime()) / 60000);
|
|
}
|
|
|
|
function run() {
|
|
const dstStartDay = zonedDateOnlyToUtc("2026-03-29");
|
|
const startA = combineDateAndTime(dstStartDay, "01:30");
|
|
const startB = combineDateAndTime(dstStartDay, "03:30");
|
|
assert.equal(
|
|
minutesBetween(startA, startB),
|
|
60,
|
|
"DST-Start: 01:30 -> 03:30 muss in Berlin 60 Minuten ergeben"
|
|
);
|
|
|
|
const dstEndDay = zonedDateOnlyToUtc("2026-10-25");
|
|
const endA = combineDateAndTime(dstEndDay, "01:30");
|
|
const endB = combineDateAndTime(dstEndDay, "03:30");
|
|
assert.equal(
|
|
minutesBetween(endA, endB),
|
|
180,
|
|
"DST-Ende: 01:30 -> 03:30 muss in Berlin 180 Minuten ergeben"
|
|
);
|
|
|
|
const asIso = formatInTimeZone(dstStartDay, DEFAULT_TIMEZONE, "yyyy-MM-dd");
|
|
assert.equal(asIso, "2026-03-29", "Datumskonvertierung darf lokalen Tag nicht verschieben");
|
|
|
|
const dayStart = atStartOfDayInZone(dstStartDay);
|
|
const dayEnd = atEndOfDayInZone(dstStartDay);
|
|
const startIso = formatInTimeZone(dayStart, DEFAULT_TIMEZONE, "yyyy-MM-dd HH:mm");
|
|
const endIso = formatInTimeZone(dayEnd, DEFAULT_TIMEZONE, "yyyy-MM-dd HH:mm");
|
|
assert.equal(startIso, "2026-03-29 00:00");
|
|
assert.equal(endIso, "2026-03-29 23:59");
|
|
|
|
// eslint-disable-next-line no-console
|
|
console.log("[timezone-test] OK - Europe/Berlin DST Verhalten verifiziert");
|
|
}
|
|
|
|
run();
|