refactor: plan timeframes use a per-day-of-week picker (like the V2 tariff)
The timeframes model was a coarse weekday/weekend split, which couldn't express
"open Saturdays" or different rules on a specific day — and it didn't match the
V2 tariff, which already has a proper per-day-of-week picker (Hën–Die).
Replace PlanTimeframes { weekday, weekend } with { days[], fromMin, toMin }: the
allowed window applies only on the selected days (0=Sun..6=Sat; empty = every
day); on unselected days the subscriber parks free. A "night plan, free
weekends" is just days [Mon..Fri] with a 20:00→08:00 window — the exact case
from before, now expressible alongside any other day combination.
outOfWindowGap reworked to the days model (per-day membership test instead of
the weekend helper); the plans editor reuses the tariff composer's Mon-first
checkbox row and the shared tariff.dow0..6 labels. No production plans carry
timeframes yet (feature shipped today), so the shape changed directly with no
migration. Unit tests updated + extended (Saturday-only, every-day, weekday
night); 81 shared tests pass. Build+lint 12/12.
Claude-Session: https://claude.ai/code/session_01Xcm6ikLgGoCxxHrxtjkk5V
This commit is contained in:
@@ -4,15 +4,17 @@ import { outOfWindowGap, type PlanTimeframes } from "./index.js";
|
||||
// The "tariff bridge" gap for a subscriber scan outside their allowed window. UTC tz
|
||||
// keeps the wall-clock arithmetic obvious in the tests. See wiki/entities/subscription.md.
|
||||
|
||||
// Night plan: weekday allowed 20:00→08:00 (wraps midnight); weekend all-day.
|
||||
// Night plan: window 20:00→08:00 (wraps midnight) on weekdays (Mon..Fri). Days not in the
|
||||
// set (Sat/Sun) are unrestricted — no charge.
|
||||
const night: PlanTimeframes = {
|
||||
weekday: { fromMin: 20 * 60, toMin: 8 * 60 }, // 1200 → 480
|
||||
weekend: { allDay: true },
|
||||
days: [1, 2, 3, 4, 5], // Mon..Fri
|
||||
fromMin: 20 * 60,
|
||||
toMin: 8 * 60, // 1200 → 480
|
||||
graceMin: 0,
|
||||
tz: "UTC",
|
||||
};
|
||||
|
||||
// A weekday + a weekend (2026-06-22 is a Monday; 2026-06-20 is a Saturday).
|
||||
// 2026-06-22 is a Monday; 2026-06-20 is a Saturday.
|
||||
const monday = (hhmm: string) => `2026-06-22T${hhmm}:00.000Z`;
|
||||
const saturday = (hhmm: string) => `2026-06-20T${hhmm}:00.000Z`;
|
||||
|
||||
@@ -49,11 +51,20 @@ describe("outOfWindowGap — exit edge (late departure)", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("outOfWindowGap — weekend all-day", () => {
|
||||
it("any Saturday scan is free (entry + exit)", () => {
|
||||
describe("outOfWindowGap — days the window doesn't apply", () => {
|
||||
it("a Saturday scan is free (window only Mon..Fri)", () => {
|
||||
expect(outOfWindowGap(night, "UTC", saturday("09:00"), "entry")).toBeNull();
|
||||
expect(outOfWindowGap(night, "UTC", saturday("23:30"), "exit")).toBeNull();
|
||||
});
|
||||
it("a window with no days (every day) DOES apply on Saturday", () => {
|
||||
const everyDay: PlanTimeframes = { fromMin: 1200, toMin: 480, tz: "UTC" };
|
||||
expect(outOfWindowGap(everyDay, "UTC", saturday("09:00"), "entry")).not.toBeNull();
|
||||
});
|
||||
it("an arbitrary day set (e.g. only Saturday) applies just then", () => {
|
||||
const satOnly: PlanTimeframes = { days: [6], fromMin: 1200, toMin: 480, tz: "UTC" };
|
||||
expect(outOfWindowGap(satOnly, "UTC", saturday("09:00"), "entry")).not.toBeNull();
|
||||
expect(outOfWindowGap(satOnly, "UTC", monday("09:00"), "entry")).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("outOfWindowGap — grace tolerance", () => {
|
||||
@@ -74,9 +85,4 @@ describe("outOfWindowGap — unrestricted", () => {
|
||||
it("null timeframes → never a charge", () => {
|
||||
expect(outOfWindowGap(null, "UTC", monday("09:00"), "entry")).toBeNull();
|
||||
});
|
||||
it("a day-type with no window → no charge", () => {
|
||||
const weekdayOnly: PlanTimeframes = { weekday: { fromMin: 1200, toMin: 480 }, tz: "UTC" };
|
||||
// weekend absent ⇒ unrestricted on Saturday.
|
||||
expect(outOfWindowGap(weekdayOnly, "UTC", saturday("09:00"), "entry")).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user