dtable-utils
Version:
dtable common utils
30 lines (25 loc) • 752 B
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var sort = require('../../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.SORT_TYPE.UP ? 1 : -1;
}
if (leftDate < rightDate) {
return sortType === sort.SORT_TYPE.UP ? -1 : 1;
}
return 0;
};
exports.sortDate = sortDate;