🕷 zenspider.com

by ryan davis



sitemap
Looking for the Ruby Quickref?

Reservoir Nerds, pt 2

Published 2009-01-31 @ 11:34

Tagged planning, rails, ruby, rubyhitsquad, thoughts, toys, work

ReservoirNerds.png

  >> require 'time'
  => true
  >> t0 = Time.parse "January 22, 2009 12:05:56 PM"
  => Thu Jan 22 12:05:56 -0800 2009
  >> t1 = Time.parse "January 30, 2009 5:30:48 PM"
  => Fri Jan 30 17:30:48 -0800 2009
  >> t = (t1 - t0).to_i
  => 710692
  >> u = []
  => []
  >> [86400, 3600, 60, 1].inject(t) { |t, n| m = t / n; u << m if m != 0; t % n }
  => 0
  >> puts u.map {|t| '%02d' % t }.join(":").sub(/^0/, '')
  8:05:24:52