Crates.io | winnow_iso8601 |
lib.rs | winnow_iso8601 |
version | |
source | src |
created_at | 2024-11-15 14:43:36.162612 |
updated_at | 2024-11-17 20:45:22.624711 |
description | Parsing ISO8601 dates using winnow |
homepage | |
repository | https://github.com/soulstompp/winnow-iso8601 |
max_upload_size | |
id | 1449187 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
This library contains parsers for parsing ISO8601 dates and their various components.
If you have all the data you need, you can just pass along the bytes. Passing in &mut &str
isn't yet
supported but will be supported in the future.
let datetime = opt(parse_datetime)
.parse_next(&mut "2015-06-26T16:43:23+0200".as_bytes()));
// the above will give you:
Some(DateTime {
date: Date::YMD {
year: 2015,
month: 6,
day: 26,
},
time: Time {
hour: 16,
minute: 43,
second: 23,
tz_offset_hours: 2,
tz_offset_minutes: 0,
},
});
For partial data the only difference is wrapping the &'i [u8] in Partial and handling incomplete errors correctly, which is documented in winnow partial docs.
pub type Stream<'i> = Partial<&'i [u8]>;
let datetime = opt(parse_datetime)
.parse_next(&mut Stream::new("2015-06-26T16:43:23+0200").as_bytes()));
// the above will give you:
Some(DateTime {
date: Date::YMD {
year: 2015,
month: 6,
day: 26,
},
time: Time {
hour: 16,
minute: 43,
second: 23,
tz_offset_hours: 2,
tz_offset_minutes: 0,
},
});
If you have a datetime string handy you can use the helper methods such as datetime to get a DateTime object. This can
be serialized into a chrono date object if the serde
feature is enabled.
let datetime = winnow_iso8601::datetime("2015-06-26T16:43:23+0200").unwrap();
// the above will give you:
DateTime {
date: Date::YMD {
year: 2015,
month: 6,
day: 26,
},
time: Time {
hour: 16,
minute: 43,
second: 23,
tz_offset_hours: 2,
tz_offset_minutes: 0,
},
};
winnow-iso8601 is the fruit of the work of many contributors over the years, many
thanks for your help! In particular, thanks to badboy
and hoodie for the original iso8601
crate and actually reading the standard.
Documentation is online.
MIT Licensed. See LICENSE