UNPKG

dtable-utils

Version:

dtable common utils

26 lines (23 loc) 661 B
import { SORT_TYPE } from '../../constants/sort.js'; /** * Sort date * @param {string} leftDate e.g. '2023-07-31' * @param {string} nextDate * @param {string} sortType e.g. 'up' | 'down' * @returns number */ var sortDate = function sortDate(leftDate, rightDate, sortType) { var emptyLeftDate = !leftDate; var emptyRightDate = !rightDate; if (emptyLeftDate && emptyRightDate) return 0; if (emptyLeftDate) return 1; if (emptyRightDate) return -1; if (leftDate > rightDate) { return sortType === SORT_TYPE.UP ? 1 : -1; } if (leftDate < rightDate) { return sortType === SORT_TYPE.UP ? -1 : 1; } return 0; }; export { sortDate };