tinystamp

Crates.iotinystamp
lib.rstinystamp
version0.1.0
sourcesrc
created_at2024-04-05 23:37:41.96188
updated_at2024-04-05 23:37:41.96188
descriptionA tiny, zero-dependencies crate to format a timestamp as an ISO-8601 string
homepage
repositoryhttps://github.com/daniel7grant/tinystamp
max_upload_size
id1197945
size11,263
Daniel Grant (daniel7grant)

documentation

https://github.com/daniel7grant/tinystamp

README

Tinystamp

A tiny, zero-dependencies crate to format a timestamp (or now) as an ISO-8601 string (e.g. 2024-04-05T10:01:31Z).

The main usage is in simple code where you need to log a timestamp, but don't need an entire date library, like chrono or time.

Installation

Add this to your Cargo.toml:

tinystamp = "0.1.0"

Usage

The usage is very simple, use the Datetime struct to use a timestamp, or even easier use the current time. The you can format the timestamp as an ISO-8601 string using format_iso8601:

use tinystamp::Datetime;

fn main() {
    let datetime = Datetime::now();
    // or
    let datetime = Datetime::new(1712311291);
    let iso_string = datetime.format_iso8601(); // "2024-04-05T10:01:31Z"
}

The Datetime struct implements display, so it is even easier if you just want to print an ISO-8601 timestamp:

use tinystamp::Datetime;

fn main() {
    println!("{}: An event happened!", Datetime::now());
}

Limitations

To keep this library minimal, there are a few limitations:

  1. It is focused on the current date, so only usable between 2001-2099.
  2. Only ISO-8601 without subseconds supported.
  3. No timezone support, everything is in UTC.
  4. No parsing as of now (maybe there will be ISO-8601 parsing).
Commit count: 10

cargo fmt