CFFEED and Date Values

I ran into an interesting issue this week with my work at Broadchoice and the RSS feeds that some of my code was generating. For some reason the times were off by multiple hours. It wasn’t a database issue. When viewing the data in non-RSS mode it was perfect. But as soon as I switched to the RSS feed the problem was pretty bad. Because the hours were so far off, new data wasn’t showing up in feed readers.

I did some reading (and remember, CFFEED isn’t covered at all in the developer’s guide - just the reference) and came across this note:

When the cffeed tag creates a feed, you can use W3C or RFC 822 formats for both feed types. You can also use any standard date or date/time format accepted by ColdFusion.

Now I read this as - “You can use a normal CF date and I’m cool with it.” But that isn’t the case. When I viewed source on the XML generated by CFFEED, the times were marked as GMT but were still in the original value. What I mean is, the time had originally been 1PM EST, but the XML said 1PM GMT, which is obviously way wrong.

Fixing this was a bit difficult. (And if folks know a simpler solution, speak up!) I began by using GMTDateFormat. This UDF takes a date and an offset value. It returns a time in GMT. The offset though can’t be just a number. It had to be in the form of

+NNMM

or

-NNMM

So I knew I could get the offset using getTimeZoneInfo(). However, this returned a simple value, like 5, not +05. I ended up using this code:

<cfset var tz = getTimeZoneInfo()> <cfset var offset = numberFormat(tz.utcHourOffset,"00") & numberFormat(tz.utcMinuteOffset, "00")>

<!— implies no - —> <cfif len(offset) is 4> <cfset offset = “+” & offset> </cfif> </code>

Once I did this - and used the UDF - my feeds started showing the right values. Maybe I’m crazy but it sure would be nice if this was handled by the tag for me.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Comments