Skip to content

Commit

Permalink
file name format fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rachancheet committed Mar 20, 2024
1 parent 63a89af commit 44b11d7
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 28 deletions.
137 changes: 137 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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"

[[bin]]
name = "wayshot"
Expand Down
2 changes: 1 addition & 1 deletion wayshot/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
30 changes: 4 additions & 26 deletions wayshot/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<LogicalRegion> {
Expand Down Expand Up @@ -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> = 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()
}
2 changes: 1 addition & 1 deletion wayshot/src/wayshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 44b11d7

Please sign in to comment.