use core::fmt;
use time::UtcOffset;
use crate::model::Cookie;
#[cfg_attr(docsrs, doc(cfg(feature = "display")))]
impl fmt::Display for Cookie {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let utc = self
.expires
.checked_to_offset(UtcOffset::UTC)
.unwrap_or(self.expires);
let year = utc.year();
if year < 0 {
write!(f, "-{:04}", year.unsigned_abs())?;
} else {
write!(f, "{year:04}")?;
}
write!(
f,
"-{:02}-{:02} {:02}:{:02}:{:02} {} {} {} {}",
u8::from(utc.month()),
utc.day(),
utc.hour(),
utc.minute(),
utc.second(),
self.domain,
self.path,
self.name,
self.value,
)?;
if self.is_secure() {
f.write_str(" Secure")?;
}
if self.is_http_only() {
f.write_str(" HttpOnly")?;
}
if let Some(comment) = self
.comment
.as_deref()
.filter(|comment| !comment.is_empty())
{
write!(f, " /* {comment} */")?;
}
Ok(())
}
}