diff options
author | Lars Wirzenius <liw@liw.fi> | 2022-04-15 14:57:37 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2022-04-15 14:57:37 +0000 |
commit | 99e947c92737d72f41ecca4cddf359b3643c11a9 (patch) | |
tree | 36a916b37f5dccf227cb88bd0fb92148a6deb27d /subplotlib/src/steplibrary/files.rs | |
parent | 17976432a1cf3e2c711d18b79af0e3cc135e214a (diff) | |
parent | b51631310c962fb9123d9d362bfbc62ad54730a2 (diff) | |
download | subplot-0.4.0.tar.gz |
Merge branch 'pre-release' into 'main'0.4.0
Prepare 0.4.0 release
See merge request subplot/subplot!270
Diffstat (limited to 'subplotlib/src/steplibrary/files.rs')
-rw-r--r-- | subplotlib/src/steplibrary/files.rs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/subplotlib/src/steplibrary/files.rs b/subplotlib/src/steplibrary/files.rs index 991cd88..1a55f7a 100644 --- a/subplotlib/src/steplibrary/files.rs +++ b/subplotlib/src/steplibrary/files.rs @@ -10,9 +10,10 @@ use std::io::{self, Write}; use std::path::PathBuf; use std::time::{Duration, SystemTime}; -use chrono::{TimeZone, Utc}; use filetime::FileTime; use regex::Regex; +use time::macros::format_description; +use time::OffsetDateTime; pub use crate::prelude::*; @@ -86,8 +87,12 @@ pub fn create_from_embedded_with_other_name( /// If the file does not exist, it will be created. #[step] pub fn touch_with_timestamp(context: &Datadir, filename: &str, mtime: &str) { - let ts = Utc.datetime_from_str(mtime, "%Y-%m-%d %H:%M:%S")?; - let (secs, nanos) = (ts.timestamp(), ts.timestamp_subsec_nanos()); + let fd = format_description!( + "[year]-[month]-[day] [hour]:[minute]:[second] [offset_hour]:[offset_minute]" + ); + let full_time = format!("{} +00:00", mtime); + let ts = OffsetDateTime::parse(&full_time, &fd)?; + let (secs, nanos) = (ts.unix_timestamp(), 0); let mtime = FileTime::from_unix_time(secs, nanos); let full_path = context.canonicalise_filename(filename)?; // If the file doesn't exist, create it |