Skip to content

Instantly share code, notes, and snippets.

@eknowles
Created May 13, 2024 14:32
Show Gist options
  • Save eknowles/0e81d1f9328694553360c5d7329bbbd4 to your computer and use it in GitHub Desktop.
Save eknowles/0e81d1f9328694553360c5d7329bbbd4 to your computer and use it in GitHub Desktop.
time_until_date_with_workhours() {
# Check if date is provided
if [ -z "$1" ]; then
echo "Usage: time_until_date_with_workhours <event_name> <event_time>"
return 1
fi
event_name=$1
event_time=$2
# Define colors
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
cyan='\033[0;36m'
reset='\033[0m'
# Convert future date to timestamp
future_timestamp=$(date -j -f "%Y-%m-%d" "$event_time" +%s)
# Get current timestamp
current_timestamp=$(date +%s)
# Calculate time difference
time_difference=$((future_timestamp - current_timestamp))
# Calculate total working days
total_days=$((time_difference / 86400)) # 86400 seconds in a day
total_weeks=$((total_days / 7))
# Calculate remaining days after removing weekends
remaining_days=$((total_days - (total_weeks * 2)))
# Calculate total working hours
total_working_hours=$((remaining_days * 8))
# Output the result
printf "${cyan}%s${reset} \t${red}%d${reset}w ${green}%d${reset}d ${yellow}%d${reset}h\n" "$event_name" "$total_weeks" "$remaining_days" "$total_working_hours"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment