13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'puppet/modules/wmflib/lib/puppet/parser/functions/to_milliseconds.rb', line 13
newfunction(:to_milliseconds, :type => :rvalue, :arity => 1) do |args|
time_spec = args.first
/^([0-9.+e]+)\s*(.*).?$/ =~ time_spec.downcase
count, unit = $1, $2
factor = case unit
when /^n/ then 1.0e-6 when /^u/ then 1.0e-3 when /^(ms|mil)/ then 1.0 when /^s/ then 1.0e3 when /^(m|min)/ then 6.0e4 when /^h/ then 3.6e6 when /^d/ then 8.64e7 when /^w/ then 6.048e8 when /^mo/ then 2.62974e9 when /^y/ then 3.15569e10 else fail(ArgumentError, "to_milliseconds(): Invalid time spec #{time_spec.inspect}")
end
ms = factor * Float(count)
ms.to_i == ms ? ms.to_i : ms
end
|