rosetta-utc 0.1.0

A wrapper implementation of DateTime<Utc> providing binary diesel bindings for SQLite and PostgreSQL.
Documentation

rosetta-utc

CI Security Audit License: MIT Codecov Crates.io Docs.rs

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), with Timestamptz sql type.
  • In SQLite, maps to TEXT, storing ISO8639 strings, with TimestamptzSqlite

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: Enables TimestampUTC support for PostgreSQL.
    • sqlite: Enables TimestampUTC support for SQLite.
  • serde: Enables serialization and deserialization via Serde.
  • wasm: Enables support for TimestampUTC::now() on wasm32-unknown-unknown targets by enabling chrono/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());