From 01a8aee2261519b0bbcb9e9d4603d0c74ddb7a78 Mon Sep 17 00:00:00 2001 From: gahusb Date: Thu, 2 Jul 2026 15:43:22 +0900 Subject: [PATCH] =?UTF-8?q?fix(stock):=20=EB=A7=A4=EB=A7=A4=EC=95=8C?= =?UTF-8?q?=EB=9E=8C=20=EC=9D=B4=EB=A0=A5=20days=20=ED=95=84=ED=84=B0=20?= =?UTF-8?q?=ED=8F=AC=EB=A7=B7=EC=9D=84=20ISO=EB=A1=9C=20=ED=86=B5=EC=9D=BC?= =?UTF-8?q?=20(=EA=B2=BD=EA=B3=84=EC=9D=BC=20=EA=B3=BC=EB=8B=A4=ED=8F=AC?= =?UTF-8?q?=ED=95=A8=20=EC=88=98=EC=A0=95,=20=EB=A6=AC=EB=B7=B0=20Importan?= =?UTF-8?q?t)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stock/app/db.py | 2 +- stock/tests/test_trade_alerts_db.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/stock/app/db.py b/stock/app/db.py index 95a9986..1fca446 100644 --- a/stock/app/db.py +++ b/stock/app/db.py @@ -509,7 +509,7 @@ def add_alert_history(ticker: str, name: str, kind: str, condition: str, price, def get_alert_history(days: int = 7) -> list: with _conn() as conn: rows = conn.execute( - "SELECT * FROM trade_alert_history WHERE fired_at >= datetime('now', ?) ORDER BY fired_at DESC", + "SELECT * FROM trade_alert_history WHERE fired_at >= strftime('%Y-%m-%dT%H:%M:%fZ','now', ?) ORDER BY fired_at DESC", (f"-{int(days)} days",), ).fetchall() return [ diff --git a/stock/tests/test_trade_alerts_db.py b/stock/tests/test_trade_alerts_db.py index 5e68820..b8c551f 100644 --- a/stock/tests/test_trade_alerts_db.py +++ b/stock/tests/test_trade_alerts_db.py @@ -31,3 +31,18 @@ def test_alert_history_records_and_reads(db): assert len(rows) == 1 assert rows[0]["ticker"] == "005930" and rows[0]["kind"] == "buy" assert rows[0]["detail"]["vol"] == 2.1 + +def test_alert_history_days_filter_format_consistency(db): + """fired_at은 ISO(T/Z)로 저장 — 필터도 ISO여야 경계일 비교가 정확. + 7일 경계 밖(정확히 7일 전 자정) 레코드는 제외되어야 한다. 포맷 불일치면 잘못 포함됨.""" + db.add_alert_history("005930", "삼성", "buy", "buy_breakout", 71500, {}) # now + conn = sqlite3.connect(db.DB_PATH) + conn.execute( + "INSERT INTO trade_alert_history(ticker,name,kind,condition,price,detail_json,fired_at) " + "VALUES('000660','SK','sell','sell_stop_loss',60000,'{}', " + "strftime('%Y-%m-%dT%H:%M:%fZ','now','-7 days','start of day'))" + ) + conn.commit(); conn.close() + tickers = [r["ticker"] for r in db.get_alert_history(days=7)] + assert "005930" in tickers + assert "000660" not in tickers