ref: 6b869d76700a730cc9a2dc2b1c40375141d30b58
author: sirjofri <sirjofri@sirjofri.de>
date: Fri Nov 7 05:23:12 EST 2025
adds files
--- /dev/null
+++ b/clock
@@ -1,0 +1,63 @@
+#!/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
+}
--- /dev/null
+++ b/hours.awk
@@ -1,0 +1,45 @@
+#!/bin/awk -f
+
+function gettime(time) {+ hours = int(time / 3600)
+ minute = int(time / 60)
+ sec = int(time % 60)
+ return sprintf("%dh %dm %ds", hours, minute, sec);+}
+
+BEGIN {+ FS="\t";
+ sum=0;
+
+ # print report table header tbl(1)
+ printf ".TS\nbox expand;\n";
+ printf "c c c c\n";
+ printf "- s s s\n";
+ printf "l l r l.\n";
+ printf "From\tTo\tTime\tDescription\n";
+ printf "\n";
+}
+
+$1 && $2 && $3 && !/^#/ {+ cmd = "date -f 'DD.MM.YYYY hh:mm:ss' "$1
+ cmd | getline from
+ close(cmd)
+ cmd = "date -f 'DD.MM.YYYY hh:mm:ss' "$2
+ cmd | getline to
+ close(cmd)
+ time = $2 - $1
+ $1 = $2 = ""
+ sub(/^ +/, "")
+ sub(/ +$/, "")
+ printf "%s\t%s\t%s\t%s\n", from, to, gettime(time), $0;
+ sum += time;
+}
+
+END {+ printf ".T&\n";
+ printf "- s s s\n";
+ printf "l r r c.\n";
+ printf "\n";
+ printf "\tSum\t%s\t\n", gettime(sum);
+ printf ".TE\n";
+}
--- /dev/null
+++ b/mkfile
@@ -1,0 +1,11 @@
+default:V:
+ echo 'Use mk install'
+
+files=hours.awk report clock
+
+install:V: ${files:%=$home/bin/rc/hours/%}+
+$home/bin/rc/hours/%: %
+ if(! test -d $home/bin/rc/hours)
+ mkdir $home/bin/rc/hours
+ cp $prereq $target
--- /dev/null
+++ b/report
@@ -1,0 +1,13 @@
+#!/bin/rc
+
+rfork e
+clockfile=$home/lib/hours
+test -r .hours && clockfile=.hours
+
+{+echo '.SH
+Report
+.R'
+
+hours/hours.awk <$clockfile
+} | tbl | troff -ms
--
⑨