Skip to content

Commit

Permalink
Merge pull request #60 from georust/mkirk/remove-chrono
Browse files Browse the repository at this point in the history
remove chrono
  • Loading branch information
michaelkirk authored Oct 5, 2023
2 parents f75efa9 + deef29c commit 1343f2b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 14 deletions.
26 changes: 26 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# Changes

## unreleased

- Remove `chrono` dependency
- update geo-types to 0.7.8

### Breaking Changes

Due to previous security issues caused by the `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
- Update CI to use same Rust versions as geo
- Switch GeoAdmin API to WGS84
Expand Down
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ edition = "2018"

[dependencies]
thiserror = "1.0"
geo-types = "0.7"
geo-types = "0.7.8"
num-traits = "0.2"
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
8 changes: 3 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
static UA_STRING: &str = "Rust-Geocoding";

use chrono;
#[allow(deprecated)]
pub use geo_types::{Coordinate, Point};
pub use geo_types::{Coord, Point};
use num_traits::Float;
use reqwest::blocking::Client;
use reqwest::header::ToStrError;
Expand Down Expand Up @@ -103,14 +101,14 @@ where
/// Examples
///
/// ```
/// use geocoding::{Coordinate, Forward, Opencage, Point};
/// use geocoding::{Coord, Forward, Opencage, Point};
///
/// let oc = Opencage::new("dcdbf0d783374909b3debee728c7cc10".to_string());
/// let address = "Schwabing, München";
/// let res: Vec<Point<f64>> = oc.forward(address).unwrap();
/// assert_eq!(
/// res,
/// vec![Point(Coordinate { x: 11.5884858, y: 48.1700887 })]
/// vec![Point(Coord { x: 11.5884858, y: 48.1700887 })]
/// );
/// ```
pub trait Forward<T>
Expand Down
23 changes: 16 additions & 7 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 All @@ -625,8 +635,7 @@ where
#[cfg(test)]
mod test {
use super::*;
#[allow(deprecated)]
use crate::Coordinate;
use crate::Coord;

#[test]
fn reverse_test() {
Expand Down Expand Up @@ -658,7 +667,7 @@ mod test {
let res = oc.forward(&address);
assert_eq!(
res.unwrap(),
vec![Point(Coordinate {
vec![Point(Coord {
x: 11.5884858,
y: 48.1700887
})]
Expand Down

1 comment on commit 1343f2b

@michaelkirk
Copy link
Member Author

@michaelkirk michaelkirk commented on 1343f2b Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am shocked, shocked! to learn that when I merged something which was passing CI 3 months ago, it is now failing CI. (shocked!)

Please sign in to comment.