From 3098d12e8a24885613cfdcd89061811a6d84d2a9 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sun, 20 Jul 2025 18:32:02 +0200 Subject: [PATCH] Support short dates --- moneymgr_mobile/lib/utils/ocr_utils.dart | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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, );