Javascript-遍历一系列约会,找到下一个可用的]] << [

问题描述 投票:1回答:2
给定x天的时间,我试图遍历一系列约会(这些对象包含startDateendDate),并发现x天中没有安排约会的最快发生时间[[C0 ])。尝试使用时刻,但我不确定这是否是正确(或最优雅)的路线。注意:我不仅要解决所有约会之后的第一个开放日,因为现有约会之间可能会有开放日]

pendingStartDate

给定x天,我试图遍历一系列约会(包含startDate和endDate的对象),并找到x天中没有约会的最快发生时间...
javascript reactjs momentjs scheduling date-range
2个回答
0
投票
import Moment from 'moment'; import { extendMoment } from 'moment-range'; const moment = extendMoment(Moment); const determineStartDate = (daysNeeded, existingAppts) => { // this is about as far as I've gotten... pendingStartDate = moment(); existingAppts.forEach((a) => { range = moment.range(moment(a.startDate), moment(a.endDate); console.log(range.contains(pendingStartDate)); }) } // just some dummy code to help explain const daysNeeded = 2 const existingAppts = [ { startDate: '2020-06-15', endDate: '2020-06-17' }, { startDate: '2020-06-14', endDate: '2020-06-14' }, ] const pendingStartDate = determineStartDate(daysNeeded, existingAppts);

0
投票
© www.soinside.com 2019 - 2024. All rights reserved.