|
| 1 | +use std::fmt::{mod, Show}; |
| 2 | +use std::str::FromStr; |
| 3 | +use time::Tm; |
| 4 | +use header::{Header, HeaderFormat}; |
| 5 | +use super::util::{from_one_raw_str, tm_from_str}; |
| 6 | + |
| 7 | +/// The `LastModified` header field. |
| 8 | +#[deriving(PartialEq, Clone)] |
| 9 | +pub struct LastModified(pub Tm); |
| 10 | + |
| 11 | +deref!(LastModified -> Tm) |
| 12 | + |
| 13 | +impl Header for LastModified { |
| 14 | + fn header_name(_: Option<LastModified>) -> &'static str { |
| 15 | + "Last-Modified" |
| 16 | + } |
| 17 | + |
| 18 | + fn parse_header(raw: &[Vec<u8>]) -> Option<LastModified> { |
| 19 | + from_one_raw_str(raw) |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | + |
| 24 | +impl HeaderFormat for LastModified { |
| 25 | + fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result { |
| 26 | + let tm = **self; |
| 27 | + match tm.tm_utcoff { |
| 28 | + 0 => tm.rfc822().fmt(fmt), |
| 29 | + _ => tm.to_utc().rfc822().fmt(fmt) |
| 30 | + } |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +impl FromStr for LastModified { |
| 35 | + fn from_str(s: &str) -> Option<LastModified> { |
| 36 | + tm_from_str(s).map(LastModified) |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +bench_header!(imf_fixdate, LastModified, { vec![b"Sun, 07 Nov 1994 08:48:37 GMT".to_vec()] }) |
| 41 | +bench_header!(rfc_850, LastModified, { vec![b"Sunday, 06-Nov-94 08:49:37 GMT".to_vec()] }) |
| 42 | +bench_header!(asctime, LastModified, { vec![b"Sun Nov 6 08:49:37 1994".to_vec()] }) |
0 commit comments