headers/common/
last_modified.rs

1use std::time::SystemTime;
2use util::HttpDate;
3
4/// `Last-Modified` header, defined in
5/// [RFC7232](http://tools.ietf.org/html/rfc7232#section-2.2)
6///
7/// The `Last-Modified` header field in a response provides a timestamp
8/// indicating the date and time at which the origin server believes the
9/// selected representation was last modified, as determined at the
10/// conclusion of handling the request.
11///
12/// # ABNF
13///
14/// ```text
15/// Expires = HTTP-date
16/// ```
17///
18/// # Example values
19///
20/// * `Sat, 29 Oct 1994 19:43:31 GMT`
21///
22/// # Example
23///
24/// ```
25/// # extern crate headers;
26/// use headers::LastModified;
27/// use std::time::{Duration, SystemTime};
28///
29/// let modified = LastModified::from(
30///     SystemTime::now() - Duration::from_secs(60 * 60 * 24)
31/// );
32/// ```
33#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
34pub struct LastModified(pub(super) HttpDate);
35
36derive_header! {
37    LastModified(_),
38    name: LAST_MODIFIED
39}
40
41impl From<SystemTime> for LastModified {
42    fn from(time: SystemTime) -> LastModified {
43        LastModified(time.into())
44    }
45}
46
47impl From<LastModified> for SystemTime {
48    fn from(date: LastModified) -> SystemTime {
49        date.0.into()
50    }
51}