summaryrefslogtreecommitdiff
path: root/ar/.local/bin/schedule
blob: c339e2bd130299fd1422340574f9c6762f2dba0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/sh

if [ -z "$1" ]; then
  echo "Usage: ${0##*/} <date-string>"
  echo " Example: ${0##*/} 'tomorrow 06:00'"
  exit 2
fi

set -e

# Calculate the seconds until the given date
secsUntil=$(expr "$(date +%s -d "$*")" - "$(date +%s)")

# Calculate minutes and hours
minutesUntil=$(echo "scale=1; $secsUntil/60" | bc)
hoursUntil=$(echo "scale=2; $secsUntil/3600" | bc)

# Get the formatted date
date=$(date -d "$*")

# Display the result
echo "$hoursUntil hours (or $minutesUntil mins) until $date"