Thank you belltown and agmark for these code samples. I didn't know how to use the roRegex for this type of function either. I'd searched far and wide on how to convert these non-standard dates to ones I could manipulate and I finally came across this post.
For my needs I was trying to convert into a more standard date format but I was working with the same type of date/time as agmark, although mine was in this format "Tue, 03 Feb 2015 04:02:11 +0000". Fortunately this same code formatted it properly for me as well. I'm using the MRSS Template to pull in rss feeds to make my channel and some of the rss feeds don't use standard date formats. This was a big help. However it took me a little tweaking and further research to be able to manipulate my dates into the format I wanted.
I wound up making a function I could call in the NWM_Utilities.brs file of the MRSS Template, so I could re-use this code as needed. I call it using the following code.
dateTmp = util.convertDate(releaseDate)
I'm using the 1.2.1 version of the MRSS Template and the code above was added to the NWM_MRSS.brs file in the "else" section of the "release date" section. Here is the whole section if you just want to replace it.
' release date
if item.GetNamedElements("blip:datestamp").Count() > 0
dt = CreateObject("roDateTime")
dt.FromISO8601String(ValidStr(item.GetNamedElements("blip:datestamp")[0].GetText()))
newItem.releaseDate = dt.AsDateStringNoParam()
else
releaseDate = ValidStr(item.pubdate.GetText())
dateTmp = util.convertDate(releaseDate)
newItem.releaseDate = dateTmp
end if
newItem.shortDescriptionLine2 = newItem.releaseDate
If you use the MRSS example you have to edit the NWM_Utilities.brs file at the top to add this call in the NWM_Utilities function at the top of that file.
convertDate: NWM_UT_convertDate
I then have the following function in that file.
Function NWM_UT_convertDate(inStr)
dateIn = inStr
ro = CreateObject ("roRegex", "(\d+)\s+([a-z]+)\s+(\d+)\s+(\d+:\d+:\d+)\D", "i")
da = ro.Match (dateIn)
ml = "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC"
mon% = (Instr (1, ml, Ucase (da [2])) - 1)/3 + 1
dateOut = da[3] + "-" + mon%.ToStr () + "-" + da [1] + " " + da [4]
dt=CreateObject("roDateTime")
dt.fromISO8601String(dateOut)
dateShrt = dt.AsDateString("short-month-short-weekday")
result = dateShrt
print dateShrt
return result
End Function
I'm posting this here so that anyone else who might encounter the same problem with RSS feeds not having standard date format, but rather iTunes formats, can use this to convert the date so they can format it for their channel as they see fit. You can change the format, "short-month-short-weekday", to any of the ones in the Roku SDK documentation for the ifDateTime interface under the AsDateString operation
http://sdkdocs.roku.com/display/sdkdoc/ifDateTime. Of course you could probably also modify this to support different locales and make the format a variable based on the proper locale. However I found this is a good start to at least be able to format the Date/Time to your liking in your own channel.
Thanks again to belltown for the code I could modify to make this work.