Share

RSS.NET

Tracker: Bugs

5 Problem with reading time dates - ID: 927898
Last Update: Comment added ( nobody )

There is a problem with reading out the Pubdate item
variable from some RSS feeds. As long as GMT is used,
everything is fine, but if someone were to use the date
as

Fri, 16 May 2003 15:24:38 EST

which many products are doing, then the Parse method
gets screwed up. MS only allows it to parse GMT and
everything else throws an error. MS is expecting the
programmer to convert to UTC which I think is a flaw in
the class.

Anyway, I was wondering if anyone had brought this up
and if there was a suggested fix. If not, I'll try to whip
something up.

Thanks


Nobody/Anonymous ( nobody ) - 2004-04-01 22:43

5

Open

None

George Tsiokos

Reading Feeds

General

Public


Comments ( 7 )




Date: 2008-08-12 06:16
Sender: nobody

Logged In: NO

I dropped the code referenced below in a class called DateParser in the
RSS.net Shared folder:

http://bytes.com/forum/thread214648.html

Then instead of the shameless hackery of code that looks like:

string tmp = elementText.ToString ();
tmp = tmp.Substring (0, tmp.Length - 5);
tmp += "GMT";
item.PubDate = DateTime.Parse (tmp);

I wrote:

item.PubDate = DateParser.ParseDateTime(elementText.ToString());



Date: 2006-05-21 14:50
Sender: coders4hire

Logged In: YES
user_id=864387

George, I noticed your note on this and I'm running into
the same problem (years later albeit). Curious whether
you found a better solution. Looks like this project has
been abandoned.


Date: 2005-04-03 16:28
Sender: nobody

Logged In: NO

you need to add using System.Globalization; to that class
and it'll work.



Date: 2004-09-15 15:13
Sender: nobody

Logged In: NO

erebuss: thats great, but i cant seem to use your code
without getting gobs of compile errors... can u tell me wehre i
need to put that code?


Date: 2004-05-30 21:28
Sender: lotasAccepting Donations

Logged In: YES
user_id=22052

that works grand! when will this be added to the CVS release?


Date: 2004-05-29 15:15
Sender: erebuss

Logged In: YES
user_id=1052533

I had the same problem and thanks to a mvp, I had the
solution:

public static string[][] TimeZones = new string[][] {
new string[] {"ACDT", "+1030", "Australian Central Daylight"},
new string[] {"ACST", "+0930", "Australian Central Standard"},
new string[] {"ADT", "-0300", "(US) Atlantic Daylight"},
new string[] {"AEDT", "+1100", "Australian East Daylight"},
new string[] {"AEST", "+1000", "Australian East Standard"},
new string[] {"AHDT", "-0900", "AHDT"},
new string[] {"AHST", "-1000", "AHST"},
new string[] {"AST", "-0400", "(US) Atlantic Standard"},
new string[] {"AT", "-0200", "Azores"},
new string[] {"AWDT", "+0900", "Australian West Daylight"},
new string[] {"AWST", "+0800", "Australian West Standard"},
new string[] {"BAT", "+0300", "Bhagdad"},
new string[] {"BDST", "+0200", "British Double Summer"},
new string[] {"BET", "-1100", "Bering Standard"},
new string[] {"BST", "-0300", "Brazil Standard"},
new string[] {"BT", "+0300", "Baghdad"},
new string[] {"BZT2", "-0300", "Brazil Zone 2"},
new string[] {"CADT", "+1030", "Central Australian Daylight"},
new string[] {"CAST", "+0930", "Central Australian Standard"},
new string[] {"CAT", "-1000", "Central Alaska"},
new string[] {"CCT", "+0800", "China Coast"},
new string[] {"CDT", "-0500", "(US) Central Daylight"},
new string[] {"CED", "+0200", "Central European Daylight"},
new string[] {"CET", "+0100", "Central European"},
new string[] {"CST", "-0600", "(US) Central Standard"},
new string[] {"EAST", "+1000", "Eastern Australian Standard"},
new string[] {"EDT", "-0400", "(US) Eastern Daylight"},
new string[] {"EED", "+0300", "Eastern European Daylight"},
new string[] {"EET", "+0200", "Eastern Europe"},
new string[] {"EEST", "+0300", "Eastern Europe Summer"},
new string[] {"EST", "-0500", "(US) Eastern Standard"},
new string[] {"FST", "+0200", "French Summer"},
new string[] {"FWT", "+0100", "French Winter"},
new string[] {"GMT", "-0000", "Greenwich Mean"},
new string[] {"GST", "+1000", "Guam Standard"},
new string[] {"HDT", "-0900", "Hawaii Daylight"},
new string[] {"HST", "-1000", "Hawaii Standard"},
new string[] {"IDLE", "+1200", "Internation Date Line East"},
new string[] {"IDLW", "-1200", "Internation Date Line West"},
new string[] {"IST", "+0530", "Indian Standard"},
new string[] {"IT", "+0330", "Iran"},
new string[] {"JST", "+0900", "Japan Standard"},
new string[] {"JT", "+0700", "Java"},
new string[] {"MDT", "-0600", "(US) Mountain Daylight"},
new string[] {"MED", "+0200", "Middle European Daylight"},
new string[] {"MET", "+0100", "Middle European"},
new string[] {"MEST", "+0200", "Middle European Summer"},
new string[] {"MEWT", "+0100", "Middle European Winter"},
new string[] {"MST", "-0700", "(US) Mountain Standard"},
new string[] {"MT", "+0800", "Moluccas"},
new string[] {"NDT", "-0230", "Newfoundland Daylight"},
new string[] {"NFT", "-0330", "Newfoundland"},
new string[] {"NT", "-1100", "Nome"},
new string[] {"NST", "+0630", "North Sumatra"},
new string[] {"NZ", "+1100", "New Zealand "},
new string[] {"NZST", "+1200", "New Zealand Standard"},
new string[] {"NZDT", "+1300", "New Zealand Daylight"},
new string[] {"NZT", "+1200", "New Zealand"},
new string[] {"PDT", "-0700", "(US) Pacific Daylight"},
new string[] {"PST", "-0800", "(US) Pacific Standard"},
new string[] {"ROK", "+0900", "Republic of Korea"},
new string[] {"SAD", "+1000", "South Australia Daylight"},
new string[] {"SAST", "+0900", "South Australia Standard"},
new string[] {"SAT", "+0900", "South Australia Standard"},
new string[] {"SDT", "+1000", "South Australia Daylight"},
new string[] {"SST", "+0200", "Swedish Summer"},
new string[] {"SWT", "+0100", "Swedish Winter"},
new string[] {"USZ3", "+0400", "USSR Zone 3"},
new string[] {"USZ4", "+0500", "USSR Zone 4"},
new string[] {"USZ5", "+0600", "USSR Zone 5"},
new string[] {"USZ6", "+0700", "USSR Zone 6"},
new string[] {"UT", "-0000", "Universal Coordinated"},
new string[] {"UTC", "-0000", "Universal Coordinated"},
new string[] {"UZ10", "+1100", "USSR Zone 10"},
new string[] {"WAT", "-0100", "West Africa"},
new string[] {"WET", "-0000", "West European"},
new string[] {"WST", "+0800", "West Australian Standard"},
new string[] {"YDT", "-0800", "Yukon Daylight"},
new string[] {"YST", "-0900", "Yukon Standard"},
new string[] {"ZP4", "+0400", "USSR Zone 3"},
new string[] {"ZP5", "+0500", "USSR Zone 4"},
new string[] {"ZP6", "+0600", "USSR Zone 5"}
};

public static DateTime ParseDateTime(string dateTime)
{
System.Globalization.CultureInfo ci =
CultureInfo.InvariantCulture;

try
{
return DateTime.Parse(dateTime, ci,
DateTimeStyles.AllowWhiteSpaces);
}
catch (FormatException)
{
try
{
return DateTime.ParseExact(dateTime, new string[]
{ci.DateTimeFormat.SortableDateTimePattern,
ci.DateTimeFormat.RFC1123Pattern}, ci,
DateTimeStyles.AllowWhiteSpaces);
}
catch (FormatException)
{
string dateFormat =
ci.DateTimeFormat.RFC1123Pattern.Replace("'GMT'", "zzz");
foreach(string[] entry in TimeZones)
{
if (dateTime.EndsWith(entry[0]))
{
dateTime = String.Format("{0}{1}",
dateTime.Substring(0,
dateTime.Length - entry[0].Length), entry[1]);
break; }
}
try
{
return DateTime.ParseExact(dateTime,
dateFormat, ci,
DateTimeStyles.AllowWhiteSpaces);
}
catch (FormatException)
{
return DateTime.Now;
}
}
}
}


Just change the switch in rssreader.cs :
item.PubDate = ParseDateTime(elementText.ToString());

Enjoy !



Date: 2004-05-03 12:04
Sender: lotasAccepting Donations

Logged In: YES
user_id=22052

its not only when it ends in something like EST, but also when
it ends in something like +0000 or +0500. i just found that
out the hard way....


Log in to comment.




Attached File

No Files Currently Attached

Change ( 1 )

Field Old Value Date By
assigned_to nobody 2004-04-24 02:39 gtsiokos