2026-06-27 15:12:40 +08:00
|
|
|
import assert from "node:assert/strict";
|
2026-06-27 15:38:31 +08:00
|
|
|
import { normalizeNtfyServerUrl } from "../src/utils/ntfy";
|
2026-06-27 15:12:40 +08:00
|
|
|
import { getNextRepeatDate, parseReminderDate } from "../src/utils/date";
|
|
|
|
|
|
|
|
|
|
const base = new Date("2026-06-27T10:00:00");
|
|
|
|
|
|
|
|
|
|
const plusTwoHours = parseReminderDate("+2h", base);
|
|
|
|
|
assert.equal(plusTwoHours?.toISOString(), new Date("2026-06-27T12:00:00").toISOString());
|
|
|
|
|
|
|
|
|
|
const tomorrow = parseReminderDate("tomorrow 09:30", base);
|
|
|
|
|
assert.equal(tomorrow?.toISOString(), new Date("2026-06-28T09:30:00").toISOString());
|
|
|
|
|
|
|
|
|
|
const simple = parseReminderDate("2026-07-01 14:46", base);
|
|
|
|
|
assert.equal(simple?.getFullYear(), 2026);
|
|
|
|
|
assert.equal(simple?.getMonth(), 6);
|
|
|
|
|
assert.equal(simple?.getDate(), 1);
|
|
|
|
|
assert.equal(simple?.getHours(), 14);
|
|
|
|
|
assert.equal(simple?.getMinutes(), 46);
|
|
|
|
|
|
|
|
|
|
const nextDaily = getNextRepeatDate("2026-06-26T10:00:00.000Z", { frequency: "daily", interval: 1 }, new Date("2026-06-27T10:00:01.000Z"));
|
|
|
|
|
assert.equal(nextDaily, "2026-06-28T10:00:00.000Z");
|
|
|
|
|
|
|
|
|
|
const nextWeekly = getNextRepeatDate("2026-06-20T10:00:00.000Z", { frequency: "weekly", interval: 2 }, new Date("2026-06-27T10:00:01.000Z"));
|
|
|
|
|
assert.equal(nextWeekly, "2026-07-04T10:00:00.000Z");
|
|
|
|
|
|
2026-06-27 15:38:31 +08:00
|
|
|
assert.equal(normalizeNtfyServerUrl("notifai.dinlo.ru/"), "https://notifai.dinlo.ru");
|
|
|
|
|
assert.equal(normalizeNtfyServerUrl("http://127.0.0.1:8080/"), "http://127.0.0.1:8080");
|