20 lines
512 B
TypeScript
20 lines
512 B
TypeScript
import { RacingDomainValidationError } from '../errors/RacingDomainError';
|
|
|
|
export class Year {
|
|
private constructor(private readonly value: number) {}
|
|
|
|
static create(value: number): Year {
|
|
if (value < 1900 || value > new Date().getFullYear() + 1) {
|
|
throw new RacingDomainValidationError('Year must be between 1900 and next year');
|
|
}
|
|
return new Year(value);
|
|
}
|
|
|
|
toNumber(): number {
|
|
return this.value;
|
|
}
|
|
|
|
equals(other: Year): boolean {
|
|
return this.value === other.value;
|
|
}
|
|
} |