| Crates.io | iso8601-duration-serde |
| lib.rs | iso8601-duration-serde |
| version | 0.1.0 |
| created_at | 2025-10-19 10:25:47.316981+00 |
| updated_at | 2025-10-19 10:25:47.316981+00 |
| description | A Rust library for serializing and deserializing time::Duration using the ISO 8601 format. |
| homepage | |
| repository | https://github.com/windtail/iso8601-duration-serde |
| max_upload_size | |
| id | 1890316 |
| size | 16,252 |
A Rust library for serializing and deserializing time::Duration using the ISO 8601 format.
This library provides a simple way to serialize and deserialize time::Duration types using the widely supported ISO 8601 duration format.
Examples:
P1D represents 1 dayPT1H represents 1 hourPT30M represents 30 minutesPT45S represents 45 secondsP2DT3H30M15S represents 2 days, 3 hours, 30 minutes, and 15 secondsuse serde::{Serialize, Deserialize};
use time::Duration;
#[derive(Serialize, Deserialize)]
struct Example {
#[serde(with = "iso8601_duration_serde")]
duration: Duration,
}
// Serialization
let example = Example {
duration: Duration::days(1) + Duration::hours(2) + Duration::minutes(30),
};
let json = serde_json::to_string(&example)?;
// json will be: {"duration":"P1DT2H30M"}
// Deserialization
let json = r#"{"duration":"PT45S"}"#;
let example: Example = serde_json::from_str(json)?;
// example.duration will be Duration::seconds(45)
time::DurationThis project is licensed under the MIT License - see the LICENSE file for details.