From 0823ae2a16c42434ee2e9401049dd3fb52eb7d1e Mon Sep 17 00:00:00 2001 From: holly sparkles Date: Tue, 19 Dec 2023 20:59:27 +0100 Subject: [PATCH] feat: add filename formatting --- Cargo.toml | 1 + src/main.rs | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 40ad268..6b8b219 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,4 +6,5 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +chrono = "0.4.31" screenshots = "0.8.6" diff --git a/src/main.rs b/src/main.rs index 3479e0a..28d5875 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +use chrono::{DateTime, Local, Utc}; use screenshots::{image::ImageBuffer, Screen}; fn main() { @@ -39,7 +40,12 @@ fn capture_all() { }); if !img.is_empty() { - match img.save("target/capture.png") { + let filename: DateTime = Utc::now().with_timezone(&Local); + + match img.save(format!( + "target/{}.png", + filename.format("%Y-%m-%d_%H-%M-%S") + )) { Ok(_) => println!("screenshot saved successfully!"), Err(err) => println!("there was an error saving the image: {:?}", err), } -- libgit2 1.7.2