Skip to content

Instantly share code, notes, and snippets.

@bobanj
Forked from pjb3/time.rake
Created July 8, 2012 06:27
Show Gist options
  • Save bobanj/3069659 to your computer and use it in GitHub Desktop.
Save bobanj/3069659 to your computer and use it in GitHub Desktop.
def format_time_interval(from_time, to_time)
seconds = (to_time - from_time).abs.round
minutes, seconds = seconds.divmod(60)
if minutes > 60 * 24
" "
elsif minutes > 60
hours, minutes =
" %2dh %2dm " % minutes.divmod(60)
else
" %2dm %2ds " % [minutes, seconds]
end
end
desc "Print the commits with the amount of time between each commit"
task :time do
if `git config --list` =~ /^user\.email=(.*)$/
email = $1
else
raise "Could not find your email address in git config"
end
prev_time = Time.now
prev_subject = nil
`git log --author=#{email} --pretty=format:"%ct %s"`.each_line do |l|
if l =~ /^(\d+) (.*)$/
curr_time = Time.at($1.to_i)
if prev_subject
puts "#{prev_time.strftime('%a, %b %d %I:%M%p')} #{format_time_interval(prev_time, curr_time)} #{prev_subject}"
end
prev_subject = $2
prev_time = curr_time
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment