| Crates.io | timetraveler |
| lib.rs | timetraveler |
| version | 0.2.0 |
| created_at | 2025-10-06 20:04:54.57151+00 |
| updated_at | 2025-10-06 20:08:49.159708+00 |
| description | Library for converting between different time crates |
| homepage | https://codeberg.org/Raniz/timetraveler |
| repository | https://codeberg.org/Raniz/timetraveler |
| max_upload_size | |
| id | 1870779 |
| size | 59,755 |
A crate for converting between different time representations.
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);
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.
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!
This project is licensed under both the MIT license and the Apache License (Version 2.0).