rosetta-utc
A wrapper implementation of DateTime<Utc> providing binary diesel bindings for SQLite and PostgreSQL.
Why it exists
This crate bridges the gap, providing a unified TimestampUTC type that:
- In PostgreSQL, maps to
TIMESTAMPTZ(Timestamp with time zone), withTimestamptzsql type. - In SQLite, maps to
TEXT, storing ISO8639 strings, withTimestamptzSqlite
The two SQL types are remapped to the same Rust type, TimestampUTC, which internally uses chrono::DateTime<Utc>.
This ensures consistent UTC handling across both databases, preventing common timezone-related bugs in distributed applications.
Features
This crate provides a TimestampUTC wrapper type that implements various traits based on enabled features:
diesel: Enables Diesel integration.postgres: EnablesTimestampUTCsupport for PostgreSQL.sqlite: EnablesTimestampUTCsupport for SQLite.
serde: Enables serialization and deserialization via Serde.wasm: Enables support forTimestampUTC::now()onwasm32-unknown-unknowntargets by enablingchrono/wasmbind.
Usage
Add this to your Cargo.toml. Select the features matching your database requirements.
[]
= { = "0.1", = ["diesel", "postgres", "sqlite", "serde"] }
Example
use TimestampUTC;
use FromStr;
// Get current UTC time
let now = now;
// Parse from string (RFC 3339)
let parsed = from_str.unwrap;
// Access underlying chrono::DateTime<Utc> methods via Deref
println!;