hive-agent: finish chrono-clock migration on remaining call sites

This commit is contained in:
damocles 2026-08-01 23:49:03 +02:00 committed by mara
commit f4a35786b1
10 changed files with 63 additions and 47 deletions

View file

@ -17,8 +17,9 @@ use std::path::Path;
use std::sync::Mutex;
use anyhow::{Context, Result};
use chrono::{DateTime, Utc};
use hive_sh4re::ReminderStats;
use hive_sh4re::wire_time::now_unix;
use hive_sh4re::wire_time;
use rusqlite::{Connection, params};
const SCHEMA: &str = r"
@ -42,8 +43,8 @@ pub struct Reminder {
pub id: i64,
pub message: String,
pub file_path: Option<String>,
pub due_at: i64,
pub created_at: i64,
pub due_at: DateTime<Utc>,
pub created_at: DateTime<Utc>,
}
/// The harness-local reminder store. Cheap to share behind an `Arc`; the
@ -81,7 +82,7 @@ impl Reminders {
/// Panics if the connection mutex is poisoned.
pub fn store(&self, message: &str, file_path: Option<&str>, due_at: i64) -> Result<i64> {
let conn = self.conn.lock().unwrap();
let now = now_unix();
let now = Utc::now().timestamp();
conn.execute(
"INSERT INTO reminders (message, file_path, due_at, created_at, sent_at) \
VALUES (?1, ?2, ?3, ?4, NULL)",
@ -170,7 +171,7 @@ impl Reminders {
let conn = self.conn.lock().unwrap();
conn.execute(
"UPDATE reminders SET sent_at = ?1 WHERE id = ?2",
params![now_unix(), id],
params![Utc::now().timestamp(), id],
)?;
Ok(())
}
@ -210,7 +211,7 @@ impl Reminders {
pub fn rollup(&self, since_secs: i64) -> Result<ReminderStats> {
let conn = self.conn.lock().unwrap();
let cutoff = if since_secs > 0 {
now_unix().saturating_sub(since_secs)
Utc::now().timestamp().saturating_sub(since_secs)
} else {
i64::MIN
};
@ -258,12 +259,14 @@ impl Reminders {
}
fn row_to_reminder(row: &rusqlite::Row) -> rusqlite::Result<Reminder> {
let due_at_secs: i64 = row.get(3)?;
let created_at_secs: i64 = row.get(4)?;
Ok(Reminder {
id: row.get(0)?,
message: row.get(1)?,
file_path: row.get(2)?,
due_at: row.get(3)?,
created_at: row.get(4)?,
due_at: wire_time::from_secs(due_at_secs),
created_at: wire_time::from_secs(created_at_secs),
})
}
@ -287,7 +290,7 @@ mod tests {
let pending = s.list_pending().unwrap();
assert_eq!(pending.len(), 1);
assert_eq!(pending[0].id, id);
assert_eq!(pending[0].due_at, 1000);
assert_eq!(pending[0].due_at.timestamp(), 1000);
assert_eq!(s.count_pending().unwrap(), 1);
}
@ -348,7 +351,7 @@ mod tests {
)
.unwrap();
}
let cutoff = now_unix() - 10;
let cutoff = Utc::now().timestamp() - 10;
let n = s.prune_delivered_older_than(cutoff).unwrap();
assert_eq!(n, 1, "only the backdated row is older than cutoff");
let remaining_ids: Vec<i64> = {