mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-28 00:04:25 +00:00
Handle two-digit years in pubDate — assume this century. Add tests for this. Fixes #5244.
This commit is contained in:
1 parent
17319b1910
commit
da41360cee
2 files changed
+23
No files matched your search
@@ -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;
|
||||
|
||||
@@ -101,6 +101,26 @@ final class RSDateParserTests: XCTestCase {
|
||||
XCTAssertEqual(d, expectedDateResult)
|
||||
}
|
||||
|
||||
func testTwoDigitYear() {
|
||||
// <https://github.com/Ranchero-Software/NetNewsWire/issues/5244>
|
||||
|
||||
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")
|
||||
|
||||
Reference in new issue
Block a user