Skip to content

Commit

Permalink
round up
Browse files Browse the repository at this point in the history
  • Loading branch information
ipitio committed Jan 26, 2024
1 parent a5f60fc commit 181148e
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions advanced/Scripts/webpage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -634,28 +634,27 @@ generate_systemd_calendar() {
local total_seconds=$(echo "$interval_hours * 3600" | bc)
local freq_entries=()

if (( $(echo "$total_seconds < 60" | bc -l) )); then # seconds
if (( $(echo "$total_seconds < 60" | bc -l) )); then # less than a minute
total_seconds=60
fi
if (( $(echo "$total_seconds >= 60 && $total_seconds < 3600" | bc -l) )); then # less than an hour
local minute_interval=$(echo "$total_seconds / 60" | bc)
freq_entries+=("*-*-* *:00/$minute_interval:00")
elif (( $(echo "$total_seconds == 3600" | bc -l) )); then # an hour
freq_entries+=("*-*-* *:00:00")
elif (( $(echo "86400 % $total_seconds == 0" | bc -l) )); then # factors of a day
local hour_interval=$(echo "$total_seconds / 3600" | bc)
freq_entries+=("*-*-* 00/$hour_interval:00:00")
elif (( $(echo "$total_seconds < 86400" | bc -l) )); then # less than a day
local current_second=0
while (( $(echo "$current_second < 86400" | bc -l) )); do
local hour=$(echo "$current_second / 3600" | bc)
local minute=$(echo "($current_second % 3600) / 60" | bc)
local second=$(echo "$current_second % 60" | bc)

hour=${hour%.*}
minute=${minute%.*}
second=${second%.*}

freq_entries+=("*-*-* $(printf "%02d:%02d:%02d" $hour $minute $second)")
freq_entries+=("*-*-* $(printf "%02d:%02d:00" $hour $minute)")
current_second=$(echo "$current_second + $total_seconds" | bc)
done
elif (( $(echo "$total_seconds >= 60 && $total_seconds < 3600" | bc -l) )); then # minutes
local minute_interval=$(echo "$total_seconds / 60" | bc)
freq_entries+=("*-*-* *:00/$minute_interval:00")
elif (( $(echo "$total_seconds == 3600" | bc -l) )); then # an hour
freq_entries+=("*-*-* *:00:00")
elif (( $(echo "86400 % $total_seconds == 0" | bc -l) )); then # factors of a day
local hour_interval=$(echo "$total_seconds / 3600" | bc)
freq_entries+=("*-*-* 00/$hour_interval:00:00")
else # days
local full_days=$(echo "$interval_hours / 24" | bc)
local remaining_hours=$(echo "$interval_hours - ($full_days * 24)" | bc)
Expand Down

0 comments on commit 181148e

Please sign in to comment.