Permalink
Browse files

Add helpers for turning a number into a timestamp

  >> 168.to_time_s('%M:%S')
  => "02:48"

Add useful? for Float, not sure why it wasn't there
  • Loading branch information...
1 parent ffb3ff5 commit 6f2b5205edb9268dac28d9090d1dcf5e02003966 @UnderpantsGnome committed Apr 5, 2007
Showing with 17 additions and 1 deletion.
  1. +2 −1 init.rb
  2. +11 −0 lib/time.rb
  3. +4 −0 lib/useful.rb
View
@@ -1,2 +1,3 @@
require 'core_extensions'
-require 'useful'
+require 'time'
+require 'useful'
View
@@ -0,0 +1,11 @@
+class Fixnum
+ def to_time_s(format='%M:%S')
+ Time.at(self).gmtime.strftime(format)
+ end
+end
+
+class Float
+ def to_time_s(format='%M:%S')
+ Time.at(self).gmtime.strftime(format)
+ end
+end
View
@@ -13,3 +13,7 @@ def useful?
class Fixnum
def useful?; true end
end
+
+class Float
+ def useful?; true end
+end

0 comments on commit 6f2b520

Please sign in to comment.