Skip to content

Instantly share code, notes, and snippets.

@whym
Created December 2, 2009 02:56
Show Gist options
  • Select an option

  • Save whym/246889 to your computer and use it in GitHub Desktop.

Select an option

Save whym/246889 to your computer and use it in GitHub Desktop.
calculate the difference between the given time in the argument and the current time
ruby -rtime -e'd=(Time.parse(ARGV.join(%q{ }))-Time.now).to_i; sign=d/d.abs<0?%q{-}:%q{}; d=d.abs; s,m,h=[60,60].map{|x| r=d%x; d=(d-r)/x; r}+[d]; puts sprintf %q!%s%d:%02d:%02d!, sign,h,m,s' # "2010-01-15T23:59 EST"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment