This crate provides high-performance formatting and parsing routines for ISO8601 timestamps, primarily focused on UTC values but with support for parsing (and automatically applying) UTC Offsets.
The primary purpose of this is to keep the lightweight representation of timestamps within data structures, and only formatting it to a string when needed via Serde.
The [Timestamp] struct is only 12 bytes, while the formatted strings can be as large as 35 bytes, and care is taken to avoid heap allocations when formatting.
Example:
use iso8601_timestamp::Timestamp;
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct Event {
name: String,
ts: Timestamp, // only 12 bytes
value: i32,
}when serialized to JSON could result in:
{
"name": "some_event",
"ts": "2021-10-17T02:03:01Z",
"value": 42
}When serializing to non-human-readable formats, such as binary formats, the Timestamp will be written as an i64 representing milliseconds since the Unix Epoch. This way it only uses 8 bytes instead of 24.
Similarly, when deserializing, it supports either an ISO8601 string or an i64 representing a unix timestamp in milliseconds.
-
std(default)- Enables standard library features, such as getting the current time.
-
serde(default)- Enables serde implementations for
Timestampand [TimestampStr]
- Enables serde implementations for
-
rkyv_08- Enables
rkyv0.8 archive support forTimestamp, serializing it as a 64-bit signed unix offset in milliseconds. - NOTE: The archived representation for 0.8 is endian-agnostic, but will depend on how rkyv is configured. See rkyv's documentation for more information. Both systems will need to be configured identically.
- Enables
-
verify- Verifies numeric inputs when parsing and fails when non-numeric input is found.
- When disabled, parsing ignores invalid input, possibly giving garbage timestamps.
-
pg- Enables
ToSql/FromSqlimplementations forTimestampso it can be directly stored/fetched from a PostgreSQL database usingrust-postgres
- Enables
-
rusqlite- Enables
ToSql/FromSqlimplementations forTimestampso it can be stored/fetched from anrusqlite/sqlite3database
- Enables
-
diesel/diesel-pg- Enables support for diesel
ToSql/FromSqlandAsExpression
- Enables support for diesel
-
schema- Enables implementation for
JsonSchemafor generating a JSON schema on the fly usingschemars.
- Enables implementation for
-
bson- Enables
visit_mapimplementation to handle deserializing BSON (MongoDB) DateTime format,{ $date: string }.
- Enables
-
rand- Enables
randimplementations, to generate random timestamps.
- Enables
-
quickcheck- Enables
quickcheck'sArbitraryimplementation onTimestamp
- Enables
-
worker- Enables support for
now_utc()in Cloudflare workers
- Enables support for
-
js- Enables support for
now_utc()in WASM usingjs-sys
- Enables support for
-
ramhorns- Implements
ContentforTimestamp, formatting it as a regular ISO8601 timestamp.
- Implements
-
fred- Implements conversions between
TimestampandRedisValue/RedisKeyto be used withfredRedis client. - Values are stored as milliseconds since the Unix Epoch, and keys are stored as ISO8601 strings.
- Implements conversions between
-
borsh- Implements
Borsh(de)serialization forTimestampusing theborshcrate. - Timestamps are serialized as
i64milliseconds since the Unix Epoch.
- Implements