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

#2 in Date and time

Download history 1536767/week @ 2024-07-17 1553855/week @ 2024-07-24 1568490/week @ 2024-07-31 1597470/week @ 2024-08-07 1504323/week @ 2024-08-14 1584649/week @ 2024-08-21 1476977/week @ 2024-08-28 1638972/week @ 2024-09-04 1533727/week @ 2024-09-11 1642565/week @ 2024-09-18 1792027/week @ 2024-09-25 2159969/week @ 2024-10-02 2173704/week @ 2024-10-09 2246523/week @ 2024-10-16 1775399/week @ 2024-10-23 1650076/week @ 2024-10-30

8,271,407 downloads per month
Used in 15,646 crates (121 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