Skip to main content

Function: defineSemanticTimes()

function defineSemanticTimes<T>(defs): SemanticTimeContext<keyof T & string>;
Define semantic times with type-safe names. Returns a context object that provides:
  • Type-safe coverage() function that only accepts defined semantic time names
  • resolve() function to expand semantic times to concrete requirements

Type Parameters

Type Parameter
T extends Record<string, SemanticTimeEntry>

Parameters

ParameterType
defsT

Returns

SemanticTimeContext<keyof T & string>

Examples

const times = defineSemanticTimes({
  opening: { startTime: { hours: 6 }, endTime: { hours: 8 } },
  lunch: { startTime: { hours: 11, minutes: 30 }, endTime: { hours: 14 } },
  closing: { startTime: { hours: 21 }, endTime: { hours: 23 } },
});

const coverage = times.coverage([
  { semanticTime: "lunch", roleId: "server", targetCount: 3 },
  { semanticTime: "opening", roleId: "keyholder", targetCount: 1, priority: "MANDATORY" },
  // Type error: "dinner" is not a defined semantic time
  // { semanticTime: "dinner", roleId: "server", targetCount: 2 },
]);
const times = defineSemanticTimes({
  lunch: [
    {
      startTime: { hours: 11, minutes: 30 },
      endTime: { hours: 14 },
      days: ["monday", "tuesday", "wednesday", "thursday", "friday"],
    },
    { startTime: { hours: 12 }, endTime: { hours: 15 }, days: ["saturday", "sunday"] },
  ],
});
const coverage = times.coverage([
  { semanticTime: "lunch", roleId: "server", targetCount: 3 },
  // One-off party - concrete time
  {
    day: "2026-01-14",
    startTime: { hours: 15 },
    endTime: { hours: 20 },
    roleId: "server",
    targetCount: 5,
  },
]);