X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/f5764a05d616e8d3c55b94503d5a1f789ac66ea7..ab9fdb73256fb57a48aad2161fa022146031f7ca:/services/api/lib/config_loader.rb diff --git a/services/api/lib/config_loader.rb b/services/api/lib/config_loader.rb index 522aa73b0a..f421fb5b2a 100644 --- a/services/api/lib/config_loader.rb +++ b/services/api/lib/config_loader.rb @@ -147,14 +147,14 @@ class ConfigLoader 'Ki' => 1 << 10, 'M' => 1000000, 'Mi' => 1 << 20, - "G" => 1000000000, - "Gi" => 1 << 30, - "T" => 1000000000000, - "Ti" => 1 << 40, - "P" => 1000000000000000, - "Pi" => 1 << 50, - "E" => 1000000000000000000, - "Ei" => 1 << 60, + "G" => 1000000000, + "Gi" => 1 << 30, + "T" => 1000000000000, + "Ti" => 1 << 40, + "P" => 1000000000000000, + "Pi" => 1 << 50, + "E" => 1000000000000000000, + "Ei" => 1 << 60, }[mt[2]] end end @@ -180,8 +180,13 @@ class ConfigLoader end end - def self.parse_duration durstr, cfgkey: - duration_re = /-?(\d+(\.\d+)?)(s|m|h)/ + def self.parse_duration(durstr, cfgkey:) + sign = 1 + if durstr[0] == '-' + durstr = durstr[1..-1] + sign = -1 + end + duration_re = /(\d+(\.\d+)?)(s|m|h)/ dursec = 0 while durstr != "" mt = duration_re.match durstr @@ -189,7 +194,7 @@ class ConfigLoader raise "#{cfgkey} not a valid duration: '#{durstr}', accepted suffixes are s, m, h" end multiplier = {s: 1, m: 60, h: 3600} - dursec += (Float(mt[1]) * multiplier[mt[3].to_sym]) + dursec += (Float(mt[1]) * multiplier[mt[3].to_sym] * sign) durstr = durstr[mt[0].length..-1] end return dursec.seconds