Skip to content

Commit

Permalink
rm dependence on chrono, replace with time 0.3.11 (chronotope/chrono#499
Browse files Browse the repository at this point in the history
)
  • Loading branch information
cdstanford committed Jul 19, 2022
1 parent 48fa4e7 commit b451969
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 48 deletions.
55 changes: 10 additions & 45 deletions 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 Cargo.toml
Expand Up @@ -7,12 +7,12 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
chrono = "0.4.15"
disjoint-sets = "0.4.2"
rand = "0.8.5"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
structopt = "0.3.21"
time = { version = "0.3.11", features = ["formatting"] }

[lib]
doctest = false
Expand Down
12 changes: 10 additions & 2 deletions src/util.rs
Expand Up @@ -4,14 +4,14 @@
(File I/O, JSON serialization, system time, etc.)
*/

use chrono::offset::Local;
use serde::de::DeserializeOwned;
use serde::ser::Serialize;
use std::fmt::Debug;
use std::fs::{self, File};
use std::io::{self, BufReader, BufWriter, Write};
use std::path::{Path, PathBuf};
use std::time::{Duration, SystemTime};
use time::{format_description, OffsetDateTime};

/*
File I/O
Expand Down Expand Up @@ -134,8 +134,16 @@ pub fn time_since(t: &SystemTime) -> Duration {
}

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

#[test]
Expand Down

0 comments on commit b451969

Please sign in to comment.