Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts

    Reading an RFC822-formatted date?

    I'm writing a little admin system for updating our site news scroller. I would like the news scroller to be fed from our RSS xml file.

    Dates in RSS feeds, as I understand it, need to be formatted to RFC822. In short, they need to look like this:
    Fri, 13 Jun 2008 16:33:50 GMT
    The trouble is, that looks pretty rubbish squeezed into a news scroller. I want the dates in that to look like this:

    13.06.08
    But... VBScript, it seems, doesn't recognise RFC822-formatted dates as being dates: isDate("Fri, 13 Jun 2008 16:33:50 GMT") returns false.

    So how am I supposed to get the date back out of my RSS file?

    The only thing I can think of at the moment is to write a regexp to lift the relevant bits out of it. But that seems like a horribly complicated solution for a Friday afternoon when there's perfectly good drinking to be done, and I'm sure I'm not the only one who's come up against this problem, so I'm asking on here in the hope that someone can put me right

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    Looks like I'm the only person trying to read RFC822-formatted dates in VBScript, then...

    Anyway, I did a little regexp to get me the date out. It's nothing special but I'll stick it up here to save anyone else the bother:

    Code:
    function parseRSSDate(sRSSDate)
    '	take RFC822-formatted date string and return VBScript date object
    '	ie: "Fri, 13 Jun 2008 16:33:50 GMT"	
    
    	dim sDay, sMonthName, sMonthNum, sYear, sHour, sMinute, sSecond
    	dim oRE, oMatches, oMatch
    	dim sDate, oDate
    	
    	set oRE = new regexp
    		oRE.IgnoreCase	= True
    		oRE.Global		= True
    		oRE.Pattern		= "^([A-Za-z]{3}),\s([0-9]{1,2})\s([A-Za-z]{3})\s([0-9]{4})\s([0-9]{2}):([0-9]{2}):([0-9]{2})"
    		set oMatches = oRE.Execute(sRSSDate)
    			if oMatches.count > 0 then
    				set oMatch = oMatches(0)
    					sDay		= oMatch.SubMatches(1)
    					sMonthName	= oMatch.SubMatches(2)
    					sMonthNum	= monthVal(sMonthName)
    					sYear		= oMatch.SubMatches(3)
    					sHour		= oMatch.SubMatches(4)
    					sMinute		= oMatch.SubMatches(5)
    					sSecond		= oMatch.SubMatches(6)
    					sDate = sMonthNum & "/" & sDay & "/" & sYear
    					oDate = cDate(sDate)
    				set oMatch = nothing
    			end if
    		set oMatches = nothing
    	set oRE = nothing
    	parseRSSDate = oDate
    end function

  • #3
    ajy
    ajy is offline
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    same issue here

    I'm actually dealling with the exact same issue.

    But I am not a very experienced coder.

    How do I use your function?

  • #4
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    Like it says on the tin, really:

    Code:
    objDate = parseRSSDate("Fri, 13 Jun 2008 16:33:50 GMT")
    it also calls a function called monthVal, which just returns a number for a month name:

    Code:
    function monthVal(sMonthName)
    	' return month number (1-12) from month name
    	dim rv
    	dim aMonths : aMonths = Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
    	for i = 0 to uBound(aMonths)
    		if sMonthName = aMonths(i) then rv = i+1
    	next
    	monthVal = rv
    end function

  • #5
    ajy
    ajy is offline
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you for the quick reply! It's much appreciated.

    I'm pretty much an idiot when it comes to this stuff.

    This is the code I am using to display my RSS feed.

    http://www.tele-pro.co.uk/scripts/rs...d_class_dl.htm

    example: http://www.tele-pro.co.uk/scripts/rs...ed_class.1.txt

    it works great but the output of the PubDates is RFC822-formatted of course. I'd like to incorporate your code to parse it but I just cant seem to figure it out.

    The code on the page to display it is:


    <%
    ' +---------------------------------------------+
    ' | RSS Content Feed VBScript Class 1.0 |
    ' | © 2004 www.tele-pro.co.uk |
    ' | http://www.tele-pro.co.uk/scripts/rss/ |
    ' +---------------------------------------------+
    '
    ' Sample VBScript Code for the RSSContentFeed Class
    ' Example Code - Setting Properties
    ' sample_code_properties.asp

    %>
    <!-- #INCLUDE VIRTUAL="/rss/rss_content_feed_class.asp" -->
    <%

    'create object
    Dim rss
    Set rss= New RSSContentFeed

    'set content url
    rss.ContentURL = "http://www.somerssfeed.goesherecom/"

    'set content url
    rss.MaxResults = 10

    'set cache
    rss.Cache = ""

    'cache items for 2 days
    rss.CacheDays = 0

    'from cache?
    if rss.FromCache Then
    'item was returned from cache
    End If

    'display properties
    Response.Write "<br> rss.MaxResults: " & rss.MaxResults
    Response.Write "<br> rss.ContentURL: " & rss.ContentURL
    'Response.Write "<br> rss.CacheDays: " & rss.CacheDays

    'get content
    rss.GetRSS()

    %>
    <!-- EVENTS BOX STARTS-->
    <%

    Dim i
    For Each i in rss.Results

    response.Write ""
    response.Write "<div id=""rss_events"">"
    response.write "<span class=""pubdates"">" & rss.PubDates(i) & "<span> - <span class=""title""><a href=" & rss.Links(i) & ">" & rss.Titles(i) & "</a><span>"
    response.write "<br>"
    response.write "<span class=""descriptions"">" & rss.Descriptions(i) & "<span>"
    response.Write "</div>"

    Next

    Response.Write "<span style""font-size:.9em""><a href=" & rss.ContentURL & ">View Event Calendar</a></span><BR><BR><BR>"
    'release object
    Set rss= Nothing

    %>

    I have no understanding of how to add in your code.

  • #6
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    Well, I'm guessing that this bit:
    Code:
    rss.PubDates(i)
    writes out the RFC822-formatted date, right? So you pass that value into the function.

    Paste the function (well, the two functions that I posted: parseRSSDate() and monthVal() ) into your file, up at the top somewhere. It's not that important where right now.

    Then change this:
    Code:
    Dim i
    For Each i in rss.Results
    
    response.Write ""
    response.Write "<div id=""rss_events"">"
    response.write "<span class=""pubdates"">" & rss.PubDates(i) & "<span> - <span class=""title""><a href=" & rss.Links(i) & ">" & rss.Titles(i) & "</a><span>"
    response.write "<br>"
    response.write "<span class=""descriptions"">" & rss.Descriptions(i) & "<span>"
    response.Write "</div>"
    
    Next
    to look like this:

    Code:
    Dim i
    For Each i in rss.Results
    
    objDate = parseRSSDate(rss.PubDates(i))
    sDateDay = datePart("D", objDate)
    sDateMonth = datePart("M", objDate)
    sDateYear = datePart("YYYY", objDate)
    sDateDisplay = sDateDay & "/" & sDateMonth & "/" & sDateYear 
    
    response.Write ""
    response.Write "<div id=""rss_events"">"
    response.write "<span class=""pubdates"">" & sDateDisplay & "<span> - <span class=""title""><a href=" & rss.Links(i) & ">" & rss.Titles(i) & "</a><span>"
    response.write "<br>"
    response.write "<span class=""descriptions"">" & rss.Descriptions(i) & "<span>"
    response.Write "</div>"
    
    Next
    Does that make sense?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •