Open
Description
Trying to parse a string with TZ-Information including seconds (+00:00:00) fails (see below 3rd element in the vector).
use chrono::DateTime; // chrono 0.4.38
fn main() {
// from ...
// https://docs.rs/chrono/latest/chrono/format/strftime/index.html
// ... under "TIME ZONE SPECIFIERS:"
// %::z | +09:30:00 | Offset from the local time to UTC with seconds.
let f = "%Y-%m-%dT%H:%M:%S%::z";
// Testvalues
let tooshort_ok_toolong = [
"2023-01-02T23:24:25+01", // really to short -> fails
"2023-01-02T23:24:25+01:00", // although to short but is Ok ?
"2023-01-02T23:24:25+01:30:01", // _should_ run but fails
];
for s in tooshort_ok_toolong.iter() {
let t = DateTime::parse_from_str(s, f);
println!("Parse {:<28} > {} > {:?}", s, f, t);
}
let dt = chrono::offset::Utc::now();
println!("\nFormatting \"{}\" ok > {} > {}",dt, f, dt.format(f));
}
Running the program gives ...
Parse 2023-01-02T23:24:25+01 > %Y-%m-%dT%H:%M:%S%::z > Err(ParseError(TooShort))
Parse 2023-01-02T23:24:25+01:00 > %Y-%m-%dT%H:%M:%S%::z > Ok(2023-01-02T23:24:25+01:00)
Parse 2023-01-02T23:24:25+01:30:01 > %Y-%m-%dT%H:%M:%S%::z > Err(ParseError(TooLong))
Formatting "2024-11-16 18:36:11.833133 UTC" ok > %Y-%m-%dT%H:%M:%S%::z > 2024-11-16T18:36:11+00:00:00
Formatting "2024-11-16 18:20:44.712920200 UTC" ok %Y-%m-%dT%H:%M:%S%::z > 2024-11-16T18:20:44+00:00:00
Metadata
Metadata
Assignees
Labels
No labels