diff options
author | Tim Smith <tsmith@chef.io> | 2017-12-08 10:19:59 -0800 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2017-12-08 10:19:59 -0800 |
commit | 973d91ab278529dd859f32c7206deec6600f449c (patch) | |
tree | f5abade41f8dcec940c97bffebfd75f21eaac1d2 | |
parent | db320dc818b36a24b01c267517bd087e8b0a3fb6 (diff) | |
download | chef-973d91ab278529dd859f32c7206deec6600f449c.tar.gz |
Properly handle an ISO8601 duration of 0 seconds
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | lib/chef/resource/windows_task.rb | 3 | ||||
-rw-r--r-- | spec/unit/resource/windows_task_spec.rb | 3 |
2 files changed, 4 insertions, 2 deletions
diff --git a/lib/chef/resource/windows_task.rb b/lib/chef/resource/windows_task.rb index 9fd7db7f53..7d7bd249a8 100644 --- a/lib/chef/resource/windows_task.rb +++ b/lib/chef/resource/windows_task.rb @@ -212,7 +212,6 @@ class Chef # @param [Integer] seconds The amount of seconds for this duration def sec_to_dur(seconds) seconds = seconds.to_i - return if seconds == 0 iso_str = "P" if seconds > 604_800 # more than a week weeks = seconds / 604_800 @@ -224,7 +223,7 @@ class Chef seconds -= (86_400 * days) iso_str << "#{days}D" end - if seconds > 0 + if seconds >= 0 iso_str << "T" if seconds > 3600 # more than an hour hours = seconds / 3600 diff --git a/spec/unit/resource/windows_task_spec.rb b/spec/unit/resource/windows_task_spec.rb index f16e29fd08..62fa6e9064 100644 --- a/spec/unit/resource/windows_task_spec.rb +++ b/spec/unit/resource/windows_task_spec.rb @@ -281,6 +281,9 @@ describe Chef::Resource::WindowsTask do end context "#sec_to_dur" do + it "return PT0S when passed 0" do + expect(resource.send(:sec_to_dur, 0)).to eql("PT0S") + end it "return PT1S when passed 1" do expect(resource.send(:sec_to_dur, 1)).to eql("PT1S") end |