ref: 662804331795230f76a836ce2db230317149d709
dir: /clock/
#!/bin/rc
rfork e
clockfile=$home/lib/clocked_hour
clocktarget=$home/lib/hours
if (test -f .hours)
clocktarget=.hours
fn printstats{
echo CURRENT TIMER
d=`{cat $clockfile}
echo 'desc ' $d(2-)
t=$d(1)
c=`{date -un}
td=`{echo $c - $t | hoc}
echo 'started ' `{date -u $t}
hours=`{echo 'int(' $td / 3600 ')' | hoc}
min=`{echo 'int(' $td / 60 ')' | hoc}
sec=`{echo $td % 60 | hoc}
echo 'running '$hours^h $min^m $sec^s
}
flagfmt='b:begin, e:end'
args='description'
if (~ $#* 0 || ! ifs=() eval `{aux/getflags $*}) {
# no args: print info
aux/usage
if (test -f $clockfile) {
printstats
}
exit
}
if (~ $#begin 1 && ~ $#end 1) {
echo '-b and -e are exclusive'
exit 'usage'
}
if (~ $#begin 1) {
if (test -f $clockfile) {
printstats
echo '@{rm' $"clockfile^'}'
exit 'timer running'
}
d=`{date -un}
echo $"d^' '^$"* > $clockfile
exit
}
if (~ $#end 1) {
if (! test -f $clockfile) {
echo 'no timer running'
exit 'no timer'
}
d=`{cat $clockfile}
from=$d(1)
to=`{date -un}
desc=$d(2-)
echo $from^' '^$to^' '^$"desc >> $clocktarget
rm $clockfile
}