lib/rufus/scheduler/util.rb in rufus-scheduler-3.0.0 vs lib/rufus/scheduler/util.rb in rufus-scheduler-3.0.1
- old
+ new
@@ -131,21 +131,21 @@
# y -> year
# 'nada' -> millisecond
#
# Some examples:
#
- # Rufus::Scheduler.parse_duration_string "0.5" # => 0.5
- # Rufus::Scheduler.parse_duration_string "500" # => 0.5
- # Rufus::Scheduler.parse_duration_string "1000" # => 1.0
- # Rufus::Scheduler.parse_duration_string "1h" # => 3600.0
- # Rufus::Scheduler.parse_duration_string "1h10s" # => 3610.0
- # Rufus::Scheduler.parse_duration_string "1w2d" # => 777600.0
+ # Rufus::Scheduler.parse_duration "0.5" # => 0.5
+ # Rufus::Scheduler.parse_duration "500" # => 0.5
+ # Rufus::Scheduler.parse_duration "1000" # => 1.0
+ # Rufus::Scheduler.parse_duration "1h" # => 3600.0
+ # Rufus::Scheduler.parse_duration "1h10s" # => 3610.0
+ # Rufus::Scheduler.parse_duration "1w2d" # => 777600.0
#
# Negative time strings are OK (Thanks Danny Fullerton):
#
- # Rufus::Scheduler.parse_duration_string "-0.5" # => -0.5
- # Rufus::Scheduler.parse_duration_string "-1h" # => -3600.0
+ # Rufus::Scheduler.parse_duration "-0.5" # => -0.5
+ # Rufus::Scheduler.parse_duration "-1h" # => -3600.0
#
def self.parse_duration(string, opts={})
string = string.to_s
@@ -181,34 +181,41 @@
end
mod * val
end
+ class << self
+ #-
+ # for compatibility with rufus-scheduler 2.x
+ #+
+ alias parse_duration_string parse_duration
+ alias parse_time_string parse_duration
+ end
+
+
# Turns a number of seconds into a a time string
#
- # Rufus.to_duration_string 0 # => '0s'
- # Rufus.to_duration_string 60 # => '1m'
- # Rufus.to_duration_string 3661 # => '1h1m1s'
- # Rufus.to_duration_string 7 * 24 * 3600 # => '1w'
- # Rufus.to_duration_string 30 * 24 * 3600 + 1 # => "4w2d1s"
+ # Rufus.to_duration 0 # => '0s'
+ # Rufus.to_duration 60 # => '1m'
+ # Rufus.to_duration 3661 # => '1h1m1s'
+ # Rufus.to_duration 7 * 24 * 3600 # => '1w'
+ # Rufus.to_duration 30 * 24 * 3600 + 1 # => "4w2d1s"
#
# It goes from seconds to the year. Months are not counted (as they
# are of variable length). Weeks are counted.
#
# For 30 days months to be counted, the second parameter of this
# method can be set to true.
#
- # Rufus.to_time_string 30 * 24 * 3600 + 1, true # => "1M1s"
+ # Rufus.to_duration 30 * 24 * 3600 + 1, true # => "1M1s"
#
- # (to_time_string is an alias for to_duration_string)
- #
# If a Float value is passed, milliseconds will be displayed without
# 'marker'
#
- # Rufus.to_duration_string 0.051 # => "51"
- # Rufus.to_duration_string 7.051 # => "7s51"
- # Rufus.to_duration_string 0.120 + 30 * 24 * 3600 + 1 # => "4w2d1s120"
+ # Rufus.to_duration 0.051 # => "51"
+ # Rufus.to_duration 7.051 # => "7s51"
+ # Rufus.to_duration 0.120 + 30 * 24 * 3600 + 1 # => "4w2d1s120"
#
# (this behaviour mirrors the one found for parse_time_string()).
#
# Options are :
#
@@ -236,11 +243,15 @@
s
end
class << self
+ #-
+ # for compatibility with rufus-scheduler 2.x
+ #+
alias to_duration_string to_duration
+ alias to_time_string to_duration
end
# Turns a number of seconds (integer or Float) into a hash like in :
#
# Rufus.to_duration_hash 0.051
@@ -248,11 +259,10 @@
# Rufus.to_duration_hash 7.051
# # => { :s => 7, :ms => "51" }
# Rufus.to_duration_hash 0.120 + 30 * 24 * 3600 + 1
# # => { :w => 4, :d => 2, :s => 1, :ms => "120" }
#
- # This method is used by to_duration_string (to_time_string) behind
- # the scene.
+ # This method is used by to_duration behind the scenes.
#
# Options are :
#
# * :months, if set to true, months (M) of 30 days will be taken into
# account when building up the result