Support short dates
This commit is contained in:
@@ -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,
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user