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: To Fix//BugVerified

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

Created: 12/29/2017

Components: 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