Please review pull request #655: (#7639) Assume unspecified time components are zero opened by (seanmil)

Description:

If you abbreviate the time in a range the expected behavior would
be to assume the unspecified components are zero, but Puppet has
traditionally used the current time value instead. This changes
the behavior so that a time range of "10-11" will always translate
to "10:00:00 - 11:00:00".

  • Opened: Wed Apr 11 21:21:29 UTC 2012
  • Based on: puppetlabs:master (42c8526aca72a4205358f8e8fdab20f48417106b)
  • Requested merge: seanmil:schedule/bug/7639-abbreviated_ranges (89e7196761e66c24f5a493aa882904e631f643eb)

Diff follows:

diff --git a/lib/puppet/type/schedule.rb b/lib/puppet/type/schedule.rb
index 89c8aaa..120d58f 100755
--- a/lib/puppet/type/schedule.rb
+++ b/lib/puppet/type/schedule.rb
@@ -139,13 +139,13 @@ def match?(previous, now)
             if range[1]
               ary << range[1]
             else
-              ary << now.min
+              ary << 0
             end
 
             if range[2]
               ary << range[2]
             else
-              ary << now.sec
+              ary << 0
             end
 
             time = Time.local(*ary)
diff --git a/spec/unit/type/schedule_spec.rb b/spec/unit/type/schedule_spec.rb
index 5b06a97..845e1a7 100755
--- a/spec/unit/type/schedule_spec.rb
+++ b/spec/unit/type/schedule_spec.rb
@@ -106,6 +106,27 @@ def min(method, count)
     end
   end
 
+  describe Puppet::Type.type(:schedule), "when matching ranges with abbreviated time specifications" do
+    before do
+      Time.stubs(:now).returns(Time.local(2011, "may", 23, 11, 45, 59))
+    end
+
+    it "should match when just an hour is specified" do
+      @schedule[:range] = "11-12"
+      @schedule.must be_match
+    end
+
+    it "should not match when the ending hour is the current hour" do
+      @schedule[:range] = "10-11"
+      @schedule.must_not be_match
+    end
+
+    it "should not match when the ending minute is the current minute" do
+      @schedule[:range] = "10:00 - 11:45"
+      @schedule.must_not be_match
+    end
+  end
+
   describe Puppet::Type.type(:schedule), "when matching ranges spanning days, day 1" do
     before do
       # Test with the current time at a month's end boundary to ensure we are

    

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to