Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +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();

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 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,
Comment on lines +23 to +24
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(Weekday::Mon | Weekday::Tue | Weekday::Wed | Weekday::Thu, 0..7)
| (Weekday::Mon | Weekday::Tue | Weekday::Wed | Weekday::Thu, 23..) => true,
(Weekday::Mon | Weekday::Tue | Weekday::Wed | Weekday::Thu, 0..7 | 23..) => true,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meh, I was unsure if patterns for ranges work like that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They do

_ => false,
};
if is_quiet_hours {
"73"
} else {
"100"
}

"73"
}

fn play_music(path: &str, do_cap: bool) -> Result<(), ExitStatus> {
Expand Down