Update Chrono 0.4

This commit is contained in:
PoiScript 2017-08-22 22:57:50 +08:00
parent 2d524faf92
commit 18106c2e0c
4 changed files with 24 additions and 24 deletions

6
Cargo.lock generated
View File

@ -2,7 +2,7 @@
name = "inth-oauth2" name = "inth-oauth2"
version = "0.11.0" version = "0.11.0"
dependencies = [ dependencies = [
"chrono 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hyper 0.10.11 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.10.11 (registry+https://github.com/rust-lang/crates.io-index)",
"hyper-native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "hyper-native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
@ -46,7 +46,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "chrono" name = "chrono"
version = "0.3.1" version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"num 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", "num 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
@ -506,7 +506,7 @@ dependencies = [
"checksum base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "30e93c03064e7590d0466209155251b90c22e37fab1daf2771582598b5827557" "checksum base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "30e93c03064e7590d0466209155251b90c22e37fab1daf2771582598b5827557"
"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5" "checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5"
"checksum byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c40977b0ee6b9885c9013cd41d9feffdd22deb3bb4dc3a71d901cc7a77de18c8" "checksum byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c40977b0ee6b9885c9013cd41d9feffdd22deb3bb4dc3a71d901cc7a77de18c8"
"checksum chrono 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d9123be86fd2a8f627836c235ecdf331fdd067ecf7ac05aa1a68fbcf2429f056" "checksum chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7c20ebe0b2b08b0aeddba49c609fe7957ba2e33449882cb186a180bc60682fa9"
"checksum core-foundation 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "25bfd746d203017f7d5cbd31ee5d8e17f94b6521c7af77ece6c9e4b2d4b16c67" "checksum core-foundation 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "25bfd746d203017f7d5cbd31ee5d8e17f94b6521c7af77ece6c9e4b2d4b16c67"
"checksum core-foundation-sys 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "065a5d7ffdcbc8fa145d6f0746f3555025b9097a9e9cda59f7467abae670c78d" "checksum core-foundation-sys 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "065a5d7ffdcbc8fa145d6f0746f3555025b9097a9e9cda59f7467abae670c78d"
"checksum crypt32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e34988f7e069e0b2f3bfc064295161e489b2d4e04a2e4248fb94360cdf00b4ec" "checksum crypt32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e34988f7e069e0b2f3bfc064295161e489b2d4e04a2e4248fb94360cdf00b4ec"

View File

@ -12,7 +12,7 @@ repository = "https://github.com/programble/inth-oauth2"
readme = "README.md" readme = "README.md"
[dependencies] [dependencies]
chrono = { version = "0.3", features = ["serde"] } chrono = { version = "0.4", features = ["serde"] }
hyper = "0.10" hyper = "0.10"
serde = "1.0.8" serde = "1.0.8"
serde_derive = "1.0.5" serde_derive = "1.0.5"

View File

@ -1,4 +1,4 @@
use chrono::{DateTime, UTC, Duration}; use chrono::{DateTime, Utc, Duration};
use serde_json::Value; use serde_json::Value;
use client::response::{FromResponse, ParseError}; use client::response::{FromResponse, ParseError};
@ -7,16 +7,16 @@ use token::Lifetime;
/// An expiring token. /// An expiring token.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub struct Expiring { pub struct Expiring {
expires: DateTime<UTC>, expires: DateTime<Utc>,
} }
impl Expiring { impl Expiring {
/// Returns the expiry time of the access token. /// Returns the expiry time of the access token.
pub fn expires(&self) -> &DateTime<UTC> { &self.expires } pub fn expires(&self) -> &DateTime<Utc> { &self.expires }
} }
impl Lifetime for Expiring { impl Lifetime for Expiring {
fn expired(&self) -> bool { self.expires < UTC::now() } fn expired(&self) -> bool { self.expires < Utc::now() }
} }
impl FromResponse for Expiring { impl FromResponse for Expiring {
@ -32,14 +32,14 @@ impl FromResponse for Expiring {
.ok_or(ParseError::ExpectedFieldType("expires_in", "i64"))?; .ok_or(ParseError::ExpectedFieldType("expires_in", "i64"))?;
Ok(Expiring { Ok(Expiring {
expires: UTC::now() + Duration::seconds(expires_in), expires: Utc::now() + Duration::seconds(expires_in),
}) })
} }
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use chrono::{UTC, Duration}; use chrono::{Utc, Duration};
use client::response::FromResponse; use client::response::FromResponse;
use super::Expiring; use super::Expiring;
@ -48,7 +48,7 @@ mod tests {
fn from_response() { fn from_response() {
let json = r#"{"expires_in":3600}"#.parse().unwrap(); let json = r#"{"expires_in":3600}"#.parse().unwrap();
let expiring = Expiring::from_response(&json).unwrap(); let expiring = Expiring::from_response(&json).unwrap();
assert!(expiring.expires > UTC::now()); assert!(expiring.expires > Utc::now());
assert!(expiring.expires <= UTC::now() + Duration::seconds(3600)); assert!(expiring.expires <= Utc::now() + Duration::seconds(3600));
} }
} }

View File

@ -1,4 +1,4 @@
use chrono::{DateTime, UTC, Duration}; use chrono::{DateTime, Utc, Duration};
use serde_json::Value; use serde_json::Value;
use client::response::{FromResponse, ParseError}; use client::response::{FromResponse, ParseError};
@ -8,7 +8,7 @@ use token::Lifetime;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Refresh { pub struct Refresh {
refresh_token: String, refresh_token: String,
expires: DateTime<UTC>, expires: DateTime<Utc>,
} }
impl Refresh { impl Refresh {
@ -18,11 +18,11 @@ impl Refresh {
pub fn refresh_token(&self) -> &str { &self.refresh_token } pub fn refresh_token(&self) -> &str { &self.refresh_token }
/// Returns the expiry time of the access token. /// Returns the expiry time of the access token.
pub fn expires(&self) -> &DateTime<UTC> { &self.expires } pub fn expires(&self) -> &DateTime<Utc> { &self.expires }
} }
impl Lifetime for Refresh { impl Lifetime for Refresh {
fn expired(&self) -> bool { self.expires < UTC::now() } fn expired(&self) -> bool { self.expires < Utc::now() }
} }
impl FromResponse for Refresh { impl FromResponse for Refresh {
@ -38,7 +38,7 @@ impl FromResponse for Refresh {
Ok(Refresh { Ok(Refresh {
refresh_token: refresh_token.into(), refresh_token: refresh_token.into(),
expires: UTC::now() + Duration::seconds(expires_in), expires: Utc::now() + Duration::seconds(expires_in),
}) })
} }
@ -56,14 +56,14 @@ impl FromResponse for Refresh {
Ok(Refresh { Ok(Refresh {
refresh_token: refresh_token.into(), refresh_token: refresh_token.into(),
expires: UTC::now() + Duration::seconds(expires_in), expires: Utc::now() + Duration::seconds(expires_in),
}) })
} }
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use chrono::{UTC, Duration}; use chrono::{Utc, Duration};
use client::response::FromResponse; use client::response::FromResponse;
use super::Refresh; use super::Refresh;
@ -73,8 +73,8 @@ mod tests {
let json = r#"{"refresh_token":"aaaaaaaa","expires_in":3600}"#.parse().unwrap(); let json = r#"{"refresh_token":"aaaaaaaa","expires_in":3600}"#.parse().unwrap();
let refresh = Refresh::from_response(&json).unwrap(); let refresh = Refresh::from_response(&json).unwrap();
assert_eq!("aaaaaaaa", refresh.refresh_token); assert_eq!("aaaaaaaa", refresh.refresh_token);
assert!(refresh.expires > UTC::now()); assert!(refresh.expires > Utc::now());
assert!(refresh.expires <= UTC::now() + Duration::seconds(3600)); assert!(refresh.expires <= Utc::now() + Duration::seconds(3600));
} }
#[test] #[test]
@ -82,11 +82,11 @@ mod tests {
let json = r#"{"expires_in":3600}"#.parse().unwrap(); let json = r#"{"expires_in":3600}"#.parse().unwrap();
let prev = Refresh { let prev = Refresh {
refresh_token: String::from("aaaaaaaa"), refresh_token: String::from("aaaaaaaa"),
expires: UTC::now(), expires: Utc::now(),
}; };
let refresh = Refresh::from_response_inherit(&json, &prev).unwrap(); let refresh = Refresh::from_response_inherit(&json, &prev).unwrap();
assert_eq!("aaaaaaaa", refresh.refresh_token); assert_eq!("aaaaaaaa", refresh.refresh_token);
assert!(refresh.expires > UTC::now()); assert!(refresh.expires > Utc::now());
assert!(refresh.expires <= UTC::now() + Duration::seconds(3600)); assert!(refresh.expires <= Utc::now() + Duration::seconds(3600));
} }
} }