ColdFusion循环在相同的代码看起来不同的时间 [英] ColdFusion Loops to Seemingly Different Times in Same Code

查看:154
本文介绍了ColdFusion循环在相同的代码看起来不同的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下循环:

<cfloop from="#timeFormat(roomAvail.startTime,'short')#" to="#timeFormat(roomAvail.endTime,'short')#" step="#CreateTimeSpan(0,0,30,0)#" index="time">
    <cfoutput>
        #timeFormat(time,'short')#<br/>
    </cfoutput>
</cfloop>

当我的输入来自: 9:00 AM 到: 8:00 PM 代码每隔30分钟从上午9:00到下午7:30输出。

When my input is from:9:00 AM to:8:00 PM the code outputs every 30 min increment from 9:00 AM to 7:30 PM.

当我的输入来自: 10:00 AM 到: 1:00 PM 30分钟递增表格上午10:00到下午1:00。

When my input is from:10:00 AM to:1:00 PM the code outputs every 30 min increment form 10:00 AM to 1:00 PM.

任何人都可以解释发生了什么,为什么第一个循环中缺少一个30分钟段,而不是第二?我被告知这是一个有效的循环时间的方法,但我开始认为,因为时间被渲染为一个浮动的底层Java方法,一些舍入正在发生,它正在拧紧。

Can anyone explain what is happening and why there is one 30 min segment missing from the first loop and not the second? I was told this was a valid method of looping over times, but I'm starting to think that because the time is rendered as a float in the underlying Java method, some rounding is occurring and it's screwing up.

编辑:我真的不认为这很重要,我不传递日期/时间对象。

I really don't think it matters that I'm not passing in Date/Time objects. CF is casting that behind the scenes, otherwise the entire thing wouldn't work at all.

推荐答案

这将是因为下面的罩,所有CF正在做的是将日期转换为双打(或在你的情况:字符串到日期到双打),和晚上8点(1天的20/24)将有一个舍入误差,将其留在预期的上限;而下午1点(1天的13/24)在预期的上限之外是轻微的。

It'll be because under the hood, all CF is doing is converting the Dates to Doubles (or in your case: the Strings to Dates to Doubles), and 8pm (20/24ths of 1 day) will have a rounding error which leaves it within the intended upper boundary; whereas 1pm (13/24ths of 1 day) is slighty outside the intended upper boundary.

这可能不会帮助你传递一个字符串,当循环预期日期。

It probably doesn't help that you're passing a string when the loop is expecting dates.

这篇关于ColdFusion循环在相同的代码看起来不同的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆