Skip to content

Commit 3eadcb1

Browse files
authored
Replace chrono with humantime in provenance doc tests. (#175)
Closes #173 Closes #174
1 parent 4def777 commit 3eadcb1

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ serde-pickle = "1.1.0"
3333
bincode = "1.3.1"
3434
rand = "0.8.3"
3535
rand_distr = "0.4.0"
36-
chrono = "0.4.19"
36+
humantime = {version = "2.1.0"}
37+
# chrono is out (for now) due to security issues
38+
# chrono = "0.4.19"
3739

3840
[build-dependencies]
3941
bindgen = "0.59.1"

src/provenance.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,9 @@ assert_eq!(record_0, row_0.record);
4545
let timestamp = prov_ref.timestamp(0).unwrap();
4646
assert_eq!(timestamp, row_0.timestamp);
4747
48-
// You can get the `chrono::DateTime` object back from the `String`:
49-
50-
let dt = chrono::DateTime::parse_from_rfc3339(&timestamp).unwrap();
51-
52-
// You can get specific time types back, too:
48+
// You can get the `humantime::Timestamp` object back from the `String`:
5349
use core::str::FromStr;
54-
let dt_utc = chrono::DateTime::<chrono::Utc>::from_str(&timestamp).unwrap();
55-
let dt_local = chrono::DateTime::<chrono::Local>::from_str(&timestamp).unwrap();
56-
println!("local = {}", dt_local);
50+
let timestamp_string = humantime::Timestamp::from_str(&timestamp).unwrap();
5751
5852
// Provenance transfers to the tree sequences
5953
let treeseq = tables.tree_sequence(tskit::TreeSequenceFlags::BUILD_INDEXES).unwrap();
@@ -77,11 +71,9 @@ let record_0 = prov_ref.record(0).unwrap();
7771
assert_eq!(record_0, row_0.record);
7872
let timestamp = prov_ref.timestamp(0).unwrap();
7973
assert_eq!(timestamp, row_0.timestamp);
80-
let dt = chrono::DateTime::parse_from_rfc3339(&timestamp).unwrap();
8174
use core::str::FromStr;
82-
let dt_utc = chrono::DateTime::<chrono::Utc>::from_str(&timestamp).unwrap();
83-
let dt_local = chrono::DateTime::<chrono::Local>::from_str(&timestamp).unwrap();
84-
println!("local = {}", dt_local);
75+
let dt_utc = humantime::Timestamp::from_str(&timestamp).unwrap();
76+
println!("utc = {}", dt_utc);
8577
```
8678
8779
"##

0 commit comments

Comments
 (0)