Author Topic: RSS Time format hack  (Read 1266 times)

0 Members and 1 Guest are viewing this topic.

Offline Paul

  • Hero Member
  • *****
  • Posts: 162
RSS Time format hack
« on: May 23, 2014, 02:12:31 AM »
Recently I wanted to use csv write to generate an RSS feed.

(as an aside, Windows 8 "live tiles" on the start screen can read RSS feeds & dynamically update.
http://www.hanselman.com/blog/MakeAWindows81PinnedLiveTileForYOURWebsiteInMinutes.aspx )

However, RSS feeds require the time to be in a very particular format.

Here is a "csv write" script hack that will save the time in the correct format.

Enter the following line just above "use strict" near the top of the script

Code: [Select]
use POSIX qw(strftime);
use strict;

Comment out the old date/time subroutine underneath it with a "#" before each line (you could also delete it, but I like to leave it there in case you want to go back to it)

Code: [Select]
#my @date=localtime();
#$date[4]++; $date[5]+=1900;
#for(0..4){$date[$_]=sprintf("%02d",$date[$_]);}
#my $date="$date[2]:$date[1]:$date[0] $date[5]-$date[4]-$date[3]";
#if ($alternativeDateFormat){
#$date[5]=sprintf("%02d",$date[5]-2000);
#$date = "$date[5]:$date[4]:$date[3]-$date[0]:$date[1]:$date[2]";
# }

Then enter the following directly underneath it.

Code: [Select]
my $date = strftime "%a, %d %h %Y %X %z", localtime; #RSS date format hack
The date will look something like this in your database under the "DATE" field.

Fri, 23 May 2014 07:33:08 +1000

(with the timezone reflecting your server timezone)


Then the "csv read" template can look something like this (example to get you started). Read the RSS documentation online for more info on this.

Code: [Select]
<?xml version='1.0' encoding='UTF-8'?>
<rss version='2.0'>
<channel>
<title>Title of your RSS Feed</title>
<description>Description of your RSS feed</description>
<language>en-us</language>

<template>
<item>
<title>[[title_of_RSS_item]]</title>
<link>[[link]]</link>
<description>[[your_RSS_item]]</description>
<pubDate>[[DATE]]</pubDate>
</item>
</template>

</channel>
</rss>
« Last Edit: May 23, 2014, 02:16:07 AM by Paul »

Offline Jason

  • Administrator
  • Hero Member
  • *****
  • Posts: 1018
    • slipdex
Re: RSS Time format hack
« Reply #1 on: May 24, 2014, 06:13:10 PM »
Nice one Paul. I'm still working on the new version of the scripts, but I do have a US date format option built in. I could easily add this as an RSS date output option as well. Making it an option instead of over-riding the already used DATE format would be more beneficial I think. That way the user still has the ability to use the DATE sorting methods for filtering purposes, but could also have the RSS formatted date for proper display. I will look into including that as an optional date output. Nice work!

Jason
Founder of www.slipdex.com