diff --git a/Modules/RSParser/Sources/ObjC/RSDateParser.m b/Modules/RSParser/Sources/ObjC/RSDateParser.m index 4fe95e983..8a346d3fe 100755 --- a/Modules/RSParser/Sources/ObjC/RSDateParser.m +++ b/Modules/RSParser/Sources/ObjC/RSDateParser.m @@ -337,6 +337,9 @@ static NSDate *RSParsePubDateWithBytes(const char *bytes, NSUInteger numberOfByt month = nextMonthValue(bytes, numberOfBytes, finalIndex + 1, &finalIndex); year = nextNumericValue(bytes, numberOfBytes, finalIndex + 1, 4, &finalIndex); + if (year != NSNotFound && year < 100) { // Check for two-digit years and assume 21st century + year += 2000; + } hour = nextNumericValue(bytes, numberOfBytes, finalIndex + 1, 2, &finalIndex); if (hour == NSNotFound) hour = 0; diff --git a/Modules/RSParser/Tests/RSParserTests/RSDateParserTests.swift b/Modules/RSParser/Tests/RSParserTests/RSDateParserTests.swift index 26a805b86..e80678143 100644 --- a/Modules/RSParser/Tests/RSParserTests/RSDateParserTests.swift +++ b/Modules/RSParser/Tests/RSParserTests/RSDateParserTests.swift @@ -101,6 +101,26 @@ final class RSDateParserTests: XCTestCase { XCTAssertEqual(d, expectedDateResult) } + func testTwoDigitYear() { + // + + var expectedDateResult = Self.dateWithValues(2026, 4, 12, 17, 24, 19) + + var d = RSDateWithString("Sun, 12 Apr 26 17:24:19 +0000") + XCTAssertEqual(d, expectedDateResult) + + d = RSDateWithString("12 Apr 26 17:24:19 +0000") + XCTAssertEqual(d, expectedDateResult) + + expectedDateResult = Self.dateWithValues(2099, 5, 28, 21, 3, 38) + d = RSDateWithString("Fri, 28 May 99 21:03:38 +0000") + XCTAssertEqual(d, expectedDateResult) + + expectedDateResult = Self.dateWithValues(2000, 1, 1, 0, 0, 0) + d = RSDateWithString("01 Jan 00 00:00:00 +0000") + XCTAssertEqual(d, expectedDateResult) + } + func testHighMillisecondDate() { let expectedDateResult = Self.dateWithValues(2021, 03, 29, 10, 46, 56, 516) let d = RSDateWithString("2021-03-29T10:46:56.516941+00:00")