#!/bin/sh
offWorkTime="19:00:00"
offWorkHour=${offWorkTime:0:2}
offWorkMinute=${offWorkTime:3:2}
offWorkSecond=${offWorkTime:6:2}
currentTime=`TZ='Asia/Hong_Kong' date +%H:%M:%S`
currentHour=${currentTime:0:2}
currentMinute=${currentTime:3:2}
currentSecond=${currentTime:6:2}
second=$((offWorkSecond - currentSecond))
if [[ $second -lt 0 ]]
then
second=$((second + 60))
offWorkMinute=$((offWorkMinute - 1))
if [[ $offWorkMinute -lt 0 ]]
then
offWorkMinute=$((offWorkMinute + 60))
offWorkHour=$((offWorkHour - 1))
fi
fi
minute=$((offWorkMinute - currentMinute))
if [[ $minute -lt 0 ]]
then
minute=$((minute + 60))
offWorkHour=$((offWorkHour - 1))
fi
hour=$((offWorkHour - currentHour))
while true
do
second=$((second - 1))
if [[ $second -lt 0 ]]
then
second=$((second + 60))
minute=$((minute - 1))
if [[ $minute -lt 0 ]]
then
minute=$((minute + 60))
hour=$((hour - 1))
fi
fi
if [[ $second -lt 10 ]]
then
secondStr="0$second"
else
secondStr="$second"
fi
if [[ $minute -lt 10 ]]
then
minuteStr="0$minute"
else
minuteStr="$minute"
fi
if [[ $hour -lt 10 ]]
then
hourStr="0$hour"
else
hourStr="$hour"
fi
tput cup 0 0
tput civis
echo $(tput setaf 1; tput setab 6; tput bold)"offworkTime: $hourStr:$minuteStr:$secondStr"$(tput sgr0)
if [[ $hour -eq 0 && $minute -eq 0 && $second -eq 0 ]]
then
break
fi
sleep 1s
done