37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import { RaceTimeOfDay } from './RaceTimeOfDay';
|
|
import { LeagueTimezone } from './LeagueTimezone';
|
|
import type { RecurrenceStrategy } from './RecurrenceStrategy';
|
|
import { RacingDomainValidationError } from '../errors/RacingDomainError';
|
|
|
|
export class SeasonSchedule {
|
|
readonly startDate: Date;
|
|
readonly timeOfDay: RaceTimeOfDay;
|
|
readonly timezone: LeagueTimezone;
|
|
readonly recurrence: RecurrenceStrategy;
|
|
readonly plannedRounds: number;
|
|
|
|
constructor(params: {
|
|
startDate: Date;
|
|
timeOfDay: RaceTimeOfDay;
|
|
timezone: LeagueTimezone;
|
|
recurrence: RecurrenceStrategy;
|
|
plannedRounds: number;
|
|
}) {
|
|
if (!(params.startDate instanceof Date) || Number.isNaN(params.startDate.getTime())) {
|
|
throw new RacingDomainValidationError('SeasonSchedule.startDate must be a valid Date');
|
|
}
|
|
if (!Number.isInteger(params.plannedRounds) || params.plannedRounds <= 0) {
|
|
throw new RacingDomainValidationError('SeasonSchedule.plannedRounds must be a positive integer');
|
|
}
|
|
|
|
this.startDate = new Date(
|
|
params.startDate.getFullYear(),
|
|
params.startDate.getMonth(),
|
|
params.startDate.getDate(),
|
|
);
|
|
this.timeOfDay = params.timeOfDay;
|
|
this.timezone = params.timezone;
|
|
this.recurrence = params.recurrence;
|
|
this.plannedRounds = params.plannedRounds;
|
|
}
|
|
} |