From 0448eb813424157c09fcec48e58c4c1ee4456d60 Mon Sep 17 00:00:00 2001 From: cdkl Date: Mon, 26 Feb 2024 12:25:10 -0500 Subject: [PATCH] Remote utc to localtime conversion from daily_plot.py Introduction of yesterday/today handling added a bug that expresses itself on systems whose timezones are behind UTC. Specifically, the 'localtime' modifier to DATE() attempts to interpret the date to the left as UTC, and convert to localtime. The result is that in timezones behind UTC, the date selected is always 1 earlier than intended. No timezone conversion should be done. The db data is in local time already. Here's a demonstration of calling DATE() in various ways in North America EST: sqlite> select DATE('now'); 2024-02-26 sqlite> select DATETIME('now'); 2024-02-26 17:20:46 sqlite> select DATE('2024-02-26'); 2024-02-26 sqlite> select DATETIME('2024-02-26'); 2024-02-26 00:00:00 sqlite> select DATE('now', 'localtime'); 2024-02-26 sqlite> select DATE('2024-02-26', 'localtime'); 2024-02-25 <--- this is the bug --- scripts/daily_plot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/daily_plot.py b/scripts/daily_plot.py index e0dc6a0..bbf46b3 100755 --- a/scripts/daily_plot.py +++ b/scripts/daily_plot.py @@ -19,7 +19,7 @@ def get_data(now=None): conn = sqlite3.connect(DB_PATH) if now is None: now = datetime.now() - df = pd.read_sql_query(f"SELECT * from detections WHERE Date = DATE('{now.strftime('%Y-%m-%d')}', 'localtime')", + df = pd.read_sql_query(f"SELECT * from detections WHERE Date = DATE('{now.strftime('%Y-%m-%d')}')", conn) # Convert Date and Time Fields to Panda's format