-
Notifications
You must be signed in to change notification settings - Fork 319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parsing speed improvements #4297
Open
Pikacz
wants to merge
4
commits into
RevenueCat:main
Choose a base branch
from
Pikacz:parsing_speed_improvements
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// | ||
// Copyright RevenueCat Inc. All Rights Reserved. | ||
// | ||
// Licensed under the MIT License (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://opensource.org/licenses/MIT | ||
// | ||
// ISO8601DateFormatterTests.swift | ||
// | ||
// Created by Paweł Czerwiński on 6/28/24. | ||
|
||
import Nimble | ||
@testable import ReceiptParser | ||
import XCTest | ||
|
||
class ISO8601DateFormatterTests: XCTestCase { | ||
|
||
private let someValidDates: [(text: String, date: Date)] = [ | ||
("2018-11-13T16:46:31Z", Date(timeIntervalSince1970: 1542127591.0)), | ||
("2020-07-22T17:39:08Z", Date(timeIntervalSince1970: 1595439548.0)), | ||
("2020-07-14T21:47:57Z", Date(timeIntervalSince1970: 1594763277.0)), | ||
("2020-07-22T17:39:06Z", Date(timeIntervalSince1970: 1595439546.0)), | ||
("2022-09-14T01:47:57Z", Date(timeIntervalSince1970: 1663120077.0)), | ||
("2022-09-14T01:47:07Z", Date(timeIntervalSince1970: 1663120027.0)) | ||
] | ||
|
||
private let someInvalidlyParsedDates: [(text: String, date: Date)] = [ | ||
("2022-09-31T01:47:57Z", Date(timeIntervalSince1970: 1664588877.0)), // September has only 30 days | ||
("2022-02-29T12:47:57Z", Date(timeIntervalSince1970: 1646138877.0)), // In 2022 February had 28 days not 29 | ||
("2022-02-30T12:47:57Z", Date(timeIntervalSince1970: 1646225277.0)), // In 2022 February had 28 days not 30 | ||
("2022-02-31T01:47:57Z", Date(timeIntervalSince1970: 1646272077.0)), // In 2022 February had 28 days not 31 | ||
("2016-02-30T01:47:57Z", Date(timeIntervalSince1970: 1456796877.0)), // In 2016 February had 29 days not 30 | ||
("2016-02-31T01:47:57Z", Date(timeIntervalSince1970: 1456883277.0)), // In 2016 February had 29 days not 31 | ||
("2022-09-14T24:47:07Z", Date(timeIntervalSince1970: 1663202827.0)) // Too high hour | ||
] | ||
|
||
private let someInvalidDates: [String] = [ | ||
"2022-13-14T24:47:07Z", // invalid month | ||
"2022-12-32T24:47:07Z", // invalid day | ||
"2022-09-14T25:47:07Z", // invalid hour | ||
"2022-09-14T23:61:07Z", // invalid minutes | ||
"2022-09-14T23:60:07Z", // invalid minutes | ||
"2022-09-14T12:47:60Z", // invalid seconds | ||
"2022-09-14T12:47:72Z" // invalid seconds | ||
] | ||
|
||
func testParseStandardDates() { | ||
for (dateString, expectedResult) in someValidDates { | ||
expect(ISO8601DateFormatter.default.date(from: dateString)) == expectedResult | ||
} | ||
} | ||
|
||
func testParseInvalidDatesThatForSomeReasonWorks() { | ||
for (dateString, observedResult) in someInvalidlyParsedDates { | ||
expect(ISO8601DateFormatter.default.date(from: dateString)) == observedResult | ||
} | ||
} | ||
|
||
func testParseInvalidDates() { | ||
for dateString in someInvalidDates { | ||
expect(ISO8601DateFormatter.default.date(from: dateString)).to(beNil()) | ||
} | ||
} | ||
|
||
func testConsistencyWithRawBitsParser() { | ||
let allDates = someValidDates.map { $0.text } + | ||
someInvalidlyParsedDates.map { $0.text } + | ||
someInvalidDates | ||
|
||
for dateString in allDates { | ||
do { | ||
let data = try XCTUnwrap(dateString.data(using: .ascii)) | ||
let rawBits = ArraySlice(data) | ||
XCTAssertEqual(ISO8601DateFormatter.default.date(from: dateString), rawBits.toDate()) | ||
} catch { | ||
fail("Unexpected error for \(dateString), error: \(error)") | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dumb little nitpicks that you can totally disregard:
private
here is redundant in that the extension is already private, we try not to repeatWe usually add line breaks after extension definitions and before they end
See examples in the style guide
Also, given that the method already returns an optional type, it feels like the
try
part is also redundant, I'd maybe go withtoDateFastParse
Again, I don't feel particularly strongly about any of these tbh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Please let me know if there is anything else you wish me to change.