@modern-kit/utils
Version:
32 lines (29 loc) • 957 B
JavaScript
import { parseDate } from '../parseDate/index.mjs';
import { objectKeys } from '../../object/objectKeys/index.mjs';
import '../parseDateString/index.mjs';
const TIME_UNITS = {
days: 1e3 * 60 * 60 * 24,
hours: 1e3 * 60 * 60,
minutes: 1e3 * 60,
seconds: 1e3
};
const TIME_UNITS_KEYS = objectKeys(TIME_UNITS);
function getDDay(date) {
const targetDate = parseDate(date);
const today = /* @__PURE__ */ new Date();
const timeDiff = targetDate.getTime() - today.getTime();
const isNegative = timeDiff < 0;
const absoluteDiff = Math.abs(timeDiff);
let remainingTime = absoluteDiff;
const calculateTime = () => {
return TIME_UNITS_KEYS.reduce((acc, key) => {
const value = Math.floor(remainingTime / TIME_UNITS[key]);
remainingTime %= TIME_UNITS[key];
acc[key] = value && isNegative ? -value : value;
return acc;
}, {});
};
return calculateTime();
}
export { getDDay };
//# sourceMappingURL=index.mjs.map