Compare commits

...

7 Commits

Author SHA1 Message Date
e62e97c06b Fix help 2022-03-31 15:25:34 +02:00
103a003cf0 Fix output 2022-03-31 14:57:05 +02:00
7800235bd1 Adding possible clockout times 2022-03-31 14:56:10 +02:00
f7ebc0409f Improve output again 2022-03-24 14:16:51 +01:00
5a00aee3f2 Improve output 2022-03-24 14:04:07 +01:00
c563ba96f0 Make it more readble 2022-03-24 13:09:14 +01:00
29a306f988 Adding nice Balance at the moment 2022-03-24 13:07:30 +01:00

84
badgy
View File

@ -24,21 +24,52 @@ devalidate()
s2h() s2h()
{ {
local sc=${1} local sc=0
local sign=""
if [ ${1} -lt 0 ]; then
sign="-"
sc=$(echo ${1} | cut -c2-)
else
sc=${1}
fi
local h=$(( sc / 3600)) local h=$(( sc / 3600))
local m=$(( (sc % 3600) / 60 )) local m=$(( (sc % 3600) / 60 ))
local s=$(( sc % 60)) local s=$(( sc % 60))
printf "%dh%02dm" "${h}" "${m}" printf "%s%dh%02dm" "${sign}" "${h}" "${m}"
} }
getNewBalance() getNewBalance()
{ {
local wk=25200 local workDay=25200
local blh=$(echo ${1} | cut -d ':' -f 1) local blh=$(echo ${1} | cut -d ':' -f 1 | cut -c2-)
local blm=$(echo ${1} | cut -d ':' -f 2) local blm=$(echo ${1} | cut -d ':' -f 2)
local bls="" local bls=$((blh*3600 + blm*60))
local nbls="" local nbls=0
echo ${nbls} if [ "${bls}" -le "${workDay}" ]; then
nbls=$((${2}-(workDay - bls)))
else
nbls=$((bls+${2}))
fi
echo $nbls
}
getClockOutTime()
{
local workDay=25200
local dr=${1}
local now=$(date +'%s')
local remaining=$((workDay - dr))
local endingTime=$((now + remaining))
date -d @${endingTime} +'%H:%M'
}
captitalTime2seconds()
{
cph=$(echo "${1}" | awk -F ':' '{gsub("+|-",""); print $1}' )
cpm=$(echo "${1}" | awk -F ':' '{gsub("+|-",""); print $2}' )
sign=${1::1}
echo ${sign}$(( (cphd*3600)+(cpm*60)))
} }
getCapitalTime() getCapitalTime()
@ -47,31 +78,40 @@ getCapitalTime()
clocks=$(echo ${data} | jq -rc ".timers[]") clocks=$(echo ${data} | jq -rc ".timers[]")
sl=$(echo ${data} | jq -rc ".capitaltime") sl=$(echo ${data} | jq -rc ".capitaltime")
dr=0 dr=0
echo "Timers:" echo "Timers :"
for cl in ${clocks} for cl in ${clocks}
do do
starts=$(echo ${cl} | jq -rc ".start") starts=$(echo ${cl} | jq -rc ".start")
st=$(date --date="${starts}" +'%s') st=$(date --date="${starts}" +'%s')
ends=$(echo ${cl} | jq -rc ".end") ends=$(echo ${cl} | jq -rc ".end")
echo echo
echo " Start: $(date --date=${starts} +'%A %d %B %Y : %H:%M')" echo -n " $(date --date=${starts} +"%A %d %B %Y") "
echo -n "$(date --date=${starts} +'%H:%M') to "
if [ "${ends}" != "null" ];then if [ "${ends}" != "null" ];then
ed=$(date --date="${ends}" +'%s') ed=$(date --date="${ends}" +'%s')
echo " End: $(date --date=${ends} +'%A %d %B %Y : %H:%M')" echo -n "$(date --date=${ends} +'%H:%M')"
else else
ed=$(date +'%s') ed=$(date +'%s')
echo " End: running" echo -n "....."
fi fi
dr=$(( dr + (ed - st))) timerCount="$((ed - st))"
echo -n " ($(s2h ${timerCount}))"
dr=$(( dr + timerCount))
done done
nbl=$(getNewBalance "${sl}" "${dr}") nbl=$(getNewBalance "${sl}" "${dr}")
balance=$(captitalTime2seconds "${sl}")
clockOutTime=$(getClockOutTime "$((dr+balance))")
echo echo
echo "Your time balance is : ${sl}" echo
echo "Today you worked $(s2h ${dr})" echo "Your time balance is: ${sl}"
#echo "If you validate now your balance will be : ${nbl}" echo
echo "Today you worked: $(s2h ${dr})"
echo
echo "Balance if you validate now : $(s2h ${nbl})"
echo "Clockout time (use balance) : ${clockOutTime}"
echo "Clockout time (keep balance) : $(getClockOutTime "${dr}")"
} }
show() show()
@ -84,11 +124,11 @@ if [ -e "${HOME}/.badgyrc" ]; then
else else
echo "${HOME}/.badgyrc file is missing, I need it" echo "${HOME}/.badgyrc file is missing, I need it"
echo "Create it with this command:" echo "Create it with this command:"
echo " echo 'BADGEURL="https://myninebage" KEY="XXXX-XX-XXX-XXX"' > ${HOME}/.badyrc" echo " echo 'BADGEURL="https://myninebage" KEY="XXXX-XX-XXX-XXX"' > ${HOME}/.badgyrc"
exit 2 exit 2
fi fi
case ${1} in case ${1} in
in|clockin|c) in|clockin|c)
clockin | jq clockin | jq
;; ;;