Expand description
§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.
[dependencies]
rosetta-utc = { version = "0.1", features = ["diesel", "postgres", "sqlite", "serde"] }§Example
use rosetta_utc::TimestampUTC;
use core::str::FromStr;
// Get current UTC time
let now = TimestampUTC::now();
// Parse from string (RFC 3339)
let parsed = TimestampUTC::from_str("2023-10-27T10:00:00+00:00").unwrap();
// Access underlying chrono::DateTime<Utc> methods via Deref
println!("Timestamp: {}", now.timestamp());Modules§
- diesel_
impls - Submodule proving the implementations of the diesel-related traits.
Structs§
- TimestampUTC
- A wrapper around the
chronocrate’sDateTime<Utc>type.