gpt4 book ai didi

date - 根据日期范围和设置的星期几获取出现次数

转载 作者:行者123 更新时间:2023-12-02 14:18:43 29 4
gpt4 key购买 nike

我正在尝试根据以下已知参数计算将发生的事件总数

  1. 开始日期
  2. 结束日期
  3. 一周中的几天
  4. 周的频率(每周、每两周等)

例如,基于以下示例数据:

  1. 2017 年 5 月 1 日
  2. 2017 年 5 月 31 日
  3. 1,4(周日、周三)
  4. 每两周一次

我必须计算出此事件将运行四次(5/7、5/10、5/21、5/24)

下面是我设置的骨架。我完全困惑于如何根据已经过去的周数来增加循环中的当前日期。

<cfset local.totalRuns = 0 />

<cfset local.startDate = '2017-05-01' />
<cfset local.endDate = '2017-05-31' />
<cfset local.totalDays = DateDiff("d", local.startDate, local.endDate) />

<cfset local.daysPerWeek = '1,4' />
<cfset local.recurrence = 2 />

<cfset local.currentLoop = 0 />
<cfset local.weeksToCount = local.recurrence * 2 />

<!--- Loop a day at a time --->
<cfloop from="#local.startDate#" to="#local.endDate#" index="local.thisDay" step="#createTimespan(1, 0, 0, 0)#">

<cfset local.currentDate = local.thisDay />

<!--- Loop over each allowed day of the current week and determine actual date --->
<cfloop list="#local.daysPerWeek#" index="local.currentDay">


<!--- if current date does not exceed the end date add increment (this current is incorrect) --->
<cfif DateDiff("d", local.currentDate, local.endDate) LTE 0>
<cfset local.totalRuns++ />
</cfif>
</cfloop>

<cfset local.currentLoop++ />
</cfloop>

最佳答案

这是一条格式化的评论。它显示了我将采取的方法。

set the recurrence count to 0

start looping through the list of valid days of the week (1,4) in this case

set the control date to the start date.

do something to set the control date to the earliest
date that matches the day of the week in this loop.

if the control date is greater than the end date, break out of the loop.
otherwise

add 1 to the recurrence count

set up a while loop that adds the specified number of weeks
to the control date, and repeats the check I just described

end looping through the list of valid days of the week (1,4) in this case

关于date - 根据日期范围和设置的星期几获取出现次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43871647/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com