Skip to content

Commit

Permalink
feat: added time_stamp flag (#93)
Browse files Browse the repository at this point in the history
* feat: added time_stamp flag

* Syntax Refactor and filename format fixed

* file name format fixes

* wayshot-{timestamp}.{extension} as default filename

* chore: Update Cargo.lock

Signed-off-by: Shinyzenith <[email protected]>

---------

Signed-off-by: Shinyzenith <[email protected]>
Authored-by: rachancheet <[email protected]>
Co-authored-by: Shinyzenith <[email protected]>
  • Loading branch information
rachancheet and Shinyzenith authored Mar 23, 2024
1 parent f7f134f commit 5370c08
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
1 change: 1 addition & 0 deletions wayshot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

wl-clipboard-rs = "0.8.0"
nix = { version = "0.28.0", features = ["process"] }
Expand Down
16 changes: 5 additions & 11 deletions wayshot/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
use clap::ValueEnum;
use eyre::{bail, ContextCompat, Error, Result};

use std::{
fmt::Display,
path::PathBuf,
str::FromStr,
time::{SystemTime, UNIX_EPOCH},
};
use std::{fmt::Display, path::PathBuf, str::FromStr};

use chrono::{DateTime, Local};
use libwayshot::region::{LogicalRegion, Position, Region, Size};

pub fn parse_geometry(g: &str) -> Result<LogicalRegion> {
Expand Down Expand Up @@ -134,10 +130,8 @@ impl FromStr for EncodingFormat {
}

pub fn get_default_file_name(extension: EncodingFormat) -> PathBuf {
let time = SystemTime::now()
.duration_since(UNIX_EPOCH)
.map(|time| time.as_secs().to_string())
.unwrap_or("unknown".into());
let current_datetime: DateTime<Local> = Local::now();
let formated_time = format!("{}", current_datetime.format("%Y_%m_%d-%H_%M_%S"));

format!("{time}-wayshot.{extension}").into()
format!("wayshot-{formated_time}.{extension}").into()
}

0 comments on commit 5370c08

Please sign in to comment.