1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-11-18 15:41:17 +00:00

Replace deprecated now with now_utc (#1481)

* Replace deprecated now with now_utc

* Update doctest
This commit is contained in:
Mikail Bagishov 2020-05-02 12:14:50 +03:00 committed by GitHub
parent c27d3fad8e
commit d5ceae2074
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 13 additions and 13 deletions

View file

@ -214,7 +214,7 @@ impl Date {
write!( write!(
self, 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(); .unwrap();
} }

View file

@ -63,7 +63,7 @@ impl CookieBuilder {
/// use actix_http::cookie::Cookie; /// use actix_http::cookie::Cookie;
/// ///
/// let c = Cookie::build("foo", "bar") /// let c = Cookie::build("foo", "bar")
/// .expires(time::OffsetDateTime::now()) /// .expires(time::OffsetDateTime::now_utc())
/// .finish(); /// .finish();
/// ///
/// assert!(c.expires().is_some()); /// assert!(c.expires().is_some());

View file

@ -221,7 +221,7 @@ impl CookieJar {
if self.original_cookies.contains(cookie.name()) { if self.original_cookies.contains(cookie.name()) {
cookie.set_value(""); cookie.set_value("");
cookie.set_max_age(Duration::zero()); 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)); self.delta_cookies.replace(DeltaCookie::removed(cookie));
} else { } else {
self.delta_cookies.remove(cookie.name()); self.delta_cookies.remove(cookie.name());

View file

@ -733,7 +733,7 @@ impl<'c> Cookie<'c> {
pub fn make_permanent(&mut self) { pub fn make_permanent(&mut self) {
let twenty_years = Duration::days(365 * 20); let twenty_years = Duration::days(365 * 20);
self.set_max_age(twenty_years); 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 { fn fmt_parameters(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

View file

@ -19,7 +19,7 @@ fn try_parse_rfc_850(time: &str) -> Option<PrimitiveDateTime> {
// If the `time` string contains a two-digit year, then as per RFC 2616 § 19.3, // 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, // 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. // 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 century_start_year = (now.year() / 100) * 100;
let mut expanded_year = century_start_year + dt.year(); let mut expanded_year = century_start_year + dt.year();

View file

@ -163,11 +163,11 @@ where
LoggerResponse { LoggerResponse {
fut: self.service.call(req), fut: self.service.call(req),
format: None, format: None,
time: OffsetDateTime::now(), time: OffsetDateTime::now_utc(),
_t: PhantomData, _t: PhantomData,
} }
} else { } else {
let now = OffsetDateTime::now(); let now = OffsetDateTime::now_utc();
let mut format = self.inner.format.clone(); let mut format = self.inner.format.clone();
for unit in &mut format.0 { for unit in &mut format.0 {
@ -380,12 +380,12 @@ impl FormatText {
FormatText::Percent => "%".fmt(fmt), FormatText::Percent => "%".fmt(fmt),
FormatText::ResponseSize => size.fmt(fmt), FormatText::ResponseSize => size.fmt(fmt),
FormatText::Time => { FormatText::Time => {
let rt = OffsetDateTime::now() - entry_time; let rt = OffsetDateTime::now_utc() - entry_time;
let rt = rt.as_seconds_f64(); let rt = rt.as_seconds_f64();
fmt.write_fmt(format_args!("{:.6}", rt)) fmt.write_fmt(format_args!("{:.6}", rt))
} }
FormatText::TimeMillis => { 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; let rt = (rt.whole_nanoseconds() as f64) / 1_000_000.0;
fmt.write_fmt(format_args!("{:.6}", rt)) fmt.write_fmt(format_args!("{:.6}", rt))
} }
@ -520,7 +520,7 @@ mod tests {
.uri("/test/route/yeah") .uri("/test/route/yeah")
.to_srv_request(); .to_srv_request();
let now = OffsetDateTime::now(); let now = OffsetDateTime::now_utc();
for unit in &mut format.0 { for unit in &mut format.0 {
unit.render_request(now, &req); unit.render_request(now, &req);
} }
@ -551,7 +551,7 @@ mod tests {
) )
.to_srv_request(); .to_srv_request();
let now = OffsetDateTime::now(); let now = OffsetDateTime::now_utc();
for unit in &mut format.0 { for unit in &mut format.0 {
unit.render_request(now, &req); unit.render_request(now, &req);
} }
@ -561,7 +561,7 @@ mod tests {
unit.render_response(&resp); unit.render_response(&resp);
} }
let entry_time = OffsetDateTime::now(); let entry_time = OffsetDateTime::now_utc();
let render = |fmt: &mut Formatter<'_>| { let render = |fmt: &mut Formatter<'_>| {
for unit in &format.0 { for unit in &format.0 {
unit.render(fmt, 1024, entry_time)?; unit.render(fmt, 1024, entry_time)?;
@ -579,7 +579,7 @@ mod tests {
let mut format = Format::new("%t"); let mut format = Format::new("%t");
let req = TestRequest::default().to_srv_request(); let req = TestRequest::default().to_srv_request();
let now = OffsetDateTime::now(); let now = OffsetDateTime::now_utc();
for unit in &mut format.0 { for unit in &mut format.0 {
unit.render_request(now, &req); unit.render_request(now, &req);
} }