#rfc-3339 #parser #date-time #winnow

no-std winnow_rfc3339

Parsing RFC 3339 dates using winnow

1 unstable release

new 0.1.0 Jan 22, 2025

#434 in Date and time

MIT license

155KB
1.5K SLoC

winnow-rfc3339, making parsing RFC3339 dates a breeze

crates.io docs.rs docs

About

This library contains parsers for parsing RFC3339 dates and their various components built off the winnow-datetime parsers

Parsing

Complete

If you have all the data you need, you can just pass along the input directly.

let datetime = opt(datetime)
    .parse_next(&mut "2015-06-26 16:43:23+0200"));

// 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,
    },
});

Partial

For partial data the only difference is wrapping input in Partial and handling incomplete errors correctly, which is documented in winnow partial docs.

pub type Stream<'i> = Partial<&'i [u8]>;

let datetime = opt(datetime)
    .parse_next(&mut Stream::new("2015-06-26 16: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,
    },
});

Contributors

winnow-rfc3339 is the fruit of the work of many contributors over the years, many thanks for your help!

Documentation

Documentation is online.

License

MIT Licensed. See LICENSE

Dependencies

~4–5MB
~99K SLoC