refactor
This commit is contained in:
20
core/racing/domain/entities/Year.ts
Normal file
20
core/racing/domain/entities/Year.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user