Skip to content

Commit b451969

Browse files
committed
rm dependence on chrono, replace with time 0.3.11 (chronotope/chrono#499)
1 parent 48fa4e7 commit b451969

File tree

3 files changed

+21
-48
lines changed

3 files changed

+21
-48
lines changed

Cargo.lock

+10-45
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ edition = "2018"
77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[dependencies]
10-
chrono = "0.4.15"
1110
disjoint-sets = "0.4.2"
1211
rand = "0.8.5"
1312
serde = { version = "1.0", features = ["derive"] }
1413
serde_json = "1.0"
1514
structopt = "0.3.21"
15+
time = { version = "0.3.11", features = ["formatting"] }
1616

1717
[lib]
1818
doctest = false

src/util.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
(File I/O, JSON serialization, system time, etc.)
55
*/
66

7-
use chrono::offset::Local;
87
use serde::de::DeserializeOwned;
98
use serde::ser::Serialize;
109
use std::fmt::Debug;
1110
use std::fs::{self, File};
1211
use std::io::{self, BufReader, BufWriter, Write};
1312
use std::path::{Path, PathBuf};
1413
use std::time::{Duration, SystemTime};
14+
use time::{format_description, OffsetDateTime};
1515

1616
/*
1717
File I/O
@@ -134,8 +134,16 @@ pub fn time_since(t: &SystemTime) -> Duration {
134134
}
135135

136136
// Current datetime for use in file names
137+
// Note: removed dependence on chrono on 2022-07-19; as a result,
138+
// now this uses time::OffsetDateTime, which is UTC rather than local time.
137139
pub fn current_datetime_str() -> String {
138-
Local::now().format("%Y-%m-%d-%H%M%S").to_string()
140+
let dt: OffsetDateTime = SystemTime::now().into();
141+
let dt_fmt = format_description::parse(
142+
"[year]-[month]-[day]-[hour][minute][second]"
143+
).unwrap();
144+
dt.format(&dt_fmt).unwrap()
145+
// Old implementation using Chrono
146+
// Local::now().format("%Y-%m-%d-%H%M%S").to_string()
139147
}
140148

141149
#[test]

0 commit comments

Comments
 (0)