Module | Rufus |
In: |
lib/rufus/sc/cronline.rb
lib/rufus/sc/jobqueues.rb lib/rufus/sc/jobs.rb lib/rufus/sc/rtime.rb |
require ‘parsedate‘
DURATIONS2M | = | [ [ 'y', 365 * 24 * 3600 ], [ 'M', 30 * 24 * 3600 ], [ 'w', 7 * 24 * 3600 ], [ 'd', 24 * 3600 ], [ 'h', 3600 ], [ 'm', 60 ], [ 's', 1 ] |
DURATIONS2 | = | DURATIONS2M.dup |
DURATIONS | = | DURATIONS2M.inject({}) do |r, (k, v)| r[k] = v |
parse_time_string | -> | parse_duration_string |
to_duration_string | -> | to_time_string |
Ensures an ‘at’ value is translated to a float (to be compared with the float coming from time.to_f)
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 d -> day h -> hour m -> minute s -> second M -> month y -> year ‘nada’ -> millisecond
Some examples :
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
Turns a number of seconds (integer or Float) into a hash like in :
Rufus.to_duration_hash 0.051 # => { :ms => "51" } 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.
Options are :
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"
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"
(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"
(this behaviour mirrors the one found for parse_time_string()).
Options are :