pomodoro/pomodoro-resume.awk

42 lines
775 B
Awk
Raw Normal View History

2011-11-17 13:56:23 +00:00
#!/usr/bin/awk -f
# number of minutes from str of hh:mm format
function minFromTime(str){
h=str;
m=str;
gsub(/:.*$/,"",h);
gsub(/^.*:/,"",m);
return h*60+m;
}
# take a number of minutes, return a xh xxm format
function timeFromMin(time) {
m=time%60;
h=(time -m )/60;
if (m<10) {
m="0"m;
}
return h"h "m"m";
}
# get the name of the task
function message(){
msg=$6;
for (i=7;i<=NF;i++) {msg=msg" "$i}
return msg;
}
# For each line
{
m=message()
time[m]=time[m]+minFromTime($5)-minFromTime($3);
}
# Print the result
END {
maxlen=0;
for (i in time) {
if (length(i)>maxlen) { maxlen=length(i); } }
2011-11-17 13:56:23 +00:00
for(i in time) {
printf "%-"maxlen"s: %s\n",i,timeFromMin(time[i]);
2011-11-17 13:56:23 +00:00
}
}