Skip to content

Instantly share code, notes, and snippets.

@forkrul
Forked from citrus/git_time_calcultor.rb
Created February 23, 2014 16:09
Show Gist options
  • Save forkrul/9173291 to your computer and use it in GitHub Desktop.
Save forkrul/9173291 to your computer and use it in GitHub Desktop.
#! /usr/bin/env ruby
# encoding: UTF-8
require 'date'
since = ARGV.shift || Date.today
logs = `git log --since="#{since}" --pretty=format:"%H,%ae,%ai"`
all_commits = logs.split("\n").map{|i| i.split(",") }
if all_commits.empty?
puts "No commits found since #{since}"
exit
end
def parse_time(time)
DateTime.parse(time).to_time
end
def get_hours(commits)
t1 = parse_time(commits.first[2])
t2 = parse_time(commits.last[2])
((t1 - t2) / 3600).round(3)
end
def stats_for(label, commits)
indent = " " * (20 - label.length).abs
hours = get_hours(commits)
print "#{indent}#{label}:\t"
print hours
print " hours"
puts
end
stats_for("Total", all_commits)
all_commits.group_by{|i| i[1] }.each do |user, user_commits|
stats_for(user, user_commits)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment