tracker issue : CF-4200445

select a category, or use search below
(searches all categories and all time range)
Title:

Inconsistent loop results using a fractional step such as a timespan

| View in Tracker

Status/Resolution/Reason: Closed/Withdrawn/Workaround

Reporter/Name(from Bugbase): Matt Davis / Matt Davis ()

Created: 12/29/2017

Components: Language, Functions

Versions: 2016,11.0

Failure Type: Incorrectly functioning

Found In Build/Fixed In Build: Coldfusion 10 (Update 23) & Coldfusion 2016 (Update 5) (likey in 11 but do not have) /

Priority/Frequency: Normal / All users will encounter

Locale/System: English / Win 2016

Vote Count: 1

Problem Description: when running a loop using a timespan in the step attribute sometime the loop does not stop at the proper endpoint (TO attribute)

A version of the code came from URL:
https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-tags/tags-j-l/cfloop-looping-over-a-date-or-time-range.html

Steps to Reproduce:

<cfoutput>
	
<cfset startTime = CreateTime(10,0,0)> 
<cfset endTime = CreateTime(15,0,0)>

startTime=#startTime#<br>
endTime=#endTime#<br>
step=#CreateTimeSpan(0,0,15,0)# (every fifteen minutes)<br>

<cfloop from="#startTime#" to="#endTime#" index="i" step="#CreateTimeSpan(0,0,15,0)#"> 
	#TimeFormat(i, "hh:mm:ss tt")#<BR>
</cfloop>


<HR></HR>


<cfset dtStart = "10:00 AM" />
<cfset dtEnd = "3:00 PM" />

dtStart=#dtStart#<br>
dtEnd=#dtEnd#<br>
step=#(1/24)# (every hour)<br>

<cfloop
	index="dtHour"
	from="#dtStart#"
	to="#dtEnd#"
	step="#(1/24)#">

	#TimeFormat( dtHour, "h:mm TT" )#<br />

</cfloop>

</cfoutput>


Actual Result:

startTime={ts '1899-12-30 10:00:00'}
endTime={ts '1899-12-30 15:00:00'}
step=0.0104166666667 (every fifteen minutes)
10:00:00 AM
10:15:00 AM
10:30:00 AM
10:45:00 AM
11:00:00 AM
11:15:00 AM
11:30:00 AM
11:45:00 AM
12:00:00 PM
12:15:00 PM
12:30:00 PM
12:45:00 PM
01:00:00 PM
01:15:00 PM
01:30:00 PM
01:45:00 PM
02:00:00 PM
02:15:00 PM
02:30:00 PM
02:45:00 PM


dtStart=10:00 AM
dtEnd=3:00 PM
step=0.0416666666667 (every hour)
10:00 AM
11:00 AM
12:00 PM
1:00 PM
2:00 PM


Expected Result:

startTime={ts '1899-12-30 10:00:00'}
endTime={ts '1899-12-30 15:00:00'}
step=0.0104166666667 (every fifteen minutes)
10:00:00 AM
10:15:00 AM
10:30:00 AM
10:45:00 AM
11:00:00 AM
11:15:00 AM
11:30:00 AM
11:45:00 AM
12:00:00 PM
12:15:00 PM
12:30:00 PM
12:45:00 PM
01:00:00 PM
01:15:00 PM
01:30:00 PM
01:45:00 PM
02:00:00 PM
02:15:00 PM
02:30:00 PM
02:45:00 PM
03:00:00 PM

dtStart=10:00 AM
dtEnd=3:00 PM
step=0.0416666666667 (every hour)
10:00 AM
11:00 AM
12:00 PM
1:00 PM
2:00 PM
3:00 PM

Any Workarounds:

Attachments:

Comments:

Hi Matt, If you think that's fun, try changing `TimeFormat(i, "hh:mm:ss tt")` to `i.timeFormat("hh:mm:ss tt")`. It's really a mixed bag of multiple issues and CF trying to be something it's not. Adobe, you know what the issue(s) are right? And CF should also use BigDecimal. Thanks!, -Aaron
Comment by Aaron N.
29426 | August 03, 2018 08:37:08 AM GMT
+1...........
Vote by Aaron N.
29428 | August 03, 2018 08:40:43 AM GMT
Nevermind, forgot CF-4199861 would resolve this. Thanks!, -Aaron
Comment by Aaron N.
29427 | August 03, 2018 08:45:19 AM GMT
  One workaround I would suggest is to convert into millis by multiplication with 86400000 and iterate.   Code -  <cfoutput> <cfset startTime = CreateTime(10,0,0)> <cfset endTime = CreateTime(15,0,0)> startTime=#startTime#<br> endTime=#endTime#<br> step=#CreateTimeSpan(0,0,15,0)# (every fifteen minutes)<br> <cfset x = round(#startTime# * 86400000)> <cfset y = round(#endTime# * 86400000)> <cfset z = round(#CreateTimeSpan(0,0,15,0)# * 86400000)> <cfloop from="#x#" to="#y#" index="i" step="#z#"> #TimeFormat(i/86400000, "hh:mm:ss tt")#<BR> </cfloop> <HR></HR> <cfset dtStart = "10:00 AM" /> <cfset dtEnd = "3:00 PM" /> dtStart=#dtStart#<br> dtEnd=#dtEnd#<br> step=#(1/24)# (every hour)<br> <cfset f = round(#dtStart# * 86400000) > <cfset t = round(#dtEnd# * 86400000)> <cfset s = round(86400000/24) > <cfloop index="dtHour" from="#f#" to="#t#" step="#s#"> #TimeFormat( dtHour/86400000, "h:mm TT" )#<br /> </cfloop> </cfoutput> Please let us know if it works for you..
Comment by Nikhil D.
30739 | May 08, 2019 03:45:50 PM GMT
Hi Matt , We hope that the workaround suggested worked for you . We are closing thsi bug for now. Regards, Suchika
Comment by Suchika S.
33234 | March 03, 2020 08:01:04 AM GMT