Bitnock / BNRSSFeedParser

Simple RSS and podcast parsing in Objective-C
https://github.com/Bitnock/BNRSSFeedParser
MIT License
22 stars 3 forks source link

Parse feed when your current locale isn't english #6

Open torcelly opened 9 years ago

torcelly commented 9 years ago

Hi,

I've checked that when you use the parser and the device doesn't have the english NSLocale, the pubDate is nil. For instance, if your device use spanish:

The date:

Tue, 02 Oct 2012 19:56:51 +0000

should be

mar, 02 oct 2012 19:56:51 +0000

I believe that you should add to the NSDate category RSS the NSLocale en_US:

NSDate+RSS.m

+ (void)initialize {
  if (!pubDateFormatterTZOffset) {

    NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];

    // ex. Tue, 02 Oct 2012 19:56:51 +0000
    pubDateFormatterTZOffset = NSDateFormatter.new;
    pubDateFormatterTZOffset.dateFormat = @"EEE, dd MMM yyyy HH:mm:ss ZZZ";
    pubDateFormatterTZOffset.locale = usLocale;

    // ex. Tue, 02 Oct 2012 19:56:51 EDT
    pubDateFormatterTZAbbreviation = NSDateFormatter.new;
    pubDateFormatterTZAbbreviation.dateFormat = @"EEE, dd MMM yyyy HH:mm:ss zzz";
    pubDateFormatterTZAbbreviation.locale = usLocale;
  }

  [super initialize];
}

Thoughts? I will do pull request.

farski commented 9 years ago

Sounds good. I think you may actually want to use en_US_POSIX as the locale identifier, but you should double check.

EvsenevDev commented 8 years ago

Some problem with Russian. And en_US fix this problem. Needs PR?