How to use the subDays function from date-fns
Find comprehensive JavaScript date-fns.subDays code examples handpicked from public code repositorys.
114 115 116 117 118 119 120 121 122 123
) const monthGrouped = Object.entries( _.groupBy(dateGrouped, ([date]) => { const d = Date.parse(date) return subDays(d, getDate(d) - 1) // first day of month }) ).sort(([a], [b]) => compareAsc(Date.parse(a), Date.parse(b))) const yearGrouped = Object.entries(_.groupBy(monthGrouped, ([date]) => getYear(Date.parse(date)))).sort(([a], [b]) =>
3
10
7
356 357 358 359 360 361 362 363 364 365
//Create token const cohort = await CohortModel.findOne({ name: sessionPhase1.cohort }); if (!cohort) return res.status(404).send({ ok: false, code: ERRORS.NOT_FOUND }); const startAt = datefns.subDays(new Date(cohort.dateStart), 7); const endDate = datefns.addDays(new Date(cohort.dateEnd), 7); const sessionToken = await sessionPhase1TokenModel.create({ token: crypto.randomBytes(50).toString("hex"),
4
8
4
+ 24 other calls in file
GitHub: v-garcia/home-server
68 69 70 71 72 73 74 75 76 77
} async function dailyRoutine(linkySession, gotifyClient, usagePointId) { // Determining min days let minDay = subDays(startOfToday(), SEEK_DAYS); minDay = dateMax([minDay, (await store.getLastDay(usagePointId)) || minDay]); minDay = addDays(minDay, 1); // Retrieving prices
0
3
2
168 169 170 171 172 173 174 175 176 177
exports.startOfTodayImpl = dateFns.startOfToday exports.startOfTomorrowImpl = dateFns.startOfTomorrow exports.startOfWeekImpl = dateFns.startOfWeek exports.startOfYearImpl = dateFns.startOfYear exports.startOfYesterdayImpl = dateFns.startOfYesterday exports.subDaysImpl = dateFns.subDays exports.subHoursImpl = dateFns.subHours exports.subISOYearsImpl = dateFns.subISOYears exports.subMillisecondsImpl = dateFns.subMilliseconds exports.subMinutesImpl = dateFns.subMinutes
0
2
1
+ 16 other calls in file
36 37 38 39 40 41 42 43 44
const TODAY = new Date() const START_DATE = new Date(2020, MON, 1, 0, 0, 0) let END_DATE = null if (MON == datefns.getMonth(TODAY)) { // Set end date to yesterday END_DATE = datefns.subDays(TODAY, 1) } else { END_DATE = datefns.lastDayOfMonth(START_DATE) }
0
2
2
GitHub: Team-AC/EMS-Server
69 70 71 72 73 74 75 76 77 78
.then((count) => { if ((count == 0)) { socket.emit("Pre - Generate Murb Power", () => { const dateInterval = { start: subDays(new Date(), amountOfDaysToSub[interval]), end: new Date() } preAddMurbPower(dateInterval)
0
1
1
+ 3 other calls in file
191 192 193 194 195 196 197 198 199 200
const dailyReward = getDailyRewardLevel( eachDayRewardToBeGranted.rewardTier ); // for (let i = 0; i < totalDaysToBeGranted; i++) { // const date = subDays(new Date(), i); // const dateString = format(date, "dd MM yyyy HH:mm"); // await CareerReward.create({ // user_id: retrievedUser.id,
0
0
1
+ 51 other calls in file
30 31 32 33 34 35 36 37 38
} } GetRecentCommitsDate(date) { let result = date; let recent_commits_date = subDays(new Date(), config.scraper.recent_commits_days); if (compareAsc(recent_commits_date, date) == 1) { result = recent_commits_date; }
0
0
0
+ 123 other calls in file
20 21 22 23 24 25 26 27 28 29
const instance = { userTimeZone, // Get a date with an offset lastMilliseconds: (milliseconds) => subMilliseconds(currentDate, milliseconds), lastHours: (hours) => subHours(currentDate, hours), lastDays: (days) => subDays(currentDate, days), lastMonths: (months) => subMonths(currentDate, months), lastYears: (years) => subYears(currentDate, years), // Get a date with an offset that always includes the whole unit of the given interval and a timezone toleranz includeDays: (days) => subHours(subDays(startOfDay(currentDate), days - 1), timeZoneToleranz),
0
0
0
70 71 72 73 74 75 76 77 78 79
const report = await reportDb.getById(connection, reportUser[0].reportid); if(reportUser[0].reporttype === "Weekly"){ endDate = new Date(); startDate = subDays(new Date(),7); } else if(reportUser[0].reporttype === "Monthly"){ endDate = new Date(); startDate = subMonths(new Date(),1);
0
0
0
date-fns.format is the most popular function in date-fns (3838 examples)