UNPKG

@modern-kit/utils

Version:
34 lines (30 loc) 1.02 kB
'use strict'; var dateParseDate = require('../parseDate/index.cjs'); var objectObjectKeys = require('../../object/objectKeys/index.cjs'); require('../parseDateString/index.cjs'); const TIME_UNITS = { days: 1e3 * 60 * 60 * 24, hours: 1e3 * 60 * 60, minutes: 1e3 * 60, seconds: 1e3 }; const TIME_UNITS_KEYS = objectObjectKeys.objectKeys(TIME_UNITS); function getDDay(date) { const targetDate = dateParseDate.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(); } exports.getDDay = getDDay; //# sourceMappingURL=index.cjs.map