actix_web/http/header/date.rs
1use std::time::SystemTime;
2
3use super::{HttpDate, DATE};
4
5crate::http::header::common_header! {
6 /// `Date` header, defined
7 /// in [RFC 7231 ยง7.1.1.2](https://datatracker.ietf.org/doc/html/rfc7231#section-7.1.1.2)
8 ///
9 /// The `Date` header field represents the date and time at which the
10 /// message was originated.
11 ///
12 /// # ABNF
13 /// ```plain
14 /// Date = HTTP-date
15 /// ```
16 ///
17 /// # Example Values
18 /// * `Tue, 15 Nov 1994 08:12:31 GMT`
19 ///
20 /// # Examples
21 ///
22 /// ```
23 /// use std::time::SystemTime;
24 /// use actix_web::HttpResponse;
25 /// use actix_web::http::header::Date;
26 ///
27 /// let mut builder = HttpResponse::Ok();
28 /// builder.insert_header(
29 /// Date(SystemTime::now().into())
30 /// );
31 /// ```
32 (Date, DATE) => [HttpDate]
33
34 test_parse_and_format {
35 crate::http::header::common_header_test!(test1, [b"Tue, 15 Nov 1994 08:12:31 GMT"]);
36 }
37}
38
39impl Date {
40 /// Create a date instance set to the current system time
41 pub fn now() -> Date {
42 Date(SystemTime::now().into())
43 }
44}