Skip to content

Commit

Permalink
chore(sn_api): switch from chrono to time
Browse files Browse the repository at this point in the history
Due to the active security advisory against chrono (RUSTSEC-2020-0159)
is makes sense to switch to a library that is not affected (though we
are not using the affected APIs in `chrono`).
  • Loading branch information
Chris Connelly authored and joshuef committed Oct 26, 2021
1 parent da70738 commit 442c1bd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sn_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ edition = "2018"
[dependencies]
async-recursion = "0.3.2"
bincode = "1.3.1"
chrono = "~0.4"
color-eyre = "~0.5"
dirs-next = "2.0.0"
env_logger = "~0.8"
Expand All @@ -35,6 +34,7 @@ serde_json = "1.0.62"
sha3 = "~0.9"
safe_network = { path = "../sn", version = "0.36.3" }
thiserror = "1.0.23"
time = "0.3.4"
uhttp_uri = "~0.5"
url = "2.2.0"
urlencoding = "1.1.1"
Expand Down
10 changes: 6 additions & 4 deletions sn_api/src/app/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#[cfg(feature = "app")]
use crate::{Error, Result};
use chrono::{DateTime, SecondsFormat, Utc};
use ::time::{format_description::well_known::Rfc3339, OffsetDateTime};

use safe_network::types::{Error as SafeNdError, PublicKey, Token};
use std::{
Expand Down Expand Up @@ -53,10 +53,12 @@ pub fn parse_tokens_amount(amount_str: &str) -> Result<Token> {
}

pub fn systemtime_to_rfc3339(t: time::SystemTime) -> String {
let datetime: DateTime<Utc> = t.into();
datetime.to_rfc3339_opts(SecondsFormat::Secs, true)
let datetime: OffsetDateTime = t.into();
datetime
.format(&Rfc3339)
.expect("formatting OffsetDateTime to RFC 3339 should be infallible")
}

pub fn gen_timestamp_secs() -> String {
Utc::now().to_rfc3339_opts(SecondsFormat::Secs, true)
OffsetDateTime::now_utc().unix_timestamp().to_string()
}

0 comments on commit 442c1bd

Please sign in to comment.