Files
gridpilot.gg/core/racing/domain/value-objects/JoinedAt.ts
2025-12-17 01:23:09 +01:00

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();
}
}