vremel
Version:
JavaScript date utility library for Temporal API
15 lines • 560 B
JavaScript
import { closestIndexTo } from "./closestIndexTo.js";
/**
* Returns the closest datetime object to the given datetime object from the passed array.
* @param dateTimeToCompare the date to compare with
* @param dateTimes array of datetime objects
* @returns the closest datetime object
*/
export function closestTo(dateTimeToCompare, dateTimes) {
const ret = dateTimes[closestIndexTo(dateTimeToCompare, dateTimes)];
if (ret === undefined) {
throw new Error("Something wrong...");
}
return ret;
}
//# sourceMappingURL=closestTo.js.map