26 lines
700 B
TypeScript
26 lines
700 B
TypeScript
import { RacingDomainValidationError } from '../errors/RacingDomainError';
|
|
import type { IValueObject } from '@core/shared/domain';
|
|
|
|
export class JoinedAt implements IValueObject<Date> {
|
|
private constructor(private readonly value: Date) {}
|
|
|
|
static create(value: Date): JoinedAt {
|
|
const now = new Date();
|
|
if (value > now) {
|
|
throw new RacingDomainValidationError('Joined date cannot be in the future');
|
|
}
|
|
return new JoinedAt(new Date(value));
|
|
}
|
|
|
|
toDate(): Date {
|
|
return new Date(this.value);
|
|
}
|
|
|
|
get props(): Date {
|
|
return new Date(this.value);
|
|
}
|
|
|
|
equals(other: IValueObject<Date>): boolean {
|
|
return this.props.getTime() === other.props.getTime();
|
|
}
|
|
} |