Skip to content

Instantly share code, notes, and snippets.

@trauber
Created January 26, 2020 21:28
Show Gist options
  • Save trauber/526edcaf531712068365652810fb019a to your computer and use it in GitHub Desktop.
Save trauber/526edcaf531712068365652810fb019a to your computer and use it in GitHub Desktop.

Processing Timetrap Output for Invoicing

Process and Awk Draft

t display --format csv > tmp.csv

Write tsv file with

#!/data/data/com.termux/files/usr/bin/ruby
require 'csv'

CSV.open(ARGV[0]).each do |r|
  puts r.map{ |c| (c || "").gsub(/\t/,'\\t').gsub(/\n/,'\\n') }.join("\t")
end

Feed tsv to

# Process tsv generated from timetrap.rb display output
# into yaml for use with a LaTeX invoice.
BEGIN {
  FS = "\t"
}


# String manipulations to turn timetrap's dates
# into gawk datespecs and thence into
# seconds since the epoch.
function sste(timestring) {
  gsub("-"," ",timestring)
  gsub(":"," ",timestring)
  timestring=mktime(timestring)
  return timestring / 3600

}

# Calculate duration and 
# round it to precision 1.
function duration(t1,t2) {
  ts1=sste(t1)
  ts2=sste(t2)
  # This printf expression rounds to precision 1
  printf "%.*f", 1, ts2 - ts1
}

{
  if (NR==1) { next }
  tstart=$1
  tend=$2
  note=$3
  duration(tstart,tend)
  print " " note
}


# TODO:
# - roll each record into an array and 
#   use END block to calculate totals
#   as well as iterate through each line

Yet

  • Generate yam for invoices.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment