UNPKG

dateweeks

Version:

it will generate date with week to take from date and to date from user . it automatically generate fromm and to date

38 lines (30 loc) 1.23 kB
class Dates { dateWeek = (from_date, toDate) => { let calnderData = [] var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']; const date = new Date(new Date(from_date).getTime()); for (let i = date; i <= new Date(toDate); i.setDate(i.getDate() + 1)) { let dy_id = 0; if (i.getDay() == 0) { dy_id = 7 } else { dy_id = i.getDay() } var monthval = ((isDigit(i.getMonth() + 1)) ? ('0' + (i.getMonth() + 1)) : (i.getMonth() + 1)); var dayval = ((isDigit(i.getDate())) ? ('0' + (i.getDate())) : (i.getDate())) calnderData.push({ date: i.getFullYear() + '-' + monthval + '-' + dayval, dt: i.getDate(), mnth: i.getMonth() + 1, yr: i.getFullYear(), dy_id: dy_id, weekeDays: days[i.getDay()] }); } return calnderData } } function isDigit(val) { return String(+val).charAt(0) == val; } // var dates = new Dates() // console.log(dates.dateWeek('2024-02-12', '2024-02-15'), isDigit(12)) module.exports = Dates