我有一个在 Coldfusion 10 中创建的项目,它几乎完成了,但我只需要显示自 XML 提要中的最后一次更新以来已经过去了多长时间。我知道这应该不会太难,但我似乎无法弄清楚。
该项目由来自出版物的 XML 提要和提要中的所有发布日期提供,我需要找出哪个发布日期是最新的(它们在提要中可能不是按时间顺序排列的)。我还需要将提要中的最新发布日期与当前本地时间(即 PDT)进行比较,并且提要中的发布日期在 GMT 中列出。我已经解析出 XML,并且发布日期被捕获在名为“rssDate”的变量中,并且发布日期的格式如下:{ts'2014-06-27 20:48:46'}。
这是分解所需的元素
- 在 XML 提要中查找最近的发布日期
- 将最新的发布日期(日期和时间)从 GMT 转换为 PDT 并显示为最后更新时间戳
- 确定自最近发布日期发布以来的时间,并根据时间范围以彩色编码显示输出(请参阅包含的输出代码)。
基于时间范围的自上次更新以来的时间颜色编码输出
<cfif timeDifference LT 1>
<cfset meterColor = "4bbd07">
<cfset colorName = "Green">
<cfset messageText = "Updated less than one hour ago">
<cfelseif timeDifference GTE 1 AND timeDifference LT 1.3>
<cfset meterColor = "64ff06">
<cfset colorName = "Lime">
<cfset messageText = "Updated less than one and a half hours ago">
<cfelseif timeDifference GTE 1.3 AND timeDifference LT 2>
<cfset meterColor = "fffc06">
<cfset colorName = "Yellow">
<cfset messageText = "Updated more than two hours ago">
<cfelseif timeDifference GTE 2 AND timeDifference LT 2.3>
<cfset meterColor = "fdae15">
<cfset colorName = "Orange">
<cfset messageText = "Updated more than two hours ago">
<cfelseif timeDifference GTE 2.3 AND timeDifference LT 3>
<cfset meterColor = "ff00fc">
<cfset colorName = "Pink">
<cfset messageText = "Updated more than two and a half hours ago">
<cfelseif timeDifference GTE 3>
<cfset meterColor = "fe0000">
<cfset colorName = "Red">
<cfset messageText = "Updated more than three hours ago">
</cfif>