Skip to content
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

fix parsing of dates in receipts with milliseconds #367

Merged
merged 3 commits into from Oct 8, 2020

Conversation

aboedo
Copy link
Member

@aboedo aboedo commented Oct 8, 2020

It looks like Apple might have changed the format of dates in receipts, updating the resolution from seconds to milliseconds.

This PR updates our parser so that we handle both cases, since some receipts will still be in the old format even after the update.

More info: https://twitter.com/depth42/status/1313750495710904320

@aboedo aboedo added this to the 3.7.4 milestone Oct 8, 2020
@aboedo aboedo requested a review from vegaro October 8, 2020 19:36
@aboedo aboedo self-assigned this Oct 8, 2020
guard let dateBytes = "2020-07-14T19:36:40+0000".data(using: .ascii) else { fatalError() }
guard let dateBytes = "2020-07-14T19:36:40Z".data(using: .ascii) else { fatalError() }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't really necessary, and the code will work in either format, but it resembles the actual strings in receipts a little more closely

@aboedo
Copy link
Member Author

aboedo commented Oct 8, 2020

looks like circleCI is having issues. Tests pass locally, though.

let date = Calendar.current.date(from: dateComponents)
guard let dateBytes = "2020-07-14T19:36:40.202Z".data(using: .ascii) else { fatalError() }
let receivedDate = ISO3601DateFormatter.shared.date(fromBytes: ArraySlice(dateBytes))
expect(receivedDate!.timeIntervalSince1970).to(beCloseTo(date!.timeIntervalSince1970))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't compare same way we do in the other test because of the precision issue you mentioned to me in private?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, floating point precision is a killer here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really, we should be doing this on any and all floating point comparisons. I can update the other one.

@aboedo aboedo merged commit 87af289 into develop Oct 8, 2020
@aboedo aboedo deleted the fix/parse_receipt_dates_in_miliseconds branch October 8, 2020 22:14
@aboedo aboedo mentioned this pull request Oct 9, 2020
aboedo added a commit that referenced this pull request Oct 9, 2020
* fixed parsing of apple receipts when dates have millisecond resolution

* escaped the dot so that it works correctly with international formats

* learned to spell milliseconds
@aboedo aboedo mentioned this pull request Jul 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants