summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2022-09-18 13:59:36 +0200
committerMatthias Beyer <mail@beyermatthias.de>2022-09-18 14:03:07 +0200
commit6280fd9a3a783450a6f3f601ded6fa947b58d746 (patch)
treef02b130c40b4b1a7da2d9f1654fbd333379e3c06
parent24e61b01728b5807f30d0dd10a514672fb9c3acf (diff)
Fix: Change filename timestamp format
The fragment files need to be stored with a filename that does not contain a colon (":") character, because cargo cannot package these files. Hence, we alter the filename format in this patch to not contain this character. The subsecond part is added to avoid collisions in high-volume projects (most likely not gonna happen, but you'll never know!). Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--Cargo.lock7
-rw-r--r--Cargo.toml2
-rw-r--r--src/command/new_command.rs9
3 files changed, 15 insertions, 3 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 5c55c9a..b05c6e3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1110,9 +1110,16 @@ dependencies = [
"itoa",
"libc",
"num_threads",
+ "time-macros",
]
[[package]]
+name = "time-macros"
+version = "0.2.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "42657b1a6f4d817cda8e7a0ace261fe0cc946cf3a80314390b22cc61ae080792"
+
+[[package]]
name = "tinyvec"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index c0dee3e..0283434 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -20,7 +20,7 @@ serde = { version = "1", features = [ "derive" ] }
serde_json = "1"
serde_yaml = "0.9.13"
thiserror = "1.0.35"
-time = { version = "0.3.14", features = [ "formatting" ] }
+time = { version = "0.3.14", features = [ "formatting", "macros" ] }
toml = "0.5.9"
typed-builder = "0.10.0"
walkdir = "2.3.2"
diff --git a/src/command/new_command.rs b/src/command/new_command.rs
index 2599572..9981aa1 100644
--- a/src/command/new_command.rs
+++ b/src/command/new_command.rs
@@ -39,8 +39,13 @@ impl crate::command::Command for NewCommand {
let new_file_name = format!(
"{ts}.md",
ts = {
- time::OffsetDateTime::now_utc()
- .format(&time::format_description::well_known::Iso8601::DEFAULT)?
+ // We cannot use the well-known formats here, because cargo cannot package
+ // filenames with ":" in it, but the well-known formats contain this character.
+ // Hence we have to use our own.
+ let fragment_file_timestamp_format = time::macros::format_description!(
+ "[year]-[month]-[day]T[hour]_[minute]_[second]_[subsecond]"
+ );
+ time::OffsetDateTime::now_utc().format(&fragment_file_timestamp_format)?
},
);
unreleased_dir_path.join(new_file_name)