Permalink
Browse files

+ Add ability to provide a date range (default 'to_date' to be today …

…if not provided).

+ If multiple dates returned, show the date on each line item
  • Loading branch information...
1 parent d4ad9f5 commit cf5743835e396d58d45316570e7404f5919a688e Brian Cooke committed Mar 13, 2012
Showing with 29 additions and 9 deletions.
  1. +29 −9 fbtoday.rb
View
@@ -1,20 +1,26 @@
#!/usr/bin/env ruby
-#
require 'freshbooks.rb'
+def parsed_date_or_today(potential_date)
+ date = potential_date
+ if date
+ date = Date.parse(date)
+ else
+ date = Date.today
+ end
+ date
+end
+
+# Main
FreshBooks::Base.establish_connection('roobasoftllc.freshbooks.com', ENV['FBAPI_TOKEN'])
-date = ARGV[0]
-if date
- date = Date.parse(date)
-else
- date = Date.today
-end
+date = parsed_date_or_today(ARGV[0])
+to_date = parsed_date_or_today(ARGV[1])
hours = 0.0
projects = {}
-FreshBooks::TimeEntry.list(:date_from => date, :date_to => date).each do |te|
+FreshBooks::TimeEntry.list(:date_from => date, :date_to => to_date).each do |te|
project_info = projects[te.project_id]
if project_info.nil?
@@ -23,13 +29,27 @@
projects[te.project_id] = project_info
end
+ # check for a project filter.
+ if ENV["PROJECT"] && ENV["PROJECT"] != project_info[:project].name
+ next
+ end
+
hours += te.hours
project_info[:hours] += te.hours
- puts "#{"%04.2f" % te.hours}\t#{project_info[:project].name}\t#{te.notes}"
+
+ STDOUT.write "#{"%04.2f" % te.hours}\t#{project_info[:project].name}\t"
+
+ if date != to_date
+ # different days? show which is where
+ STDOUT.write "#{te.date}\t"
+ end
+
+ puts "#{te.notes}"
end
puts "----"
projects.values.each do |project_info|
+ next unless project_info[:hours] > 0.0
puts "#{"%04.2f" % project_info[:hours]}\t#{project_info[:project].name}"
end

0 comments on commit cf57438

Please sign in to comment.