How to use Google Calendar and Rufus-Google for Basic Time Tracking

Today I’ll share what I use for some of my DIY time-tracking when I do freelancing (sometimes I use other tools, depending on the customer).

Conventions I currently use:
  • one google calendar per customer (I name these “LoGeek CustomerName” to avoid conflicts with other calendars I would have shared with my customer – LoGeek is my company name)
  • event title stores the project name

Code


require 'rufus/gcal'

customer = "LoGeek Acme Company" 

Rufus::Google::Calendar.get_calendars( :account => user_name, :password => password)

calendar = get_calendars[customer]

# don't keep the default (low) :max_results or you'll probably miss events
events = calendar.events( "max_results" => 1000, 
  "start_min" => '2009-09-09T00:00:00',
  "start_max" => '2009-11-25T11:00:00')

events.each do |e|
  duration = (e.end_time - e.start_time)/3600.0
  raise "corrupt event" if duration > 8

  print e.title # project name
  print " - " 
  print e.start_time.strftime(...)
  print e.end_time.strftime(...)
  print " - " 
  print duration
  print " hours" 
  puts

  total += duration
end

Once you have this data, you can either export it as CSV, or reinject it into Prawn or Documatic to create an invoice.

Resources

Known dependencies: Documentation:

Thanks!

Thanks to John Mettraux for creating this useful libraries and many others!

The comments system is brand new - don't be afraid to comment!