Support short dates
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
2025-07-20 18:32:02 +02:00
parent 0943104cc8
commit 3098d12e8a

View File

@@ -46,18 +46,20 @@ Future<BaseExpenseInfo?> extractInfoFromBill({
// Check for highestCost amount on invoice // Check for highestCost amount on invoice
final dateRegexp = RegExp( final dateRegexp = RegExp(
r'([0-3][0-9])(\/|-)([0-1][0-9])(\/|-)(20[0-9]{2})', r'([0-3][0-9])(\/|-)([0-1][0-9])(\/|-)((20|)[0-9]{2})',
multiLine: true, multiLine: false,
caseSensitive: false, caseSensitive: false,
); );
final currDate = DateTime.now(); final currDate = DateTime.now();
DateTime? newest; DateTime? newest;
for (final match in dateRegexp.allMatches(extractionResult.text)) { 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 { try {
final date = DateTime( 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(3)!) ?? currDate.month,
int.tryParse(match.group(1)!) ?? currDate.day, int.tryParse(match.group(1)!) ?? currDate.day,
); );