timetraveler

Crates.iotimetraveler
lib.rstimetraveler
version0.2.0
created_at2025-10-06 20:04:54.57151+00
updated_at2025-10-06 20:08:49.159708+00
descriptionLibrary for converting between different time crates
homepagehttps://codeberg.org/Raniz/timetraveler
repositoryhttps://codeberg.org/Raniz/timetraveler
max_upload_size
id1870779
size59,755
Raniz Daniel Raneland (Raniz85)

documentation

README

Timetraveler

A crate for converting between different time representations.

API Documentation

Usage

use timetraveler::{chrono::AsDateTime, time::AsOffsetDateTime};
use time::{macros::datetime, OffsetDateTime};
use chrono::{DateTime, Utc, FixedOffset};
use chrono_tz::{Tz, Europe::Stockholm};
use rxpect::{expect, expectations::EqualityExpectations};
 
// A time::OffsetDateTime
let dt = datetime!(2024-01-01 12:00:00 +02:00);

// Convert to chrono::DateTime<Stockholm>
let utc: DateTime<Utc> = dt.as_date_time_utc();
expect(utc.to_rfc3339().as_ref()).to_equal("2024-01-01T10:00:00+00:00");

// Convert to chrono::DateTime<Stockholm>
let stockholm: DateTime<Tz> = dt.as_date_time(Stockholm);
expect(stockholm.to_rfc3339().as_ref()).to_equal("2024-01-01T11:00:00+01:00");

// Convert back to time::OffsetDateTime
let roundtrip: OffsetDateTime = stockholm.as_offset_date_time();
expect(roundtrip).to_equal(dt);

Features

The conversions in this crate are based on features. One feature per supported crate.

Currently, the only features are chrono and time and they are both enabled by default.

Note that both features must be enabled for the conversions to work—i.e. you can't just enable one of them.

Contributions

Missing a conversion function for a struct? Or maybe for a whole new crate?

Contributions are always welcome, but open an issue first and let's discuss before you sink your precious time into it.

If there is already an open issue, go ahead and open that PR!

License

This project is licensed under both the MIT license and the Apache License (Version 2.0).

Commit count: 0

cargo fmt