Private
Public Access
1
0

Fix AI date search matching only midnight instead of full day

When the AI searched for transactions on a specific date like
"2026-02-11", ParseDateArg produced 2026-02-11T00:00:00Z (midnight).
The query "Date <= midnight" excluded any transaction stored with a
time component later that day. Now date-only end dates are bumped to
23:59:59.999 so the full day is covered. Applied to search_transactions,
get_spending_by_category, and get_income_vs_expense tools.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Catherine Renelle
2026-02-11 19:36:26 -05:00
parent dbe351ac45
commit 8421d244f2
+9 -1
View File
@@ -525,10 +525,16 @@ public class ChatService : IChatService
if (match != null) categoryId = match.Id;
}
// When the AI passes a date-only end date (midnight), bump to end of day
// so "2026-02-11" means the entire day, not just midnight.
var endDate = ParseDateArg(args, "end_date");
if (endDate.HasValue && endDate.Value.TimeOfDay == TimeSpan.Zero)
endDate = endDate.Value.Date.AddDays(1).AddTicks(-1);
var searchRequest = new TransactionSearchRequest(
AccountId: null,
StartDate: ParseDateArg(args, "start_date"),
EndDate: ParseDateArg(args, "end_date"),
EndDate: endDate,
MinAmount: ParseDecimalArg(args, "min_amount"),
MaxAmount: ParseDecimalArg(args, "max_amount"),
PayeeName: ParseStringArg(args, "payee_name"),
@@ -555,6 +561,7 @@ public class ChatService : IChatService
{
var startDate = ParseDateArg(args, "start_date") ?? new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, 1, 0, 0, 0, DateTimeKind.Utc);
var endDate = ParseDateArg(args, "end_date") ?? DateTime.UtcNow;
if (endDate.TimeOfDay == TimeSpan.Zero) endDate = endDate.Date.AddDays(1).AddTicks(-1);
var report = await _reportService.GetSpendingByCategoryAsync(userId, startDate, endDate);
@@ -572,6 +579,7 @@ public class ChatService : IChatService
{
var startDate = ParseDateArg(args, "start_date") ?? DateTime.UtcNow.AddMonths(-6);
var endDate = ParseDateArg(args, "end_date") ?? DateTime.UtcNow;
if (endDate.TimeOfDay == TimeSpan.Zero) endDate = endDate.Date.AddDays(1).AddTicks(-1);
var report = await _reportService.GetIncomeVsExpenseAsync(userId, startDate, endDate);