Files
gridpilot.gg/packages/racing/domain/value-objects/WeekdaySet.ts
2025-12-05 12:24:38 +01:00

23 lines
572 B
TypeScript

import type { Weekday } from './Weekday';
import { weekdayToIndex } from './Weekday';
export class WeekdaySet {
private readonly days: Weekday[];
constructor(days: Weekday[]) {
if (!Array.isArray(days) || days.length === 0) {
throw new Error('WeekdaySet requires at least one weekday');
}
const unique = Array.from(new Set(days));
this.days = unique.sort((a, b) => weekdayToIndex(a) - weekdayToIndex(b));
}
getAll(): Weekday[] {
return [...this.days];
}
includes(day: Weekday): boolean {
return this.days.includes(day);
}
}