6 releases

0.3.2 May 2, 2018
0.3.1 Mar 4, 2018
0.3.0 Sep 6, 2017
0.2.1 Mar 4, 2017
0.1.0 Oct 15, 2016

#6 in Date and time

Download history 966/week @ 2018-11-18 1246/week @ 2018-11-25 1371/week @ 2018-12-02 1659/week @ 2018-12-09 1278/week @ 2018-12-16 758/week @ 2018-12-23 681/week @ 2018-12-30 1090/week @ 2019-01-06 1042/week @ 2019-01-13 1118/week @ 2019-01-20 1105/week @ 2019-01-27 1300/week @ 2019-02-03 1684/week @ 2019-02-10 1426/week @ 2019-02-17 1352/week @ 2019-02-24

3,959 downloads per month
Used in 19 crates (10 directly)

MIT/Apache

18KB
437 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

Read the blog post to learn more.

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


lib.rs:

Date and time utils for HTTP.

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 HttpType (8 bytes) is smaller than SystemTime (16 bytes) and using the display impl avoids a temporary allocation.

No runtime deps