1

I have a project I'm creating in Coldfusion 10 and it's almost done but I just need to display how long it is has been since the last update in the XML feed. I know this shouldn't be too difficult but I can't seem to figure it out.

The project is feed by an XML feed from a publication and of all the pubdates in the feed I need to find out which pubdate is the most recent(they may not be in chronological order in the feed). I also need to compare the most recent pubdate in the feed to the current local time which is PDT and pubdates in feed are listed in GMT. I already have the XML parsed out and the pubdates are captured in a variable named "rssDate" and the pubdates are formatted like: {ts '2014-06-27 20:48:46'}.

Here are the needed elements broken out

  1. Find most recent pubdate in the XML feed
  2. Convert the most recent pubdate (date & time) from GMT to PDT and display as last update time stamp
  3. Determine the time since publication of the most recent pubdate and output as color coded display based on time ranges (see included output code).

Color coded output of time since last update based upon time range

<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>
duncan
  • 31,401
  • 13
  • 78
  • 99
  • Your first line looks at a variable named timeDifference. How does this variable pertain to your question? Also, from where does it come? – Dan Bracuk Jun 30 '14 at 02:21
  • I envisioned that when the earliest pubdate was determined and that time would be compared with the current local PDT time. Then I would be able to display the time frame in a series of time segments with color coded display to bring attention to how long it has been since the last update. So the difference between the last updated and the current time would be stored in the variable timeDifference. I actually had this working but the code was terribly convoluted and never correct. – user3788682 Jun 30 '14 at 02:39

1 Answers1

-1

There are many way to do it. One is as as PDT is 7 hours behind GMT. Adding 7 hours in your PDT time will make it GMT and then you can compare both. (You can do it all on a single line, just for more clarity breaking it up)

<cfset myGMTTime=DateAdd("h",7,now())>
<cfset rssDat="2014-06-27 20:48:46"> <!---as you said you have this figured out--->
<cfset timeElapsed=DateDiff("n",myGMTTime,rssDate)><!---can use "h" for hours or "s" for seconds. It is "n" for minutes. "m" is used for months--->
CFML_Developer
  • 1,565
  • 7
  • 18