lib/rufus/sc/rtime.rb in rufus-scheduler-2.0.4 vs lib/rufus/sc/rtime.rb in rufus-scheduler-2.0.5

- old
+ new

@@ -78,10 +78,12 @@ def Rufus.current_time_millis (Time.new.to_f * 1000).to_i end + FLOAT_DURATION = /^\d*\.\d*$/ + # Turns a string like '1m10s' into a float like '70.0', more formally, # turns a time duration expressed as a string into a Float instance # (millisecond count). # # w -> week @@ -93,16 +95,19 @@ # y -> year # 'nada' -> millisecond # # Some examples : # + # Rufus.parse_time_string "0.5" # => 0.5 # Rufus.parse_time_string "500" # => 0.5 # Rufus.parse_time_string "1000" # => 1.0 # Rufus.parse_time_string "1h" # => 3600.0 # Rufus.parse_time_string "1h10s" # => 3610.0 # Rufus.parse_time_string "1w2d" # => 777600.0 # def Rufus.parse_time_string (string) + + return string.to_f if FLOAT_DURATION.match(string) string = string.strip index = -1 result = 0.0