Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

Fix parsing of timeDescription while using Family Sharing #2

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

afwolfe
Copy link

@afwolfe afwolfe commented Jun 13, 2022

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.

@BergQuester
Copy link
Owner

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.

@afwolfe
Copy link
Author

afwolfe commented Jun 19, 2022

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
Copy link
Author

afwolfe commented Jun 26, 2022

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants