package core import "time" // stampLayout is the one canonical on-disk timestamp format. // // It is deliberately fixed-width: exactly three fractional digits and a literal // trailing Z. The columns it feeds are compared as TEXT by SQLite, so // lexicographic order MUST equal chronological order for every ORDER BY, MAX, // and `run_after <= ?` / `expires_at < ?` comparison to be correct. // // time.RFC3339Nano cannot be used for writes because it trims trailing zeros, // which makes the fraction width vary: ".5Z" sorts after ".55Z" as a string // even though 500ms is earlier than 550ms. That is wrong even when a column is // written 100% by Go; it is not a cross-format problem. // // The layout also matches SQLite's own default // strftime('%Y-%m-%dT%H:%M:%fZ','now'), which emits exactly three fractional // digits and a Z. Matching it byte-for-byte means rows written by Go and rows // written by a column DEFAULT compare correctly against each other. const stampLayout = "2006-01-02T15:04:05.000Z" // Stamp formats t as the canonical database timestamp. func Stamp(t time.Time) string { return t.UTC().Format(stampLayout) } // Now returns the current time as the canonical database timestamp. func Now() string { return Stamp(time.Now()) }