CardVision icon indicating copy to clipboard operation
CardVision copied to clipboard

Fix parsing of timeDescription while using Family Sharing

Open afwolfe opened this issue 3 years ago • 3 comments

When parsing Apple Card transaction screenshots while using Family Sharing, family member's names are prepended on the date line, which causes the date to be improperly defaulted to "Just now." This PR attempts to address that by:

  • Detecting when a timeDescription contains spaces and is not a relative timestamp and splits after the first space (the family member's name.)
  • If a family name is split, this is also added to the memo field.
  • Created a new unit test class in TransactionReaderOCRTextTests to verify that the date parsing changes work.
  • New extensions, Date+current and Date+mock which statically set the date for testing, adapting examples from: https://dev.to/ivanmisuno/deterministic-unit-tests-for-current-date-dependent-code-in-swift-2h72

Note: The article also recommends adding a pre-commit hook to verify that Date() is no longer used in the code in favor of the new Date.current which is easier to mock in testing.

afwolfe avatar Jun 13 '22 00:06 afwolfe

Wow, thanks!

I've been pretty busy lately so it's going to take me a while before I can truest look this over.

I had a go at fixing this some months ago, but life events got in the way.

BergQuester avatar Jun 18 '22 20:06 BergQuester

No problem! Take your time, I totally understand. Thanks for releasing this in the first place. It really came in handy for the project I made to get Apple Card transactions imported into the budgeting software I use.

afwolfe avatar Jun 19 '22 13:06 afwolfe

I just made a revision to improve the handling based on testing this branch on transactions since I first made these changes. There seems to sometimes be some inconsistent behavior when VisionKit parses the screenshot and separates the fields. To address this, I added an isTimestamp() method which uses regex to see if the string contains a valid timestamp and keep appending to the string until it contains a valid timestamp. I also updated the Family Sharing test to verify that different variations on this are still processed correctly.

afwolfe avatar Jun 26 '22 23:06 afwolfe