diff --git a/Cargo.lock b/Cargo.lock index 9244fa4d..7fbfc95a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,6 +8,21 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anstream" version = "0.6.11" @@ -74,6 +89,12 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +[[package]] +name = "bumpalo" +version = "3.15.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ff69b9dd49fd426c69a0db9fc04dd934cdb6645ff000864d98f7e2af8830eaa" + [[package]] name = "bytemuck" version = "1.14.0" @@ -101,6 +122,20 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eaf5903dcbc0a39312feb77df2ff4c76387d591b9fc7b04a238dcf8bb62639a" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-targets 0.52.0", +] + [[package]] name = "clap" version = "4.4.18" @@ -166,6 +201,12 @@ dependencies = [ "windows-sys 0.45.0", ] +[[package]] +name = "core-foundation-sys" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" + [[package]] name = "crc32fast" version = "1.3.2" @@ -270,6 +311,29 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +[[package]] +name = "iana-time-zone" +version = "0.1.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "image" version = "0.24.7" @@ -298,6 +362,15 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc0000e42512c92e31c2252315bda326620a4e034105e900c98ec492fa077b3e" +[[package]] +name = "js-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -712,6 +785,60 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "wasm-bindgen" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" + [[package]] name = "wayland-backend" version = "0.3.2" @@ -789,6 +916,7 @@ dependencies = [ name = "wayshot" version = "1.3.2-dev" dependencies = [ + "chrono", "clap", "dialoguer", "eyre", @@ -821,6 +949,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.0", +] + [[package]] name = "windows-sys" version = "0.45.0" diff --git a/wayshot/Cargo.toml b/wayshot/Cargo.toml index 4594d0b4..99752194 100644 --- a/wayshot/Cargo.toml +++ b/wayshot/Cargo.toml @@ -32,6 +32,7 @@ image = { version = "0.24", default-features = false, features = [ dialoguer = { version = "0.11.0", features = ["fuzzy-select"] } eyre = "0.6.8" +chrono = "0.4.35" [[bin]] name = "wayshot" diff --git a/wayshot/src/cli.rs b/wayshot/src/cli.rs index 13496968..749c4801 100644 --- a/wayshot/src/cli.rs +++ b/wayshot/src/cli.rs @@ -46,5 +46,5 @@ pub struct Cli { /// Uses time stamp(%H:%M:%S) as file name #[arg(short, long)] - pub time_stamp: bool, + pub timestamp: bool, } diff --git a/wayshot/src/utils.rs b/wayshot/src/utils.rs index 79188171..b11993de 100644 --- a/wayshot/src/utils.rs +++ b/wayshot/src/utils.rs @@ -8,6 +8,7 @@ use std::{ time::{SystemTime, UNIX_EPOCH}, }; +use chrono::{DateTime, Local}; use libwayshot::region::{LogicalRegion, Position, Region, Size}; pub fn parse_geometry(g: &str) -> Result { @@ -142,32 +143,9 @@ pub fn get_default_file_name(extension: EncodingFormat) -> PathBuf { format!("wayshot-{time}.{extension}").into() } -fn get_hour_minute_from_unix_seconds(seconds: u64) -> String { - let total_minutes = seconds / 60; - let mut current_hour = (((total_minutes / 60) % 24) + 5) % 24; - let mut current_minute = (total_minutes % 60) + 30; - - if current_minute > 60 { - current_hour += 1; - } - - current_minute = current_minute % 60; - - if current_hour == 24 { - current_hour = 0; - } - - format!("{}:{}:{}", current_hour, current_minute, seconds % 60) -} - pub fn get_time_stamp_file_name(extension: EncodingFormat) -> PathBuf { - let time = match SystemTime::now().duration_since(UNIX_EPOCH) { - Ok(n) => get_hour_minute_from_unix_seconds(n.as_secs()), - Err(_) => { - tracing::error!("SystemTime before UNIX EPOCH!"); - String::from("") - } - }; + let current_datetime: DateTime = Local::now(); + let formated_time = format!("{}", current_datetime.format("%Y_%m_%d-%H_%M_%S")); - format!("wayshot-{time}.{extension}").into() + format!("wayshot-{formated_time}.{extension}").into() } diff --git a/wayshot/src/wayshot.rs b/wayshot/src/wayshot.rs index 3979ab2e..bdee6917 100644 --- a/wayshot/src/wayshot.rs +++ b/wayshot/src/wayshot.rs @@ -61,7 +61,7 @@ fn main() -> Result<()> { } } None => { - if cli.time_stamp { + if cli.timestamp { Some(utils::get_time_stamp_file_name(requested_encoding)) } else { Some(utils::get_default_file_name(requested_encoding))