I have recently written some code which schedules messages to send to one of our SMTP servers. This data is stored in an MySQL database. The algorithm schedules messages based on an hourly limit. Here is a portion of the algorithm, which is within a loop to schedule as many messages as required.
<cfif hourlyLimit lte 60>
<cfset minutesPerMail = 60 / hourlyLimit>
<cfset minutesAdd = int(minutesPerMail)>
<cfset secondsAdd = round((minutesPerMail % 1) * 60)>
<cfset queueDate = #DateAdd('n', minutesAdd, queueDate)#>
<cfset queueDate = #DateAdd('s', secondsAdd, queueDate)#>
For debugging purposes, I appended the following code to this portion…
<cfdump var="#minutesPerMail#"> (Outputs 1.421857...)
<cfdump var="#secondsAdd#"> (Outputs 0)
I originally suspect there may be a rounding error, and as such, I then added the following code…
<cfset modTest = minutesPerMail % 1>
<cfdump var="#modTest#"> (Outputs 0)
As you can see, by the use of the modTest variable, the modulus function is not working appropriately, as the proper output would be .421857… .
EDIT/SOLUTION: Performing a modulus action within ColdFusion returns an integer, not a float, and thus will automatically round the element to zero.
Can’t you just change it to this: