Skip to content

Replace humantime with chrono #728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions Cargo.lock

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

7 changes: 2 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ codegen-units=1
thiserror = "1.0"
libc = "0.2.155"
streaming-iterator = "0.1.5"
humantime = {version = "2.1.0", optional = true}
serde = {version = "1.0.203", features = ["derive"], optional = true}
serde_json = {version = "1.0.120", optional = true}
bincode = {version = "1.3.1", optional = true}
tskit-derive = {version = "0.2.0", path = "tskit-derive", optional = true}
chrono = { version = "0.4.40", default-features = false, features = ["now", "std"] , optional = true}

[dev-dependencies]
anyhow = {version = "1.0.86"}
Expand All @@ -38,9 +38,6 @@ serde_json = {version = "1.0.120"}
bincode = "1.3.1"
rand = "0.8.3"
rand_distr = "0.4.0"
humantime = {version = "2.1.0"}
# chrono is out (for now) due to security issues
# chrono = "0.4.19"

[build-dependencies]
bindgen = "0.69.4"
Expand All @@ -49,7 +46,7 @@ pkg-config = "0.3"

[features]
bindings = []
provenance = ["humantime"]
provenance = ["chrono"]
derive = ["tskit-derive", "serde", "serde_json", "bincode"]

[package.metadata.docs.rs]
Expand Down
2 changes: 1 addition & 1 deletion src/sys/provenance_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl ProvenanceTable {
"empty provenance record".to_owned(),
));
}
let timestamp = humantime::format_rfc3339(std::time::SystemTime::now()).to_string();
let timestamp = chrono::Utc::now().to_string();
let rv = unsafe {
tsk_provenance_table_add_row(
self.as_mut(),
Expand Down
6 changes: 3 additions & 3 deletions src/table_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ impl TableCollection {
/// specification.
/// This formatting approach has been the most straightforward method
/// for supporting round trips to/from a [`crate::provenance::ProvenanceTable`].
/// The implementations used here use the [`humantime`](https://docs.rs/humantime/latest/humantime/) crate.
/// The implementations used here use the [`chrono`](https://docs.rs/chrono/latest/chrono/) crate.
///
/// # Parameters
///
Expand Down Expand Up @@ -1076,9 +1076,9 @@ impl TableCollection {
/// let timestamp = prov_ref.timestamp(0).unwrap();
/// assert_eq!(timestamp, row_0.timestamp);
///
/// // You can get the `humantime::Timestamp` object back from the `String`:
/// // You can get the `chrono` object back from the `String`:
/// use core::str::FromStr;
/// let timestamp_string = humantime::Timestamp::from_str(&timestamp).unwrap();
/// let timestamp_string = chrono::DateTime::<chrono::Utc>::from_str(&timestamp).unwrap();
///
/// // Provenance transfers to the tree sequences
/// let treeseq = tables.tree_sequence(tskit::TreeSequenceFlags::BUILD_INDEXES).unwrap();
Expand Down
6 changes: 3 additions & 3 deletions src/trees/treeseq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ impl TreeSequence {
/// specification.
/// This formatting approach has been the most straightforward method
/// for supporting round trips to/from a [`crate::provenance::ProvenanceTable`].
/// The implementations used here use the [`humantime`](https://docs.rs/humantime/latest/humantime/) crate.
/// The implementations used here use the [`chrono`](https://docs.rs/chrono/latest/chrono/) crate.
///
/// # Parameters
///
Expand All @@ -453,7 +453,7 @@ impl TreeSequence {
/// let timestamp = prov_ref.timestamp(0).unwrap();
/// assert_eq!(timestamp, row_0.timestamp);
/// use core::str::FromStr;
/// let dt_utc = humantime::Timestamp::from_str(&timestamp).unwrap();
/// let dt_utc = chrono::DateTime::<chrono::Utc>::from_str(&timestamp).unwrap();
/// println!("utc = {}", dt_utc);
/// # }
/// ```
Expand All @@ -464,7 +464,7 @@ impl TreeSequence {
expected: "provenance record".to_string(),
});
}
let timestamp = humantime::format_rfc3339(std::time::SystemTime::now()).to_string();
let timestamp = chrono::Utc::now().to_string();
let rv = unsafe {
ll_bindings::tsk_provenance_table_add_row(
&mut (*self.inner.as_ref().tables).provenances,
Expand Down
Loading