Files
gridpilot.gg/core/racing/domain/value-objects/JoinedAt.ts
2026-01-16 19:46:49 +01:00

27 lines
710 B
TypeScript

import type { ValueObject } from '@core/shared/domain/ValueObject';
import { RacingDomainValidationError } from '../errors/RacingDomainError';
export class JoinedAt implements ValueObject<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: ValueObject<Date>): boolean {
return this.props.getTime() === other.props.getTime();
}
}