5 releases

new 0.2.3 May 14, 2025
0.2.2 May 14, 2025
0.2.1 May 11, 2025
0.2.0 May 4, 2025
0.1.0 Jan 22, 2025

#139 in Date and time

Download history 129/week @ 2025-01-21 2/week @ 2025-01-28 14/week @ 2025-02-04 12/week @ 2025-02-11 5/week @ 2025-03-11 3/week @ 2025-04-08 3/week @ 2025-04-22 108/week @ 2025-04-29 153/week @ 2025-05-06

264 downloads per month
Used in 4 crates

MIT license

49KB
1K SLoC

winnow-datetime, making building new datetime parsers a breeze.

crates.io docs.rs docs

About

This library hopes to provide common parsers and an AST which can be used to convert between these formats, along with others that are share a lot in common with RFC_3339, such as SQL dates/times. Each format crate should follow the following format.

For most use cases using one of the format specific crates will be the best option. However, if you are looking to parse something that doesn't fit into one of the provided formats you can use the parsers provided in this crate to build up your own parser.

Format-specific Crates

RFC3339

winnow-rfc3339 provides parsers for RFC3339 dates and times. This is the most common format used on the internet.

ISO8601

winnow-iso8601 provides parsers for ISO8601 dates, times, durations, and intervals. ISO8601 is a very ambitious format that can represent a wide range of date and time concepts.

Conversion

[winnow-datetime] provides a set of TryInto implementations to convert to common rust date/time libraries. Each have a feature flag of the same name as the lib to enable support for the conversions. The TryInto implementations are available with the features and so try_into() could be called to convert to any of the compatible types which are listed below.

chrono

  • Date -> chrono::NaiveDate
  • Time -> chrono::NaiveTime
  • DateTime -> chrono::DateTime<chrono::FixedOffset>

jiff

  • Date -> jiff::civil::Date
  • DateTime -> jiff::civil::DateTime
  • DateTime -> jiff::Zoned
  • Duration -> jiff::Span
  • Time -> jiff::civil::Time

time

  • Time -> time::Time
  • Date -> time::Date
  • DateTime -> time::PrimitiveDateTime
  • DateTime -> time::OffsetDateTime

Parsing Something Strange

Despite there being countless specifications some people will still come up with their own way to poetically express a datetime. So if you are looking to parse those you can build the provided structs with any combination of the pieces needed. It is probably best to start with the winnow-rfc3339 crate and only replace the parsers where they differ.

Most parsers assume that date and time components are specified from the largest to smallest unit. However, even if the format you need to parse isn't this library would still be a good option to build off, there will just be some additional parts that will have be written by hand, particularly pieces currently handled by macros.

Test and Benchmarking

Format-specific crates will use winnow-datetime-assert to build test and benchmark binaries. This crate provides a large set of test cases which greatly help ensure reliability and performance. Any crates off of these parsers should consider implementing these tests to avoid finding countless edge-cases by trial-and-error.

Dependencies

~0.9–2.6MB
~51K SLoC