diff --git a/moneymgr_mobile/lib/utils/ocr_utils.dart b/moneymgr_mobile/lib/utils/ocr_utils.dart index 175abfa..5c47f66 100644 --- a/moneymgr_mobile/lib/utils/ocr_utils.dart +++ b/moneymgr_mobile/lib/utils/ocr_utils.dart @@ -46,18 +46,20 @@ Future extractInfoFromBill({ // Check for highestCost amount on invoice final dateRegexp = RegExp( - r'([0-3][0-9])(\/|-)([0-1][0-9])(\/|-)(20[0-9]{2})', - multiLine: true, + r'([0-3][0-9])(\/|-)([0-1][0-9])(\/|-)((20|)[0-9]{2})', + multiLine: false, caseSensitive: false, ); final currDate = DateTime.now(); DateTime? newest; for (final match in dateRegexp.allMatches(extractionResult.text)) { - if (match.groupCount < 5) continue; + if (match.groupCount < 6) continue; + + int year = int.tryParse(match.group(6)!) ?? currDate.year; try { final date = DateTime( - int.tryParse(match.group(5)!) ?? currDate.year, + year > 99 ? year : (2000 + year), int.tryParse(match.group(3)!) ?? currDate.month, int.tryParse(match.group(1)!) ?? currDate.day, );