UNPKG

@takentrade/takentrade-libs

Version:
31 lines (30 loc) 991 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isToday = exports.calculateNextDate = void 0; /** * Calculate next date based on frequency */ const calculateNextDate = (frequency, lastDate) => { const nextDate = new Date(lastDate); const frequencyMap = { DAILY: () => nextDate.setDate(nextDate.getDate() + 1), WEEKLY: () => nextDate.setDate(nextDate.getDate() + 7), MONTHLY: () => nextDate.setMonth(nextDate.getMonth() + 1), }; const calculateFn = frequencyMap[frequency]; if (!calculateFn) throw new Error('Invalid frequency'); calculateFn(); return nextDate; }; exports.calculateNextDate = calculateNextDate; /** * Check if a given date is today */ const isToday = (date) => { const today = new Date(); return (date.getDate() === today.getDate() && date.getMonth() === today.getMonth() && date.getFullYear() === today.getFullYear()); }; exports.isToday = isToday;