vremel
Version:
JavaScript date utility library for Temporal API
29 lines • 1.18 kB
JavaScript
import { getConstructor, getTypeName, isInstant, isPlainDate, isPlainDateTime, isPlainMonthDay, isPlainTime, isPlainYearMonth, isZonedDateTime, } from "../type-utils.js";
export function compare(a, b) {
if (isInstant(a) && isInstant(b)) {
return getConstructor(a).compare(a, b);
}
if (isZonedDateTime(a) && isZonedDateTime(b)) {
return getConstructor(a).compare(a, b);
}
if (isPlainDate(a) && isPlainDate(b)) {
return getConstructor(a).compare(a, b);
}
if (isPlainTime(a) && isPlainTime(b)) {
return getConstructor(a).compare(a, b);
}
if (isPlainDateTime(a) && isPlainDateTime(b)) {
return getConstructor(a).compare(a, b);
}
if (isPlainYearMonth(a) && isPlainYearMonth(b)) {
if (a.calendarId !== b.calendarId) {
throw new Error("Can't compare PlainYearMonth with different calendar");
}
return getConstructor(a).compare(a, b);
}
if (isPlainMonthDay(a) || isPlainMonthDay(b)) {
throw new Error("Can't compare PlainMonthDay");
}
throw new Error(`Can't compare ${getTypeName(a)} and ${getTypeName(b)}`);
}
//# sourceMappingURL=_compare.js.map