diff options
-rw-r--r-- | lib/chef/provider/windows_task.rb | 18 | ||||
-rw-r--r-- | lib/chef/resource/windows_task.rb | 29 | ||||
-rw-r--r-- | spec/unit/resource/windows_task_spec.rb | 20 |
3 files changed, 27 insertions, 40 deletions
diff --git a/lib/chef/provider/windows_task.rb b/lib/chef/provider/windows_task.rb index 02e45cb9e0..dca0156d9c 100644 --- a/lib/chef/provider/windows_task.rb +++ b/lib/chef/provider/windows_task.rb @@ -229,8 +229,8 @@ class Chef current_resource.frequency_modifier != new_resource.frequency_modifier || current_resource.frequency != new_resource.frequency || current_resource.idle_time != new_resource.idle_time || - current_resource.random_delay != new_resource.random_delay || - !new_resource.execution_time_limit.include?(current_resource.execution_time_limit) || + random_delay_updated? || + execution_time_limit_updated? || (new_resource.start_day && new_resource.start_day != "N/A" && start_day_updated?) || (new_resource.start_time && new_resource.start_time != "N/A" && start_time_updated?) begin @@ -243,6 +243,20 @@ class Chef false end + def random_delay_updated? + return false if current_resource.random_delay.nil? && new_resource.random_delay.nil? + return true if new_resource.random_delay.nil? + current_resource.random_delay = 0 if current_resource.random_delay.nil? + ISO8601::Duration.new(current_resource.random_delay) != ISO8601::Duration.new(new_resource.random_delay) + end + + def execution_time_limit_updated? + return false if current_resource.execution_time_limit.nil? && new_resource.execution_time_limit.nil? + return true if new_resource.execution_time_limit.nil? + current_resource.execution_time_limit = 0 if current_resource.execution_time_limit.nil? + ISO8601::Duration.new(current_resource.execution_time_limit) != ISO8601::Duration.new(new_resource.execution_time_limit) + end + def start_day_updated? current_day = DateTime.strptime(current_resource.start_day, convert_system_date_format_to_ruby_date_format) new_day = parse_day(new_resource.start_day) diff --git a/lib/chef/resource/windows_task.rb b/lib/chef/resource/windows_task.rb index f61a119b5a..5ab5715ccf 100644 --- a/lib/chef/resource/windows_task.rb +++ b/lib/chef/resource/windows_task.rb @@ -209,34 +209,7 @@ class Chef # @see http://tools.ietf.org/html/rfc2445#section-4.3.6 # @param [Integer] seconds The amount of seconds for this duration def sec_to_dur(seconds) - seconds = seconds.to_i - iso_str = "P" - if seconds > 604_800 # more than a week - weeks = seconds / 604_800 - seconds -= (604_800 * weeks) - iso_str << "#{weeks}W" - end - if seconds > 86_400 # more than a day - days = seconds / 86_400 - seconds -= (86_400 * days) - iso_str << "#{days}D" - end - if seconds >= 0 - iso_str << "T" - if seconds > 3600 # more than an hour - hours = seconds / 3600 - seconds -= (3600 * hours) - iso_str << "#{hours}H" - end - if seconds > 60 # more than a minute - minutes = seconds / 60 - seconds -= (60 * minutes) - iso_str << "#{minutes}M" - end - iso_str << "#{seconds}S" - end - - iso_str + dur = seconds.to_i == 0 ? nil : ISO8601::Duration.new(seconds.to_i).to_s end end diff --git a/spec/unit/resource/windows_task_spec.rb b/spec/unit/resource/windows_task_spec.rb index fe0c55ecaf..a40e143a49 100644 --- a/spec/unit/resource/windows_task_spec.rb +++ b/spec/unit/resource/windows_task_spec.rb @@ -281,23 +281,23 @@ 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") + it "return nil when passed 0" do + expect(resource.send(:sec_to_dur, 0)).to eql(nil) end it "return PT1S when passed 1" do expect(resource.send(:sec_to_dur, 1)).to eql("PT1S") end - it "return PT24H0S when passed 86400" do - expect(resource.send(:sec_to_dur, 86400)).to eql("PT24H0S") + it "return PT86400S when passed 86400" do + expect(resource.send(:sec_to_dur, 86400)).to eql("PT86400S") end - it "return P1DT1S when passed 86401" do - expect(resource.send(:sec_to_dur, 86401)).to eql("P1DT1S") + it "return PT86401S when passed 86401" do + expect(resource.send(:sec_to_dur, 86401)).to eql("PT86401S") end - it "return P1DT1M40S when passed 86500" do - expect(resource.send(:sec_to_dur, 86500)).to eql("P1DT1M40S") + it "return PT86500S when passed 86500" do + expect(resource.send(:sec_to_dur, 86500)).to eql("PT86500S") end - it "return P1WT1S when passed 604801" do - expect(resource.send(:sec_to_dur, 604801)).to eql("P1WT1S") + it "return PT604801S when passed 604801" do + expect(resource.send(:sec_to_dur, 604801)).to eql("PT604801S") end end end |