11 releases (4 stable)

1.0.3 Aug 13, 2023
1.0.2 Nov 17, 2021
1.0.1 May 24, 2021
1.0.0 Mar 31, 2021
0.1.0 Oct 15, 2016

#3 in Date and time

Download history 1563913/week @ 2024-07-27 1530245/week @ 2024-08-03 1583030/week @ 2024-08-10 1565065/week @ 2024-08-17 1591769/week @ 2024-08-24 1497485/week @ 2024-08-31 1581572/week @ 2024-09-07 1463606/week @ 2024-09-14 1741969/week @ 2024-09-21 1807077/week @ 2024-09-28 2274760/week @ 2024-10-05 2144971/week @ 2024-10-12 2238637/week @ 2024-10-19 1694013/week @ 2024-10-26 1685695/week @ 2024-11-02 1389786/week @ 2024-11-09

7,313,432 downloads per month
Used in 14,419 crates (123 directly)

MIT/Apache

20KB
481 lines

Date and time utils for HTTP.

Build Status Crates.io Documentation

Multiple HTTP header fields store timestamps. For example a response created on May 15, 2015 may contain the header Date: Fri, 15 May 2015 15:34:21 GMT. Since the timestamp does not contain any timezone or leap second information it is equvivalent to writing 1431696861 Unix time. Rust’s SystemTime is used to store these timestamps.

This crate provides two public functions:

  • parse_http_date to parse a HTTP datetime string to a system time
  • fmt_http_date to format a system time to a IMF-fixdate

In addition it exposes the HttpDate type that can be used to parse and format timestamps. Convert a sytem time to HttpDate and vice versa. The HttpDate (8 bytes) is smaller than SystemTime (16 bytes) and using the display impl avoids a temporary allocation.

Read the blog post to learn more.

Fuzz it by installing cargo-fuzz and running cargo fuzz run fuzz_target_1.

No runtime deps