Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-13-2008, 04:53 PM   PM User | #1
Spudhead
Senior Coder

 
Spudhead's Avatar
 
Join Date: Jun 2002
Location: London, UK
Posts: 1,856
Thanks: 8
Thanked 110 Times in 109 Posts
Spudhead is on a distinguished road
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:
Quote:
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:

Quote:
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
Spudhead is offline   Reply With Quote
Old 06-16-2008, 04:43 PM   PM User | #2
Spudhead
Senior Coder

 
Spudhead's Avatar
 
Join Date: Jun 2002
Location: London, UK
Posts: 1,856
Thanks: 8
Thanked 110 Times in 109 Posts
Spudhead is on a distinguished road
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
Spudhead is offline   Reply With Quote
Old 08-06-2008, 09:56 AM   PM User | #3
ajy
New to the CF scene

 
Join Date: Aug 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
ajy is an unknown quantity at this point
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?
ajy is offline   Reply With Quote
Old 08-06-2008, 10:12 AM   PM User | #4
Spudhead
Senior Coder

 
Spudhead's Avatar
 
Join Date: Jun 2002
Location: London, UK
Posts: 1,856
Thanks: 8
Thanked 110 Times in 109 Posts
Spudhead is on a distinguished road
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
Spudhead is offline   Reply With Quote
Old 08-06-2008, 05:29 PM   PM User | #5
ajy
New to the CF scene

 
Join Date: Aug 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
ajy is an unknown quantity at this point
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.
ajy is offline   Reply With Quote
Old 08-07-2008, 01:19 PM   PM User | #6
Spudhead
Senior Coder

 
Spudhead's Avatar
 
Join Date: Jun 2002
Location: London, UK
Posts: 1,856
Thanks: 8
Thanked 110 Times in 109 Posts
Spudhead is on a distinguished road
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?
Spudhead is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:21 AM.


Advertisement
Log in to turn off these ads.