Compares this Value Object with another for equality. Value Objects are equal if they are of the same type and all equality components match.
The other Value Object to compare with
true if the Value Objects are equal, false otherwise
StaticcreateCreates a DateRange instance with validation.
The start date of the range
The end date of the range
Success with DateRange or Failure with DomainError
const result = DateRange.create(
new Date('2024-01-01'),
new Date('2024-12-31')
);
if (result.isSuccess) {
console.log(result.value.startDate); // 2024-01-01
}
const invalid = DateRange.create(
new Date('2024-12-31'),
new Date('2024-01-01')
);
if (invalid.isFailure) {
console.log(invalid.error.code); // "INVALID_DATE_RANGE"
}
StaticfromCreates a DateRange from ISO date strings.
The start date as ISO string
The end date as ISO string
Success with DateRange or Failure with DomainError
Checks if a date is within this range (inclusive).
The date to check
true if the date is within the range
Checks if this range overlaps with another range.
The other DateRange to check
true if the ranges overlap
Checks if this range completely contains another range.
The other DateRange to check
true if this range contains the other range
Checks if this range is adjacent to another range (touching but not overlapping).
The other DateRange to check
true if the ranges are adjacent
Creates a new DateRange that is the intersection of this range and another.
The other DateRange
Success with intersection DateRange or Failure if no overlap
ProtectedgetReturns the components that determine equality for this Value Object. Two Value Objects are equal if all their equality components are equal.
An array of values used for equality comparison
Returns a string representation of an object.
Represents a date range with start and end dates.
DateRange is immutable and ensures that the end date is not before the start date. Provides utility methods for checking overlaps, containment, and duration.
Example