diff --git a/actix-http/src/config.rs b/actix-http/src/config.rs index 3221b9b8..abf3d8ff 100644 --- a/actix-http/src/config.rs +++ b/actix-http/src/config.rs @@ -214,7 +214,7 @@ impl Date { write!( self, "{}", - OffsetDateTime::now().format("%a, %d %b %Y %H:%M:%S GMT") + OffsetDateTime::now_utc().format("%a, %d %b %Y %H:%M:%S GMT") ) .unwrap(); } diff --git a/actix-http/src/cookie/builder.rs b/actix-http/src/cookie/builder.rs index 80e7ee71..b64352e3 100644 --- a/actix-http/src/cookie/builder.rs +++ b/actix-http/src/cookie/builder.rs @@ -63,7 +63,7 @@ impl CookieBuilder { /// use actix_http::cookie::Cookie; /// /// let c = Cookie::build("foo", "bar") - /// .expires(time::OffsetDateTime::now()) + /// .expires(time::OffsetDateTime::now_utc()) /// .finish(); /// /// assert!(c.expires().is_some()); diff --git a/actix-http/src/cookie/jar.rs b/actix-http/src/cookie/jar.rs index 9fa6bdc7..0c76c1cf 100644 --- a/actix-http/src/cookie/jar.rs +++ b/actix-http/src/cookie/jar.rs @@ -221,7 +221,7 @@ impl CookieJar { if self.original_cookies.contains(cookie.name()) { cookie.set_value(""); cookie.set_max_age(Duration::zero()); - cookie.set_expires(OffsetDateTime::now() - Duration::days(365)); + cookie.set_expires(OffsetDateTime::now_utc() - Duration::days(365)); self.delta_cookies.replace(DeltaCookie::removed(cookie)); } else { self.delta_cookies.remove(cookie.name()); diff --git a/actix-http/src/cookie/mod.rs b/actix-http/src/cookie/mod.rs index b8ea6f4a..b94e0fe0 100644 --- a/actix-http/src/cookie/mod.rs +++ b/actix-http/src/cookie/mod.rs @@ -733,7 +733,7 @@ impl<'c> Cookie<'c> { pub fn make_permanent(&mut self) { let twenty_years = Duration::days(365 * 20); self.set_max_age(twenty_years); - self.set_expires(OffsetDateTime::now() + twenty_years); + self.set_expires(OffsetDateTime::now_utc() + twenty_years); } fn fmt_parameters(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/actix-http/src/time_parser.rs b/actix-http/src/time_parser.rs index b5b07ccb..0d06a586 100644 --- a/actix-http/src/time_parser.rs +++ b/actix-http/src/time_parser.rs @@ -19,7 +19,7 @@ fn try_parse_rfc_850(time: &str) -> Option { // If the `time` string contains a two-digit year, then as per RFC 2616 ยง 19.3, // we consider the year as part of this century if it's within the next 50 years, // otherwise we consider as part of the previous century. - let now = OffsetDateTime::now(); + let now = OffsetDateTime::now_utc(); let century_start_year = (now.year() / 100) * 100; let mut expanded_year = century_start_year + dt.year(); diff --git a/src/middleware/logger.rs b/src/middleware/logger.rs index e40fe648..7d1577c9 100644 --- a/src/middleware/logger.rs +++ b/src/middleware/logger.rs @@ -163,11 +163,11 @@ where LoggerResponse { fut: self.service.call(req), format: None, - time: OffsetDateTime::now(), + time: OffsetDateTime::now_utc(), _t: PhantomData, } } else { - let now = OffsetDateTime::now(); + let now = OffsetDateTime::now_utc(); let mut format = self.inner.format.clone(); for unit in &mut format.0 { @@ -380,12 +380,12 @@ impl FormatText { FormatText::Percent => "%".fmt(fmt), FormatText::ResponseSize => size.fmt(fmt), FormatText::Time => { - let rt = OffsetDateTime::now() - entry_time; + let rt = OffsetDateTime::now_utc() - entry_time; let rt = rt.as_seconds_f64(); fmt.write_fmt(format_args!("{:.6}", rt)) } FormatText::TimeMillis => { - let rt = OffsetDateTime::now() - entry_time; + let rt = OffsetDateTime::now_utc() - entry_time; let rt = (rt.whole_nanoseconds() as f64) / 1_000_000.0; fmt.write_fmt(format_args!("{:.6}", rt)) } @@ -520,7 +520,7 @@ mod tests { .uri("/test/route/yeah") .to_srv_request(); - let now = OffsetDateTime::now(); + let now = OffsetDateTime::now_utc(); for unit in &mut format.0 { unit.render_request(now, &req); } @@ -551,7 +551,7 @@ mod tests { ) .to_srv_request(); - let now = OffsetDateTime::now(); + let now = OffsetDateTime::now_utc(); for unit in &mut format.0 { unit.render_request(now, &req); } @@ -561,7 +561,7 @@ mod tests { unit.render_response(&resp); } - let entry_time = OffsetDateTime::now(); + let entry_time = OffsetDateTime::now_utc(); let render = |fmt: &mut Formatter<'_>| { for unit in &format.0 { unit.render(fmt, 1024, entry_time)?; @@ -579,7 +579,7 @@ mod tests { let mut format = Format::new("%t"); let req = TestRequest::default().to_srv_request(); - let now = OffsetDateTime::now(); + let now = OffsetDateTime::now_utc(); for unit in &mut format.0 { unit.render_request(now, &req); }