mirror of
https://github.com/fafhrd91/actix-web
synced 2025-07-01 16:55:08 +02:00
Upgrade time
to 0.2.5 (#1254)
* Use `OffsetDateTime` instead of `PrimitiveDateTime` * Parse time strings with `PrimitiveDateTime::parse` instead of `OffsetDateTime::parse` * Remove unused `time` dependency from actix-multipart * Fix a few errors with time related tests from the `time` upgrade * Implement logic to convert a RFC 850 two-digit year into a full length year, and organize time parsing related functions * Upgrade `time` to 0.2.2 * Correctly parse C's asctime time format using time 0.2's new format patterns * Update CHANGES.md * Use `time` without any of its deprecated functions * Enforce a UTC time offset when converting an `OffsetDateTime` into a Header value * Use the more readable version of `Duration::seconds(0)`, `Duration::zero()` * Remove unneeded conversion of time::Duration to std::time::Duration * Use `OffsetDateTime::as_seconds_f64` instead of manually calculating the amount of seconds from nanoseconds * Replace a few additional instances of `Duration::seconds(0)` with `Duration::zero()` * Truncate any nanoseconds from a supplied `Duration` within `Cookie::set_max_age` to ensure two Cookies with the same amount whole seconds equate to one another * Fix the actix-http:🍪:do_not_panic_on_large_max_ages test * Convert `Cookie::max_age` and `Cookie::expires` examples to `time` 0.2 Mainly minor changes. Type inference can be used alongside the new `time::parse` method, such that the type doesn't need to be specified. This will be useful if a refactoring takes place that changes the type. There are also new macros, which are used where possible. One change that is not immediately obvious, in `HttpDate`, there was an unnecessary conditional. As the time crate allows for negative durations (and can perform arithmetic with such), the if/else can be removed entirely. Time v0.2.3 also has some bug fixes, which is why I am not using a more general v0.2 in Cargo.toml. v0.2.3 has been yanked, as it was backwards imcompatible. This version reverts the breaking change, while still supporting rustc back to 1.34.0. * Add missing `time::offset` macro import * Fix type confusion when using `time::parse` followed by `using_offset` * Update `time` to 0.2.5 * Update CHANGES.md Co-authored-by: Jacob Pratt <the.z.cuber@gmail.com>
This commit is contained in:
@ -14,7 +14,7 @@ use bytes::Bytes;
|
||||
use futures::future::{ok, Ready};
|
||||
use log::debug;
|
||||
use regex::Regex;
|
||||
use time;
|
||||
use time::OffsetDateTime;
|
||||
|
||||
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: OffsetDateTime::now(),
|
||||
_t: PhantomData,
|
||||
}
|
||||
} else {
|
||||
let now = time::now();
|
||||
let now = OffsetDateTime::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: OffsetDateTime,
|
||||
format: Option<Format>,
|
||||
_t: PhantomData<(B,)>,
|
||||
}
|
||||
@ -242,7 +242,7 @@ pub struct StreamLog<B> {
|
||||
body: ResponseBody<B>,
|
||||
format: Option<Format>,
|
||||
size: usize,
|
||||
time: time::Tm,
|
||||
time: OffsetDateTime,
|
||||
}
|
||||
|
||||
impl<B> Drop for StreamLog<B> {
|
||||
@ -366,20 +366,20 @@ impl FormatText {
|
||||
&self,
|
||||
fmt: &mut Formatter<'_>,
|
||||
size: usize,
|
||||
entry_time: time::Tm,
|
||||
entry_time: OffsetDateTime,
|
||||
) -> 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 = OffsetDateTime::now() - entry_time;
|
||||
let rt = rt.as_seconds_f64();
|
||||
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 = OffsetDateTime::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: OffsetDateTime, 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 = OffsetDateTime::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 = OffsetDateTime::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 = OffsetDateTime::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 = OffsetDateTime::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"))));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user