From ebe92a0f6ca6b01a93e32b2628dd24a667120532 Mon Sep 17 00:00:00 2001 From: kevinpoitra Date: Sat, 4 Jan 2020 13:21:01 -0600 Subject: [PATCH] Upgrade `time` to 0.2.1 --- Cargo.toml | 4 +- actix-http/Cargo.toml | 3 +- actix-http/src/config.rs | 3 +- actix-http/src/cookie/builder.rs | 7 ++- actix-http/src/cookie/jar.rs | 10 ++-- actix-http/src/cookie/mod.rs | 28 +++++----- actix-http/src/cookie/parse.rs | 23 ++++---- actix-http/src/header/shared/httpdate.rs | 68 +++++++++--------------- actix-identity/Cargo.toml | 4 +- actix-identity/src/lib.rs | 13 ++--- actix-multipart/Cargo.toml | 4 +- actix-session/Cargo.toml | 2 +- actix-session/src/cookie.rs | 7 +-- src/middleware/logger.rs | 34 ++++++------ test-server/Cargo.toml | 2 +- 15 files changed, 98 insertions(+), 114 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1adae97b8..17a170d32 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -87,7 +87,7 @@ regex = "1.3" serde = { version = "1.0", features=["derive"] } serde_json = "1.0" serde_urlencoded = "0.6.1" -time = "0.1.42" +time = "0.2.1" url = "2.1" open-ssl = { version="0.10", package = "openssl", optional = true } rust-tls = { version = "0.16.0", package = "rustls", optional = true } @@ -115,4 +115,4 @@ actix-identity = { path = "actix-identity" } actix-session = { path = "actix-session" } actix-files = { path = "actix-files" } actix-multipart = { path = "actix-multipart" } -awc = { path = "awc" } \ No newline at end of file +awc = { path = "awc" } diff --git a/actix-http/Cargo.toml b/actix-http/Cargo.toml index 367dbafec..f08a1fbf6 100644 --- a/actix-http/Cargo.toml +++ b/actix-http/Cargo.toml @@ -52,7 +52,6 @@ base64 = "0.11" bitflags = "1.2" bytes = "0.5.3" copyless = "0.1.4" -chrono = "0.4.6" derive_more = "0.99.2" either = "1.5.3" encoding_rs = "0.8" @@ -77,7 +76,7 @@ serde_json = "1.0" sha1 = "0.6" slab = "0.4" serde_urlencoded = "0.6.1" -time = "0.1.42" +time = "0.2.1" # for secure cookie ring = { version = "0.16.9", optional = true } diff --git a/actix-http/src/config.rs b/actix-http/src/config.rs index be949aaef..6089741da 100644 --- a/actix-http/src/config.rs +++ b/actix-http/src/config.rs @@ -8,6 +8,7 @@ use actix_rt::time::{delay_for, delay_until, Delay, Instant}; use bytes::BytesMut; use futures_util::{future, FutureExt}; use time; +use time::PrimitiveDateTime; // "Sun, 06 Nov 1994 08:49:37 GMT".len() const DATE_VALUE_LENGTH: usize = 29; @@ -211,7 +212,7 @@ impl Date { } fn update(&mut self) { self.pos = 0; - write!(self, "{}", time::at_utc(time::get_time()).rfc822()).unwrap(); + write!(self, "{}", PrimitiveDateTime::now().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 f99d02b02..73b121e2e 100644 --- a/actix-http/src/cookie/builder.rs +++ b/actix-http/src/cookie/builder.rs @@ -1,7 +1,6 @@ use std::borrow::Cow; -use chrono::Duration; -use time::Tm; +use time::{Duration, PrimitiveDateTime}; use super::{Cookie, SameSite}; @@ -70,7 +69,7 @@ impl CookieBuilder { /// assert!(c.expires().is_some()); /// ``` #[inline] - pub fn expires(mut self, when: Tm) -> CookieBuilder { + pub fn expires(mut self, when: PrimitiveDateTime) -> CookieBuilder { self.cookie.set_expires(when); self } @@ -212,7 +211,7 @@ impl CookieBuilder { /// /// ```rust /// use actix_http::cookie::Cookie; - /// use chrono::Duration; + /// use time::Duration; /// /// let c = Cookie::build("foo", "bar") /// .permanent() diff --git a/actix-http/src/cookie/jar.rs b/actix-http/src/cookie/jar.rs index dc2de4dfe..b28102c56 100644 --- a/actix-http/src/cookie/jar.rs +++ b/actix-http/src/cookie/jar.rs @@ -1,7 +1,7 @@ use std::collections::HashSet; use std::mem::replace; -use chrono::Duration; +use time::{Duration, PrimitiveDateTime}; use super::delta::DeltaCookie; use super::Cookie; @@ -188,7 +188,7 @@ impl CookieJar { /// /// ```rust /// use actix_http::cookie::{CookieJar, Cookie}; - /// use chrono::Duration; + /// use time::Duration; /// /// let mut jar = CookieJar::new(); /// @@ -221,7 +221,7 @@ impl CookieJar { if self.original_cookies.contains(cookie.name()) { cookie.set_value(""); cookie.set_max_age(Duration::seconds(0)); - cookie.set_expires(time::now() - Duration::days(365)); + cookie.set_expires(PrimitiveDateTime::now() - Duration::days(365)); self.delta_cookies.replace(DeltaCookie::removed(cookie)); } else { self.delta_cookies.remove(cookie.name()); @@ -239,7 +239,7 @@ impl CookieJar { /// /// ```rust /// use actix_http::cookie::{CookieJar, Cookie}; - /// use chrono::Duration; + /// use time::Duration; /// /// let mut jar = CookieJar::new(); /// @@ -533,7 +533,7 @@ mod test { #[test] #[cfg(feature = "secure-cookies")] fn delta() { - use chrono::Duration; + use time::Duration; use std::collections::HashMap; let mut c = CookieJar::new(); diff --git a/actix-http/src/cookie/mod.rs b/actix-http/src/cookie/mod.rs index 13fd5cf4e..1d56284c5 100644 --- a/actix-http/src/cookie/mod.rs +++ b/actix-http/src/cookie/mod.rs @@ -65,9 +65,8 @@ use std::borrow::Cow; use std::fmt; use std::str::FromStr; -use chrono::Duration; use percent_encoding::{percent_encode, AsciiSet, CONTROLS}; -use time::Tm; +use time::{Duration, PrimitiveDateTime}; pub use self::builder::CookieBuilder; pub use self::draft::*; @@ -172,7 +171,7 @@ pub struct Cookie<'c> { /// The cookie's value. value: CookieStr, /// The cookie's expiration, if any. - expires: Option, + expires: Option, /// The cookie's maximum age, if any. max_age: Option, /// The cookie's domain, if any. @@ -547,7 +546,7 @@ impl<'c> Cookie<'c> { /// assert_eq!(c.expires().map(|t| t.tm_year), Some(117)); /// ``` #[inline] - pub fn expires(&self) -> Option { + pub fn expires(&self) -> Option { self.expires } @@ -645,7 +644,7 @@ impl<'c> Cookie<'c> { /// /// ```rust /// use actix_http::cookie::Cookie; - /// use chrono::Duration; + /// use time::Duration; /// /// let mut c = Cookie::new("name", "value"); /// assert_eq!(c.max_age(), None); @@ -698,18 +697,19 @@ impl<'c> Cookie<'c> { /// /// ```rust /// use actix_http::cookie::Cookie; + /// use time::Duration; /// /// let mut c = Cookie::new("name", "value"); /// assert_eq!(c.expires(), None); /// - /// let mut now = time::now(); - /// now.tm_year += 1; + /// let mut now = time::PrimitiveDateTime::now(); + /// now += Duration::week(); /// /// c.set_expires(now); /// assert!(c.expires().is_some()) /// ``` #[inline] - pub fn set_expires(&mut self, time: Tm) { + pub fn set_expires(&mut self, time: PrimitiveDateTime) { self.expires = Some(time); } @@ -720,7 +720,7 @@ impl<'c> Cookie<'c> { /// /// ```rust /// use actix_http::cookie::Cookie; - /// use chrono::Duration; + /// use time::Duration; /// /// let mut c = Cookie::new("foo", "bar"); /// assert!(c.expires().is_none()); @@ -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(time::now() + twenty_years); + self.set_expires(PrimitiveDateTime::now() + twenty_years); } fn fmt_parameters(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -760,11 +760,11 @@ impl<'c> Cookie<'c> { } if let Some(max_age) = self.max_age() { - write!(f, "; Max-Age={}", max_age.num_seconds())?; + write!(f, "; Max-Age={}", max_age.whole_seconds())?; } if let Some(time) = self.expires() { - write!(f, "; Expires={}", time.rfc822())?; + write!(f, "; Expires={}", time.format("%a, %d %b %Y %H:%M:%S GMT"))?; } Ok(()) @@ -992,7 +992,7 @@ impl<'a, 'b> PartialEq> for Cookie<'a> { #[cfg(test)] mod tests { use super::{Cookie, SameSite}; - use time::strptime; + use time::PrimitiveDateTime; #[test] fn format() { @@ -1017,7 +1017,7 @@ mod tests { assert_eq!(&cookie.to_string(), "foo=bar; Domain=www.rust-lang.org"); let time_str = "Wed, 21 Oct 2015 07:28:00 GMT"; - let expires = strptime(time_str, "%a, %d %b %Y %H:%M:%S %Z").unwrap(); + let expires = PrimitiveDateTime::parse(time_str, "%a, %d %b %Y %H:%M:%S").unwrap(); let cookie = Cookie::build("foo", "bar").expires(expires).finish(); assert_eq!( &cookie.to_string(), diff --git a/actix-http/src/cookie/parse.rs b/actix-http/src/cookie/parse.rs index 20aee9507..157126db9 100644 --- a/actix-http/src/cookie/parse.rs +++ b/actix-http/src/cookie/parse.rs @@ -5,8 +5,8 @@ use std::error::Error; use std::fmt; use std::str::Utf8Error; -use chrono::Duration; use percent_encoding::percent_decode; +use time::{Duration, PrimitiveDateTime}; use super::{Cookie, CookieStr, SameSite}; @@ -147,7 +147,7 @@ fn parse_inner<'c>(s: &str, decode: bool) -> Result, ParseError> { Ok(val) => { // Don't panic if the max age seconds is greater than what's supported by // `Duration`. - let val = cmp::min(val, Duration::max_value().num_seconds()); + let val = cmp::min(val, Duration::max_value().whole_seconds()); Some(Duration::seconds(val)) } Err(_) => continue, @@ -179,13 +179,13 @@ fn parse_inner<'c>(s: &str, decode: bool) -> Result, ParseError> { } } ("expires", Some(v)) => { - // Try strptime with three date formats according to + // Try parsing with three date formats according to // http://tools.ietf.org/html/rfc2616#section-3.3.1. Try // additional ones as encountered in the real world. - let tm = time::strptime(v, "%a, %d %b %Y %H:%M:%S %Z") - .or_else(|_| time::strptime(v, "%A, %d-%b-%y %H:%M:%S %Z")) - .or_else(|_| time::strptime(v, "%a, %d-%b-%Y %H:%M:%S %Z")) - .or_else(|_| time::strptime(v, "%a %b %d %H:%M:%S %Y")); + let tm = PrimitiveDateTime::parse(v, "%a, %d %b %Y %H:%M:%S") + .or_else(|_| PrimitiveDateTime::parse(v, "%A, %d-%b-%y %H:%M:%S")) + .or_else(|_| PrimitiveDateTime::parse(v, "%a, %d-%b-%Y %H:%M:%S")) + .or_else(|_| PrimitiveDateTime::parse(v, "%a %b %d %H:%M:%S %Y")); if let Ok(time) = tm { cookie.expires = Some(time) @@ -216,8 +216,7 @@ where #[cfg(test)] mod tests { use super::{Cookie, SameSite}; - use chrono::Duration; - use time::strptime; + use time::{Duration, PrimitiveDateTime}; macro_rules! assert_eq_parse { ($string:expr, $expected:expr) => { @@ -377,7 +376,7 @@ mod tests { ); let time_str = "Wed, 21 Oct 2015 07:28:00 GMT"; - let expires = strptime(time_str, "%a, %d %b %Y %H:%M:%S %Z").unwrap(); + let expires = PrimitiveDateTime::parse(time_str, "%a, %d %b %Y %H:%M:%S").unwrap(); expected.set_expires(expires); assert_eq_parse!( " foo=bar ;HttpOnly; Secure; Max-Age=4; Path=/foo; \ @@ -386,7 +385,7 @@ mod tests { ); unexpected.set_domain("foo.com"); - let bad_expires = strptime(time_str, "%a, %d %b %Y %H:%S:%M %Z").unwrap(); + let bad_expires = PrimitiveDateTime::parse(time_str, "%a, %d %b %Y %H:%S:%M").unwrap(); expected.set_expires(bad_expires); assert_ne_parse!( " foo=bar ;HttpOnly; Secure; Max-Age=4; Path=/foo; \ @@ -414,7 +413,7 @@ mod tests { #[test] fn do_not_panic_on_large_max_ages() { - let max_seconds = Duration::max_value().num_seconds(); + let max_seconds = Duration::max_value().whole_seconds(); let expected = Cookie::build("foo", "bar").max_age(max_seconds).finish(); assert_eq_parse!(format!(" foo=bar; Max-Age={:?}", max_seconds + 1), expected); } diff --git a/actix-http/src/header/shared/httpdate.rs b/actix-http/src/header/shared/httpdate.rs index 28d6a25ec..5177a7513 100644 --- a/actix-http/src/header/shared/httpdate.rs +++ b/actix-http/src/header/shared/httpdate.rs @@ -1,59 +1,50 @@ use std::fmt::{self, Display}; use std::io::Write; use std::str::FromStr; -use std::time::{Duration, SystemTime, UNIX_EPOCH}; +use std::time::{SystemTime, UNIX_EPOCH}; use bytes::{buf::BufMutExt, BytesMut}; use http::header::{HeaderValue, InvalidHeaderValue}; +use time::PrimitiveDateTime; use crate::error::ParseError; use crate::header::IntoHeaderValue; /// A timestamp with HTTP formatting and parsing #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] -pub struct HttpDate(time::Tm); +pub struct HttpDate(time::PrimitiveDateTime); impl FromStr for HttpDate { type Err = ParseError; fn from_str(s: &str) -> Result { - match time::strptime(s, "%a, %d %b %Y %T %Z") - .or_else(|_| time::strptime(s, "%A, %d-%b-%y %T %Z")) - .or_else(|_| time::strptime(s, "%c")) + match PrimitiveDateTime::parse(s, "%a, %d %b %Y %H:%M:%S") + .or_else(|_| PrimitiveDateTime::parse(s, "%A, %d-%b-%y %H:%M:%S")) + .or_else(|_| PrimitiveDateTime::parse(s, "%c")) { Ok(t) => Ok(HttpDate(t)), - Err(_) => Err(ParseError::Header), + Err(_) => { + Err(ParseError::Header) + }, } } } impl Display for HttpDate { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Display::fmt(&self.0.to_utc().rfc822(), f) + fmt::Display::fmt(&self.0.format("%a, %d %b %Y %H:%M:%S GMT"), f) } } -impl From for HttpDate { - fn from(tm: time::Tm) -> HttpDate { - HttpDate(tm) +impl From for HttpDate { + fn from(dt: time::PrimitiveDateTime) -> HttpDate { + HttpDate(dt) } } impl From for HttpDate { fn from(sys: SystemTime) -> HttpDate { - let tmspec = match sys.duration_since(UNIX_EPOCH) { - Ok(dur) => { - time::Timespec::new(dur.as_secs() as i64, dur.subsec_nanos() as i32) - } - Err(err) => { - let neg = err.duration(); - time::Timespec::new( - -(neg.as_secs() as i64), - -(neg.subsec_nanos() as i32), - ) - } - }; - HttpDate(time::at_utc(tmspec)) + HttpDate(PrimitiveDateTime::from(sys)) } } @@ -62,18 +53,20 @@ impl IntoHeaderValue for HttpDate { fn try_into(self) -> Result { let mut wrt = BytesMut::with_capacity(29).writer(); - write!(wrt, "{}", self.0.rfc822()).unwrap(); + write!(wrt, "{}", self.0.format("%a, %d %b %Y %H:%M:%S GMT")).unwrap(); HeaderValue::from_maybe_shared(wrt.get_mut().split().freeze()) } } impl From for SystemTime { fn from(date: HttpDate) -> SystemTime { - let spec = date.0.to_timespec(); - if spec.sec >= 0 { - UNIX_EPOCH + Duration::new(spec.sec as u64, spec.nsec as u32) + let dt = date.0; + let epoch = PrimitiveDateTime::unix_epoch(); + + if dt >= epoch { + UNIX_EPOCH + (dt - epoch) } else { - UNIX_EPOCH - Duration::new(spec.sec as u64, spec.nsec as u32) + UNIX_EPOCH - (epoch - dt) } } } @@ -81,21 +74,12 @@ impl From for SystemTime { #[cfg(test)] mod tests { use super::HttpDate; - use time::Tm; + use time::{PrimitiveDateTime, Date, Time}; - const NOV_07: HttpDate = HttpDate(Tm { - tm_nsec: 0, - tm_sec: 37, - tm_min: 48, - tm_hour: 8, - tm_mday: 7, - tm_mon: 10, - tm_year: 94, - tm_wday: 0, - tm_isdst: 0, - tm_yday: 0, - tm_utcoff: 0, - }); + const NOV_07: HttpDate = HttpDate(PrimitiveDateTime::new( + Date::try_from_ymd(1994, 11, 7).unwrap(), + Time::try_from_hms(8, 48, 37).unwrap() + )); #[test] fn test_date() { diff --git a/actix-identity/Cargo.toml b/actix-identity/Cargo.toml index b30246f0b..db850d39e 100644 --- a/actix-identity/Cargo.toml +++ b/actix-identity/Cargo.toml @@ -22,9 +22,9 @@ actix-service = "1.0.1" futures = "0.3.1" serde = "1.0" serde_json = "1.0" -time = "0.1.42" +time = "0.2.1" [dev-dependencies] actix-rt = "1.0.0" actix-http = "1.0.1" -bytes = "0.5.3" \ No newline at end of file +bytes = "0.5.3" diff --git a/actix-identity/src/lib.rs b/actix-identity/src/lib.rs index b10a419dd..5b0bdb1db 100644 --- a/actix-identity/src/lib.rs +++ b/actix-identity/src/lib.rs @@ -47,6 +47,7 @@ //! } //! ``` use std::cell::RefCell; +use std::convert::TryFrom; use std::future::Future; use std::rc::Rc; use std::task::{Context, Poll}; @@ -417,14 +418,14 @@ impl CookieIdentityInner { let now = SystemTime::now(); if let Some(visit_deadline) = self.visit_deadline { if now.duration_since(value.visit_timestamp?).ok()? - > visit_deadline.to_std().ok()? + > std::time::Duration::try_from(visit_deadline).ok()? { return None; } } if let Some(login_deadline) = self.login_deadline { if now.duration_since(value.login_timestamp?).ok()? - > login_deadline.to_std().ok()? + > std::time::Duration::try_from(login_deadline).ok()? { return None; } @@ -843,7 +844,7 @@ mod tests { let cv: CookieValue = serde_json::from_str(cookie.value()).unwrap(); assert_eq!(cv.identity, identity); let now = SystemTime::now(); - let t30sec_ago = now - Duration::seconds(30).to_std().unwrap(); + let t30sec_ago = now - std::time::Duration::try_from(Duration::seconds(30)).unwrap(); match login_timestamp { LoginTimestampCheck::NoTimestamp => assert_eq!(cv.login_timestamp, None), LoginTimestampCheck::NewTimestamp => assert!( @@ -985,7 +986,7 @@ mod tests { create_identity_server(|c| c.login_deadline(Duration::days(90))).await; let cookie = login_cookie( COOKIE_LOGIN, - Some(SystemTime::now() - Duration::days(180).to_std().unwrap()), + Some(SystemTime::now() - std::time::Duration::try_from(Duration::days(180)).unwrap()), None, ); let mut resp = test::call_service( @@ -1011,7 +1012,7 @@ mod tests { let cookie = login_cookie( COOKIE_LOGIN, None, - Some(SystemTime::now() - Duration::days(180).to_std().unwrap()), + Some(SystemTime::now() - std::time::Duration::try_from(Duration::days(180)).unwrap()), ); let mut resp = test::call_service( &mut srv, @@ -1052,7 +1053,7 @@ mod tests { .login_deadline(Duration::days(90)) }) .await; - let timestamp = SystemTime::now() - Duration::days(1).to_std().unwrap(); + let timestamp = SystemTime::now() - std::time::Duration::try_from(Duration::days(1)).unwrap(); let cookie = login_cookie(COOKIE_LOGIN, Some(timestamp), Some(timestamp)); let mut resp = test::call_service( &mut srv, diff --git a/actix-multipart/Cargo.toml b/actix-multipart/Cargo.toml index 6c683cb1a..ad9d9a720 100644 --- a/actix-multipart/Cargo.toml +++ b/actix-multipart/Cargo.toml @@ -25,9 +25,9 @@ httparse = "1.3" futures = "0.3.1" log = "0.4" mime = "0.3" -time = "0.1" +time = "0.2.1" twoway = "0.2" [dev-dependencies] actix-rt = "1.0.0" -actix-http = "1.0.0" \ No newline at end of file +actix-http = "1.0.0" diff --git a/actix-session/Cargo.toml b/actix-session/Cargo.toml index 5989cc0d6..ad78ea321 100644 --- a/actix-session/Cargo.toml +++ b/actix-session/Cargo.toml @@ -29,7 +29,7 @@ derive_more = "0.99.2" futures = "0.3.1" serde = "1.0" serde_json = "1.0" -time = "0.1.42" +time = "0.2.1" [dev-dependencies] actix-rt = "1.0.0" diff --git a/actix-session/src/cookie.rs b/actix-session/src/cookie.rs index 75eef0c01..355f49d77 100644 --- a/actix-session/src/cookie.rs +++ b/actix-session/src/cookie.rs @@ -27,6 +27,7 @@ use actix_web::{Error, HttpMessage, ResponseError}; use derive_more::{Display, From}; use futures::future::{ok, FutureExt, LocalBoxFuture, Ready}; use serde_json::error::Error as JsonError; +use time::{Duration, PrimitiveDateTime}; use crate::{Session, SessionStatus}; @@ -56,7 +57,7 @@ struct CookieSessionInner { domain: Option, secure: bool, http_only: bool, - max_age: Option, + max_age: Option, same_site: Option, } @@ -123,8 +124,8 @@ impl CookieSessionInner { fn remove_cookie(&self, res: &mut ServiceResponse) -> Result<(), Error> { let mut cookie = Cookie::named(self.name.clone()); cookie.set_value(""); - cookie.set_max_age(time::Duration::seconds(0)); - cookie.set_expires(time::now() - time::Duration::days(365)); + cookie.set_max_age(Duration::seconds(0)); + cookie.set_expires(PrimitiveDateTime::now() - Duration::days(365)); let val = HeaderValue::from_str(&cookie.to_string())?; res.headers_mut().append(SET_COOKIE, val); diff --git a/src/middleware/logger.rs b/src/middleware/logger.rs index 97fa7463f..cd15e3e03 100644 --- a/src/middleware/logger.rs +++ b/src/middleware/logger.rs @@ -14,7 +14,7 @@ use bytes::Bytes; use futures::future::{ok, Ready}; use log::debug; use regex::Regex; -use time; +use time::PrimitiveDateTime; use crate::dev::{BodySize, MessageBody, ResponseBody}; use crate::error::{Error, Result}; @@ -163,11 +163,11 @@ where LoggerResponse { fut: self.service.call(req), format: None, - time: time::now(), + time: PrimitiveDateTime::now(), _t: PhantomData, } } else { - let now = time::now(); + let now = PrimitiveDateTime::now(); let mut format = self.inner.format.clone(); for unit in &mut format.0 { @@ -192,7 +192,7 @@ where { #[pin] fut: S::Future, - time: time::Tm, + time: time::PrimitiveDateTime, format: Option, _t: PhantomData<(B,)>, } @@ -242,7 +242,7 @@ pub struct StreamLog { body: ResponseBody, format: Option, size: usize, - time: time::Tm, + time: time::PrimitiveDateTime, } impl Drop for StreamLog { @@ -366,20 +366,20 @@ impl FormatText { &self, fmt: &mut Formatter<'_>, size: usize, - entry_time: time::Tm, + entry_time: time::PrimitiveDateTime, ) -> Result<(), fmt::Error> { match *self { FormatText::Str(ref string) => fmt.write_str(string), FormatText::Percent => "%".fmt(fmt), FormatText::ResponseSize => size.fmt(fmt), FormatText::Time => { - let rt = time::now() - entry_time; - let rt = (rt.num_nanoseconds().unwrap_or(0) as f64) / 1_000_000_000.0; + let rt = PrimitiveDateTime::now() - entry_time; + let rt = (rt.whole_nanoseconds() as f64) / 1_000_000_000.0; fmt.write_fmt(format_args!("{:.6}", rt)) } FormatText::TimeMillis => { - let rt = time::now() - entry_time; - let rt = (rt.num_nanoseconds().unwrap_or(0) as f64) / 1_000_000.0; + let rt = PrimitiveDateTime::now() - entry_time; + let rt = (rt.whole_nanoseconds() as f64) / 1_000_000.0; fmt.write_fmt(format_args!("{:.6}", rt)) } FormatText::EnvironHeader(ref name) => { @@ -414,7 +414,7 @@ impl FormatText { } } - fn render_request(&mut self, now: time::Tm, req: &ServiceRequest) { + fn render_request(&mut self, now: PrimitiveDateTime, req: &ServiceRequest) { match *self { FormatText::RequestLine => { *self = if req.query_string().is_empty() { @@ -436,7 +436,7 @@ impl FormatText { } FormatText::UrlPath => *self = FormatText::Str(req.path().to_string()), FormatText::RequestTime => { - *self = FormatText::Str(now.rfc3339().to_string()) + *self = FormatText::Str(now.format("%Y-%m-%dT%H:%M:%S")) } FormatText::RequestHeader(ref name) => { let s = if let Some(val) = req.headers().get(name) { @@ -513,7 +513,7 @@ mod tests { .uri("/test/route/yeah") .to_srv_request(); - let now = time::now(); + let now = PrimitiveDateTime::now(); for unit in &mut format.0 { unit.render_request(now, &req); } @@ -544,7 +544,7 @@ mod tests { ) .to_srv_request(); - let now = time::now(); + let now = PrimitiveDateTime::now(); for unit in &mut format.0 { unit.render_request(now, &req); } @@ -554,7 +554,7 @@ mod tests { unit.render_response(&resp); } - let entry_time = time::now(); + let entry_time = PrimitiveDateTime::now(); let render = |fmt: &mut Formatter<'_>| { for unit in &format.0 { unit.render(fmt, 1024, entry_time)?; @@ -572,7 +572,7 @@ mod tests { let mut format = Format::new("%t"); let req = TestRequest::default().to_srv_request(); - let now = time::now(); + let now = PrimitiveDateTime::now(); for unit in &mut format.0 { unit.render_request(now, &req); } @@ -589,6 +589,6 @@ mod tests { Ok(()) }; let s = format!("{}", FormatDisplay(&render)); - assert!(s.contains(&format!("{}", now.rfc3339()))); + assert!(s.contains(&format!("{}", now.format("%Y-%m-%dT%H:%M:%S")))); } } diff --git a/test-server/Cargo.toml b/test-server/Cargo.toml index 52a2da8da..dd461892f 100644 --- a/test-server/Cargo.toml +++ b/test-server/Cargo.toml @@ -51,7 +51,7 @@ serde_json = "1.0" sha1 = "0.6" slab = "0.4" serde_urlencoded = "0.6.1" -time = "0.1" +time = "0.2.1" open-ssl = { version="0.10", package="openssl", optional = true } [dev-dependencies]