-
-
Notifications
You must be signed in to change notification settings - Fork 291
Description
When using ISO 8601 formatter, time is formatted having 'T' prefix, for example "T00:23:23.078374000". ISO 8691 parser, however, only allows T if the date component is present. I was able to trace it down to this bit of code:
time/time/src/parsing/iso8601.rs
Line 121 in 037af66
| input = ascii_char::<b'T'>(input) |
Unfortunately I don't have an access to the full original ISO spec, but at least the comment in the linked function and the Wikipedia article on ISO both state that T component CAN be ommitted (as opposed to MUST) in non-ambiguous scenarios. So from my understanding, T prefix should be allowed for times even without dates, at least with later standard iterations.
Example code to reproduce:
main.rs
fn main() {
let now = time::OffsetDateTime::now_utc();
let now_time = now.time();
let now_time_str = now_time
.format(&time::format_description::well_known::Iso8601::TIME)
.unwrap();
let parsed = time::Time::parse(
&now_time_str,
&time::format_description::well_known::Iso8601::TIME,
)
.unwrap(); // Currently fails here
assert_eq!(now_time, parsed);
}Cargo.toml
[package]
name = "timetest"
version = "0.1.0"
edition = "2024"
[dependencies]
time = { version = "0.3.44", features = ["formatting", "parsing"] }The fix seems straightforward enough, so I could probably try and work on it myself. Let me know if I should.