headers/common/last_modified.rs
1use crate::util::HttpDate;
2use std::time::SystemTime;
3
4/// `Last-Modified` header, defined in
5/// [RFC7232](https://datatracker.ietf.org/doc/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/// use headers::LastModified;
26/// use std::time::{Duration, SystemTime};
27///
28/// let modified = LastModified::from(
29/// SystemTime::now() - Duration::from_secs(60 * 60 * 24)
30/// );
31/// ```
32#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
33pub struct LastModified(pub(super) HttpDate);
34
35derive_header! {
36 LastModified(_),
37 name: LAST_MODIFIED
38}
39
40impl From<SystemTime> for LastModified {
41 fn from(time: SystemTime) -> LastModified {
42 LastModified(time.into())
43 }
44}
45
46impl From<LastModified> for SystemTime {
47 fn from(date: LastModified) -> SystemTime {
48 date.0.into()
49 }
50}