UNPKG

ravendb

Version:
44 lines 1.13 kB
import { throwError } from "../Exceptions/index.js"; export class DatesComparator { static compare(lhs, rhs) { if (lhs.date && rhs.date) { return lhs.date.getTime() - rhs.date.getTime(); } // lhr or rhs is null - unify values using context const leftValue = lhs.date ? lhs.date.getTime() : (lhs.context === "From" ? Number.MIN_SAFE_INTEGER : Number.MAX_SAFE_INTEGER); const rightValue = rhs.date ? rhs.date.getTime() : (rhs.context === "From" ? Number.MIN_SAFE_INTEGER : Number.MAX_SAFE_INTEGER); return leftValue - rightValue; } } /** * Date or MinDate if null */ export function leftDate(date) { return { date, context: "From" }; } /** * Date or MaxDate if null */ export function rightDate(date) { return { date, context: "To" }; } export function definedDate(date) { if (!date) { throwError("InvalidArgumentException", "Date cannot be null"); } return { date, context: "To" }; } //# sourceMappingURL=DatesComparator.js.map