Skip to content

Commit

Permalink
Remove unmentained chrono dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
flosse committed Jul 18, 2022
1 parent 51b51bb commit 3f58fa7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
25 changes: 25 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# Changes

## unreleased

- Remove unmaintained `chrono` dependency

### Breaking Changes

Due to security issues caused by the unmaintained `chrono` crate
the `NaiveDateTime` was replaces by a `UnixTime` type:

```diff
- use chrono::NaiveDateTime;
- use geocoding::opencage::Timestamp;
+ use geocoding::opencage::{Timestamp, UnixTime};

let created_http = "Mon, 16 May 2022 14:52:47 GMT".to_string();

let ts_in_seconds = 1_652_712_767_i64;
- let created_unix = NaiveDateTime::from_timestamp(ts_in_seconds, 0);
+ let created_unix = UnixTime::from_seconds(ts_in_seconds);

let timestamp = Timestamp { created_http, created_unix };

+ assert_eq!(ts_in_seconds, created_unix.as_seconds());
```

## 0.4.0

- Switch GeoAdmin API to WGS84
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
reqwest = { version = "0.11", default-features = false, features = ["default-tls", "blocking", "json"] }
hyper = "0.14.11"
chrono = { version = "0.4", features = ["serde"] }

[features]
default = ["reqwest/default"]
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

static UA_STRING: &str = "Rust-Geocoding";

use chrono;
pub use geo_types::{Coordinate, Point};
use num_traits::Float;
use reqwest::blocking::Client;
Expand Down
18 changes: 14 additions & 4 deletions src/opencage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
//! // "Carrer de Calatrava, 68, 08017 Barcelone, Espagne"
//! println!("{:?}", res.unwrap());
//! ```
use crate::chrono::naive::serde::ts_seconds::deserialize as from_ts;
use crate::chrono::NaiveDateTime;
use crate::DeserializeOwned;
use crate::GeocodingError;
use crate::InputBounds;
Expand Down Expand Up @@ -608,8 +606,20 @@ pub struct Status {
#[derive(Debug, Serialize, Deserialize)]
pub struct Timestamp {
pub created_http: String,
#[serde(deserialize_with = "from_ts")]
pub created_unix: NaiveDateTime,
pub created_unix: UnixTime,
}

/// Primitive unix timestamp
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct UnixTime(i64);

impl UnixTime {
pub const fn as_seconds(self) -> i64 {
self.0
}
pub const fn from_seconds(seconds: i64) -> Self {
Self(seconds)
}
}

/// Bounding-box metadata
Expand Down

0 comments on commit 3f58fa7

Please sign in to comment.