From 11bfbff8c9a91a5410cdf9d01dcd73023b4ea7f5 Mon Sep 17 00:00:00 2001 From: aln730 Date: Fri, 20 Mar 2026 16:49:49 -0400 Subject: [PATCH 1/2] cleaned up a fucntion because it gave me a stroke everytime --- src/main.rs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5e73c56..4f84eed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,19 +12,12 @@ fn get_volume() -> &'static str { let hour = now.hour(); let weekday = now.weekday(); - if weekday == Weekday::Sun { - if !(1..7).contains(&hour) && 23 >= hour { - return "100"; - } - } else if weekday == Weekday::Sat { - if !(1..7).contains(&hour) { - return "100"; - } - } else if (7..=23).contains(&hour) { - return "100"; - } + let not_quiet_hours = match weekday { + Weekday::Sat | Weekday::Sun => !(1..7).contains(&hour), + _ => (7..=23).contains(&hour), + }; - "73" + if not_quiet_hours {"100"} else {"73"} } fn play_music(path: &str, do_cap: bool) -> Result<(), ExitStatus> { From dd59d3cccb3d33f955b1b9f5ac768100245d5da6 Mon Sep 17 00:00:00 2001 From: aln730 Date: Thu, 26 Mar 2026 11:28:29 -0400 Subject: [PATCH 2/2] corrected my logic for sunday --- src/main.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4f84eed..0b83b89 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,16 +8,28 @@ use std::process::{Command, ExitStatus}; use std::time::Duration; fn get_volume() -> &'static str { - let now = Local::now(); let hour = now.hour(); let weekday = now.weekday(); - let not_quiet_hours = match weekday { - Weekday::Sat | Weekday::Sun => !(1..7).contains(&hour), - _ => (7..=23).contains(&hour), + let is_quiet_hours = match (weekday, hour) { + // Entering a weekend, quiet hours till 1 AM the following day + (WeekDay::Fri, 0..7) => true, + // In the weekend, quiet hours are from 1 AM - 7 AM + (WeekDay::Sat, 1..7) => true, + // In the weekend, 1 AM - 7 AM. It's a schoolnight though, + // quiet hours start at 11 PM + (WeekDay::Sun, 1..7) | (WeekDay::Sun, 23..) => true, + // Weekday normal quiet hours. Till 7 AM, then starting at 11 PM + (Weekday::Mon | Weekday::Tue | Weekday::Wed | Weekday::Thu, 0..7) + | (Weekday::Mon | Weekday::Tue | Weekday::Wed | Weekday::Thu, 23..) => true, + _ => false, }; + if is_quiet_hours { + "73" + } else { + "100" + } - if not_quiet_hours {"100"} else {"73"} } fn play_music(path: &str, do_cap: bool) -> Result<(), ExitStatus> {