mirror of
https://github.com/escalante29/WealthySmart.git
synced 2026-07-17 10:08:46 +02:00
Agent: fix date handling — Costa Rica timezone and future cuotas
Two bugs from prod (server clock is UTC, user is UTC-6): - get_recent_transactions returned future-dated Tasa Cero cuotas; it now excludes anything dated after the user's today, same rule as /transactions/recent. - "¿Cuánto he gastado hoy?" answered for the wrong day: the prompt baked date.today() in at boot — frozen from startup AND in server-UTC (8 pm in Costa Rica is already tomorrow in UTC). The prompt no longer carries a date; a new get_current_date tool returns today in CR time plus the active billing cycle, and the prompt directs the model to call it for any relative date reference. today_cr() lives in timeutil (CR has no DST, fixed UTC-6). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -149,3 +149,37 @@ def test_recent_transactions_json_safe(bound_session):
|
||||
out = tools.get_recent_transactions()
|
||||
json.dumps(out)
|
||||
assert out[0]["amount"] == 42.42
|
||||
|
||||
|
||||
def test_recent_transactions_exclude_future_cuotas(bound_session):
|
||||
from datetime import timedelta
|
||||
|
||||
from app.timeutil import today_cr
|
||||
|
||||
today = datetime.combine(today_cr(), datetime.min.time())
|
||||
bound_session.add(
|
||||
Transaction(amount=Decimal("10"), merchant="BILLED", date=today)
|
||||
)
|
||||
bound_session.add(
|
||||
Transaction(
|
||||
amount=Decimal("20"),
|
||||
merchant="FUTURE CUOTA:03/06",
|
||||
date=today + timedelta(days=45),
|
||||
)
|
||||
)
|
||||
bound_session.commit()
|
||||
merchants = [t["merchant"] for t in tools.get_recent_transactions()]
|
||||
assert "BILLED" in merchants
|
||||
assert "FUTURE CUOTA:03/06" not in merchants
|
||||
|
||||
|
||||
def test_get_current_date_is_costa_rica_and_cycle_consistent():
|
||||
from app.timeutil import today_cr
|
||||
|
||||
out = tools.get_current_date()
|
||||
today = today_cr()
|
||||
assert out["date"] == today.isoformat()
|
||||
# The active cycle must contain today: [start, end)
|
||||
start, end = out["cycle_range"]
|
||||
assert start <= out["date"] < end
|
||||
assert start.endswith("-18") and end.endswith("-18")
|
||||
|
||||
Reference in New Issue
Block a user