Skip to content

Commit

Permalink
Merge pull request #4356 from zll600/bring_extra-milliseconds_fix_to_…
Browse files Browse the repository at this point in the history
…main

Bring extra-milliseconds fix to main
  • Loading branch information
brentsimmons authored Sep 10, 2024
2 parents ad0dcf3 + 090c8e0 commit fc36c5e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
13 changes: 7 additions & 6 deletions Modules/Parser/Tests/ParserTests/RSDateParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Parser

class RSDateParserTests: XCTestCase {

static func dateWithValues(_ year: Int, _ month: Int, _ day: Int, _ hour: Int, _ minute: Int, _ second: Int) -> Date {
static func dateWithValues(_ year: Int, _ month: Int, _ day: Int, _ hour: Int, _ minute: Int, _ second: Int, _ milliseconds: Int = 0) -> Date {
var dateComponents = DateComponents()
dateComponents.calendar = Calendar.current
dateComponents.timeZone = TimeZone(secondsFromGMT: 0)
Expand All @@ -22,6 +22,7 @@ class RSDateParserTests: XCTestCase {
dateComponents.hour = hour
dateComponents.minute = minute
dateComponents.second = second
dateComponents.nanosecond = milliseconds * 1000000

return dateComponents.date!
}
Expand Down Expand Up @@ -100,9 +101,9 @@ class RSDateParserTests: XCTestCase {
XCTAssertEqual(d, expectedDateResult)
}

// func testHighMillisecondDate() {
// let expectedDateResult = Self.dateWithValues(2021, 03, 29, 10, 46, 56)
// let d = RSDateWithString("2021-03-29T10:46:56.516941+00:00")
// 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")
XCTAssertEqual(d!.timeIntervalSince1970, expectedDateResult.timeIntervalSince1970, accuracy: 0.000001)
}
}
3 changes: 3 additions & 0 deletions Modules/ParserObjC/Sources/ParserObjC/RSDateParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,9 @@ static NSInteger parsedTimeZoneOffset(const char *bytes, NSUInteger numberOfByte
if (hasMilliseconds) {
milliseconds = nextNumericValue(bytes, numberOfBytes, currentIndex, 3, &finalIndex);
currentIndex = finalIndex + 1;

// Igore more than 3 digits for fraction of a second
while (currentIndex < numberOfBytes && isdigit(bytes[currentIndex])) currentIndex++;
}

timeZoneOffset = parsedTimeZoneOffset(bytes, numberOfBytes, currentIndex);
Expand Down

0 comments on commit fc36c5e

Please sign in to comment.