import sqlite3, datetime DB = r"G:\WEB-SERVER\htdocs\AttendanceHub\ZKTecoSyncService-V2\publish\attendancehub_v2.db" NOW = datetime.datetime.now(datetime.timezone.utc) print(f"NOW(UTC) = {NOW.isoformat()}") print(f"NOW(local) = {datetime.datetime.now().isoformat()}") def parse(s): if not s: return None s = s.rstrip("Z") w, _, fr = s.partition(".") fr = (fr + "0000000")[:7] return (datetime.datetime.fromisoformat(w).replace(tzinfo=datetime.timezone.utc) + datetime.timedelta(microseconds=int(fr) / 10)) con = sqlite3.connect(f"file:{DB}?mode=ro", uri=True, timeout=20) print("\n=== the 4 Reconciliation punches, RAW values ===") for pc, dev, pt, fs, st, ack in con.execute( "SELECT personnel_code, device_id, punch_time, first_seen_at, source, acked_at " "FROM punches WHERE source='Reconciliation' AND punch_time >= '2026-10-10' " "AND punch_time <= '2026-10-10T23:59:59.9999999Z' ORDER BY first_seen_at"): p, f = parse(pt), parse(fs) print(f" pin={pc:<8} {dev}") print(f" punch_time(label) = {pt}") print(f" first_seen_at = {fs} {'*** FUTURE ***' if f and f > NOW else '(past)'}") print(f" acked_at = {ack}") if p and f: true_p = p - datetime.timedelta(seconds=12516) print(f" true punch instant = {true_p.isoformat()}" f"{' *** FUTURE ***' if true_p > NOW else ''}") print(f" live leg = {(f - true_p).total_seconds()/60:.1f} min") print("\n=== ANY row with first_seen_at in the future? ===") n = con.execute("SELECT COUNT(*) FROM punches WHERE first_seen_at > ?", (NOW.isoformat().replace("+00:00", "Z"),)).fetchone()[0] print(f" first_seen_at > now : {n}") print("\n=== ANY row with punch_time later today than now (device clock ahead)? ===") q = "SELECT COUNT(*) FROM punches WHERE punch_time > ? AND punch_time < '2026-10-11'" print(" " + str(con.execute(q, (NOW.strftime("%Y-%m-%dT%H:%M:%S.0000000Z"),)).fetchone()[0])) print("\n=== sanity: newest first_seen across all sources ===") for r in con.execute("SELECT MAX(first_seen_at) FROM punches"): print(f" MAX first_seen_at = {r[0]}") con.close()