Posted By

parkerkrhoyt on 12/27/10


Tagged

time parse object rss feed date String


Versions (?)

Parse an RSS Date/Time String Into a Date/Time Object


 / Published in: ColdFusion
 

Parsing an RSS date/time value (as a string) into a date/time object in ColdFusion.

And more additional text.

  1. <cffunction
  2. access="public"
  3. name="ParseAtomDate"
  4. returntype="date"
  5. displayname="ParseAtomDate"
  6. description="Parses a date from an Atom feed">
  7.  
  8. <cfargument
  9. name="feeddate"
  10. type="string"
  11. required="yes"
  12. displayname="The date in string format as displayed in the feed">
  13.  
  14. <cfset LOCAL.year = Left( ARGUMENTS.feeddate, 4 )/>
  15. <cfset LOCAL.year = LSParseNumber( LOCAL.year )/>
  16.  
  17. <cfset LOCAL.start = Find( "-", ARGUMENTS.feeddate ) + 1/>
  18. <cfset LOCAL.end = Find( "-", ARGUMENTS.feeddate, LOCAL.start )/>
  19. <cfset LOCAL.month = Mid( ARGUMENTS.feeddate, LOCAL.start, LOCAL.end - LOCAL.start )/>
  20. <cfset LOCAL.month = LSParseNumber( LOCAL.month )/>
  21.  
  22. <cfset LOCAL.start = LOCAL.end + 1/>
  23. <cfset LOCAL.end = Find( "T", ARGUMENTS.feeddate, LOCAL.start )/>
  24. <cfset LOCAL.day = Mid( ARGUMENTS.feeddate, LOCAL.start, LOCAL.end - LOCAL.start )/>
  25. <cfset LOCAL.day = LSParseNumber( LOCAL.day )/>
  26.  
  27. <cfset LOCAL.start = LOCAL.end + 1/>
  28. <cfset LOCAL.end = Find( ":", ARGUMENTS.feeddate, LOCAL.start )/>
  29. <cfset LOCAL.hour = Mid( ARGUMENTS.feeddate, LOCAL.start, LOCAL.end - LOCAL.start )/>
  30. <cfset LOCAL.hour = LSParseNumber( LOCAL.hour )/>
  31.  
  32. <cfset LOCAL.start = LOCAL.end + 1/>
  33. <cfset LOCAL.end = Find( ":", ARGUMENTS.feeddate, LOCAL.start )/>
  34. <cfset LOCAL.minute = Mid( ARGUMENTS.feeddate, LOCAL.start, LOCAL.end - LOCAL.start )/>
  35. <cfset LOCAL.minute = LSParseNumber( LOCAL.minute )/>
  36.  
  37. <cfset LOCAL.start = LOCAL.end + 1/>
  38. <cfset LOCAL.end = Find( "-", ARGUMENTS.feeddate, LOCAL.start )/>
  39. <cfset LOCAL.second = Mid( ARGUMENTS.feeddate, LOCAL.start, LOCAL.end - LOCAL.start )/>
  40. <cfset LOCAL.second = LSParseNumber( LOCAL.second )/>
  41.  
  42. <cfreturn CreateDateTime( LOCAL.year, LOCAL.month, LOCAL.day, LOCAL.hour, LOCAL.minute, LOCAL.second )/>
  43.  
  44. </cffunction>

Report this snippet  

You need to login to post a comment.