|
4 | 4 | (File I/O, JSON serialization, system time, etc.)
|
5 | 5 | */
|
6 | 6 |
|
7 |
| -use chrono::offset::Local; |
8 | 7 | use serde::de::DeserializeOwned;
|
9 | 8 | use serde::ser::Serialize;
|
10 | 9 | use std::fmt::Debug;
|
11 | 10 | use std::fs::{self, File};
|
12 | 11 | use std::io::{self, BufReader, BufWriter, Write};
|
13 | 12 | use std::path::{Path, PathBuf};
|
14 | 13 | use std::time::{Duration, SystemTime};
|
| 14 | +use time::{format_description, OffsetDateTime}; |
15 | 15 |
|
16 | 16 | /*
|
17 | 17 | File I/O
|
@@ -134,8 +134,16 @@ pub fn time_since(t: &SystemTime) -> Duration {
|
134 | 134 | }
|
135 | 135 |
|
136 | 136 | // 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. |
137 | 139 | 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() |
139 | 147 | }
|
140 | 148 |
|
141 | 149 | #[test]
|
|
0 commit comments