From c1c9f0208b8066719224727ffe5908a2aabc6c41 Mon Sep 17 00:00:00 2001 From: hanez Date: Thu, 23 Jul 2026 02:30:52 +0200 Subject: [PATCH] Fix !zynk key-value timestamps to use localtime instead of UTC - Fixed db_set() using datetime('now') which returns UTC, causing !zynk to display timestamps offset by the server's timezone difference. Changed to datetime('now','localtime') so timestamps match the system's local time. - Also fixed db_rotate_history() (AI query context rotation) and the zynk/tell table DEFAULT clauses to use localtime. - Same pattern as the !seen fix in 0.39.1. (0.40.1) --- CHANGELOG.md | 5 +++++ CMakeLists.txt | 2 +- db.h | 12 ++++++------ zynk.h | 2 +- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13e345a..582cfcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +2026.07.23 - Fix !zynk key-value timestamps to use localtime. (0.40.1) + +- Fixed `!zynk key = value` storing UTC timestamps instead of localtime: `db_set()` and the `zynk` table default used `datetime('now')` which returns UTC, causing `!zynk ` to display a timestamp offset by the server's timezone difference. Changed to `datetime('now','localtime')` so timestamps match the system's local time. +- Also fixed `db_rotate_history()` (used by AI query context) and the `tell` table default to use localtime. + 2026.07.23 - Commit links for !gitlog, full changelog link for !changelog, CMake, multi-file refactor. (0.40.0) - `!gitlog` now shows a link to each commit in the repository (e.g. `184d4c4 Fix whitespace... - https://...`), using the git remote URL converted from SSH/SCP to HTTPS. diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b7c501..3586be6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.13) -project(zynk VERSION 0.40.0 LANGUAGES C) +project(zynk VERSION 0.40.1 LANGUAGES C) # Prefer C99; the code is compatible with C99/C11 set(CMAKE_C_STANDARD 99) diff --git a/db.h b/db.h index 53e4592..30730da 100644 --- a/db.h +++ b/db.h @@ -100,7 +100,7 @@ int db_init(void) { } const char *sql_zynk = "CREATE TABLE IF NOT EXISTS zynk (" "key TEXT PRIMARY KEY, value TEXT NOT NULL, " - "nick TEXT NOT NULL, updated_at TEXT DEFAULT (datetime('now')))"; + "nick TEXT NOT NULL, updated_at TEXT DEFAULT (datetime('now','localtime')))"; char *err = NULL; if (db_exec(DB, sql_zynk, NULL, NULL, &err) != SQLITE_OK) { fprintf(stderr, CLR_RED "SQL: %s" CLR_RESET "\n", err ? err : "unknown error"); @@ -122,7 +122,7 @@ int db_init(void) { db_exec(DB, sql_seen, NULL, NULL, NULL); const char *sql_tell = "CREATE TABLE IF NOT EXISTS tell (" "id INTEGER PRIMARY KEY, from_nick TEXT, to_nick TEXT, " - "message TEXT, created_at TEXT DEFAULT (datetime('now')))"; + "message TEXT, created_at TEXT DEFAULT (datetime('now','localtime')))"; db_exec(DB, sql_tell, NULL, NULL, NULL); const char *sql_clear_ai = "DELETE FROM ai_pending"; db_exec(DB, sql_clear_ai, NULL, NULL, NULL); @@ -170,9 +170,9 @@ void sqlite_cleanup(void) { if (sqlite_lib) { dlclose(sqlite_lib); sqlite_lib = int db_set(const char *key, const char *value, const char *nick) { void *stmt; const char *sql = "INSERT INTO zynk(key,value,nick,updated_at)" - " VALUES(?,?,?,datetime('now'))" + " VALUES(?,?,?,datetime('now','localtime'))" " ON CONFLICT(key) DO UPDATE SET value=excluded.value," - " nick=excluded.nick, updated_at=datetime('now')"; + " nick=excluded.nick, updated_at=datetime('now','localtime')"; if (db_prepare(DB, sql, -1, &stmt, NULL) != SQLITE_OK) return -1; db_bind_text(stmt, 1, key, -1, SQLITE_STATIC); db_bind_text(stmt, 2, value, -1, SQLITE_STATIC); @@ -287,9 +287,9 @@ void db_rotate_history(const char *prefix, const char *value) { } void *stmt; const char *sql = "INSERT INTO zynk(key,value,nick,updated_at)" - " VALUES(?,?,?,datetime('now'))" + " VALUES(?,?,?,datetime('now','localtime'))" " ON CONFLICT(key) DO UPDATE SET value=excluded.value," - " nick=excluded.nick, updated_at=datetime('now')"; + " nick=excluded.nick, updated_at=datetime('now','localtime')"; if (db_prepare(DB, sql, -1, &stmt, NULL) == SQLITE_OK) { db_bind_text(stmt, 1, kbuf[0], -1, SQLITE_STATIC); db_bind_text(stmt, 2, value, -1, SQLITE_STATIC); diff --git a/zynk.h b/zynk.h index 7cd9913..b1e4f6b 100644 --- a/zynk.h +++ b/zynk.h @@ -22,7 +22,7 @@ #include #ifndef ZYNK_VERSION -#define ZYNK_VERSION "0.40.0" +#define ZYNK_VERSION "0.0.0" #endif #define VERSION ZYNK_VERSION