Skip to content

Commit 15420ef

Browse files
authored
refactor: use chrono for provenance time stamps (#728)
1 parent b613b87 commit 15420ef

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

Cargo.lock

Lines changed: 10 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ codegen-units=1
2323
thiserror = "1.0"
2424
libc = "0.2.155"
2525
streaming-iterator = "0.1.5"
26-
humantime = {version = "2.1.0", optional = true}
2726
serde = {version = "1.0.203", features = ["derive"], optional = true}
2827
serde_json = {version = "1.0.120", optional = true}
2928
bincode = {version = "1.3.1", optional = true}
3029
tskit-derive = {version = "0.2.0", path = "tskit-derive", optional = true}
30+
chrono = { version = "0.4.40", default-features = false, features = ["now", "std"] , optional = true}
3131

3232
[dev-dependencies]
3333
anyhow = {version = "1.0.86"}
@@ -38,9 +38,6 @@ serde_json = {version = "1.0.120"}
3838
bincode = "1.3.1"
3939
rand = "0.8.3"
4040
rand_distr = "0.4.0"
41-
humantime = {version = "2.1.0"}
42-
# chrono is out (for now) due to security issues
43-
# chrono = "0.4.19"
4441

4542
[build-dependencies]
4643
bindgen = "0.69.4"
@@ -49,7 +46,7 @@ pkg-config = "0.3"
4946

5047
[features]
5148
bindings = []
52-
provenance = ["humantime"]
49+
provenance = ["chrono"]
5350
derive = ["tskit-derive", "serde", "serde_json", "bincode"]
5451

5552
[package.metadata.docs.rs]

src/sys/provenance_table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl ProvenanceTable {
4545
"empty provenance record".to_owned(),
4646
));
4747
}
48-
let timestamp = humantime::format_rfc3339(std::time::SystemTime::now()).to_string();
48+
let timestamp = chrono::Utc::now().to_string();
4949
let rv = unsafe {
5050
tsk_provenance_table_add_row(
5151
self.as_mut(),

src/table_collection.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ impl TableCollection {
10471047
/// specification.
10481048
/// This formatting approach has been the most straightforward method
10491049
/// for supporting round trips to/from a [`crate::provenance::ProvenanceTable`].
1050-
/// The implementations used here use the [`humantime`](https://docs.rs/humantime/latest/humantime/) crate.
1050+
/// The implementations used here use the [`chrono`](https://docs.rs/chrono/latest/chrono/) crate.
10511051
///
10521052
/// # Parameters
10531053
///
@@ -1076,9 +1076,9 @@ impl TableCollection {
10761076
/// let timestamp = prov_ref.timestamp(0).unwrap();
10771077
/// assert_eq!(timestamp, row_0.timestamp);
10781078
///
1079-
/// // You can get the `humantime::Timestamp` object back from the `String`:
1079+
/// // You can get the `chrono` object back from the `String`:
10801080
/// use core::str::FromStr;
1081-
/// let timestamp_string = humantime::Timestamp::from_str(&timestamp).unwrap();
1081+
/// let timestamp_string = chrono::DateTime::<chrono::Utc>::from_str(&timestamp).unwrap();
10821082
///
10831083
/// // Provenance transfers to the tree sequences
10841084
/// let treeseq = tables.tree_sequence(tskit::TreeSequenceFlags::BUILD_INDEXES).unwrap();

src/trees/treeseq.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ impl TreeSequence {
431431
/// specification.
432432
/// This formatting approach has been the most straightforward method
433433
/// for supporting round trips to/from a [`crate::provenance::ProvenanceTable`].
434-
/// The implementations used here use the [`humantime`](https://docs.rs/humantime/latest/humantime/) crate.
434+
/// The implementations used here use the [`chrono`](https://docs.rs/chrono/latest/chrono/) crate.
435435
///
436436
/// # Parameters
437437
///
@@ -453,7 +453,7 @@ impl TreeSequence {
453453
/// let timestamp = prov_ref.timestamp(0).unwrap();
454454
/// assert_eq!(timestamp, row_0.timestamp);
455455
/// use core::str::FromStr;
456-
/// let dt_utc = humantime::Timestamp::from_str(&timestamp).unwrap();
456+
/// let dt_utc = chrono::DateTime::<chrono::Utc>::from_str(&timestamp).unwrap();
457457
/// println!("utc = {}", dt_utc);
458458
/// # }
459459
/// ```
@@ -464,7 +464,7 @@ impl TreeSequence {
464464
expected: "provenance record".to_string(),
465465
});
466466
}
467-
let timestamp = humantime::format_rfc3339(std::time::SystemTime::now()).to_string();
467+
let timestamp = chrono::Utc::now().to_string();
468468
let rv = unsafe {
469469
ll_bindings::tsk_provenance_table_add_row(
470470
&mut (*self.inner.as_ref().tables).provenances,

0 commit comments

Comments
 (0)