vrinek-periodicity 0.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,16 @@
1
- === 0.1 2009-08-06
1
+ === 0.2.1 -- 2009-08-06
2
2
 
3
- * 1 major enhancement:
4
- * Initial release
3
+ * <b>[FEATURE]</b> Now supports <tt>at('5:20')</tt> kind of precision
4
+
5
+ === 0.2 -- 2009-08-06
6
+
7
+ * <b>[FEATURE]</b> Can use _overnight_ limits (e.g. from 22:00 to 02:00)
8
+ * Removed some duplicate code
9
+
10
+ === 0.1.1 -- 2009-08-06
11
+
12
+ * Can use <tt>.every(:other)</tt> which means <tt>.every(2)</tt>
13
+
14
+ === 0.1 -- 2009-08-06
15
+
16
+ * Initial release
@@ -14,8 +14,8 @@ means: every 2 hours at :20 from 10:00 to 15:00 (10:20, 12:20, 14:20)
14
14
  period.next_run # returns the next calculated time as a Time object
15
15
 
16
16
  Period.new.every(:half).hour # every 30 minutes
17
- Period.every.week # every week
18
- Period.every(5).seconds # every 5 seconds
17
+ Period.new.every.week # every week
18
+ Period.new.every(5).seconds # every 5 seconds
19
19
 
20
20
  == REQUIREMENTS:
21
21
 
@@ -28,4 +28,4 @@ means: every 2 hours at :20 from 10:00 to 15:00 (10:20, 12:20, 14:20)
28
28
 
29
29
  == TODO:
30
30
 
31
- * add <em>sub-sub-time</em> precision to at(time) (e.g. '5:30')
31
+ * add something like "every minute from 20:00 to 21:00 and from 02:00 to 03:00"
@@ -5,5 +5,5 @@ require 'activesupport'
5
5
  require 'periodicity/period'
6
6
 
7
7
  module Periodicity
8
- VERSION = '0.2'
8
+ VERSION = '0.2.1'
9
9
  end
@@ -108,9 +108,15 @@ class Period
108
108
  =begin rdoc
109
109
  Sets a specific "sub-time" for the next_run:
110
110
  every(2).hours.at(15) # means "every 2 hours at the first quarter of each" e.g. 12:15, 14:15, 16:15
111
-
112
- NOTE: when using at and from, to limits together the limits *always* calculate at 0 "sub-time":
111
+
112
+ Specific time within a day is also supported:
113
+ every(3).days.at('5:30') # means "every 3 days at 05:30"
114
+
115
+ <b>NOTE 1:</b> when using at and from, to limits together the limits *always* calculate at 0 "sub-time":
113
116
  every(2).hours.at(15).from(12).to(16) # will return 12:15, 14:15 but not 16:15 because the to limit ends at 16:00
117
+
118
+ <b>NOTE 2:</b> when using minute precision (5:30) but instead of every.day the interval is in another period, the minutes will be discarded.
119
+ every.hour.at('5:30') # means "every hour at :05" (e.g. 12:05, 13:05, 14:05)
114
120
  =end
115
121
  def at(time)
116
122
  unless time.is_a?(Integer)
@@ -118,7 +124,8 @@ class Period
118
124
  when /^\d+:00$/
119
125
  time[/^\d+/].to_i
120
126
  when /^\d+:\d{2}$/
121
- raise 'Precise timing like "20:15" is not yet supported'
127
+ @min_at = time.split(/:/)[1].to_i
128
+ time.split(/:/)[0].to_i
122
129
  when /^(noon|afternoon|midnight|morning)$/
123
130
  DAY_PERIODS[time.to_s]
124
131
  else
@@ -175,7 +182,13 @@ class Period
175
182
  end
176
183
 
177
184
  def calc_precision(scope = nil)
178
- @at = 0 if scope
185
+ if scope
186
+ @at = if @min_at and scope == 1.hour
187
+ @min_at
188
+ else
189
+ 0
190
+ end
191
+ end
179
192
 
180
193
  if down = downtime(scope || @scope)
181
194
  unless now(down) == @at
@@ -36,7 +36,14 @@ describe Period do
36
36
  period.every.day.at('5:00').next_run.should == "Aug 06 05:00:00 2009".to_time
37
37
  period.every.day.at('05:00').next_run.should == "Aug 06 05:00:00 2009".to_time
38
38
 
39
- lambda {period.every.day.at('05:30').next_run}.should raise_error # not yet implemented
39
+ (n = period.every.day.at('05:30').next_run).should == "Aug 06 05:30:00 2009".to_time
40
+ (n = Period.new(n).every.day.at('05:30').next_run).should == "Aug 07 05:30:00 2009".to_time
41
+ (n = Period.new(n).every.day.at('05:30').next_run).should == "Aug 08 05:30:00 2009".to_time
42
+
43
+ (n = period.every(2).days.from(12).to(17).at('05:30').next_run).should == "Aug 12 05:30:00 2009".to_time
44
+ (n = Period.new(n).every(2).days.from(12).to(17).at('05:30').next_run).should == "Aug 14 05:30:00 2009".to_time
45
+ (n = Period.new(n).every(2).days.from(12).to(17).at('05:30').next_run).should == "Aug 16 05:30:00 2009".to_time
46
+ (n = Period.new(n).every(2).days.from(12).to(17).at('05:30').next_run).should == "Sep 12 05:30:00 2009".to_time
40
47
  end
41
48
 
42
49
  it "should return correct time with precision" do
@@ -131,12 +138,9 @@ describe Period do
131
138
  (n = Period.new(n).every.every(5).minutes.at(30).from(40).to(10).next_run).should == "Aug 05 15:50:30 2009".to_time
132
139
  end
133
140
 
134
- it "should avoid some pitfalls" do
141
+ it "should avoid some obvious pitfalls" do
135
142
  Period.new("Aug 05 14:41:23 2009".to_time).every.hour.at(40).next_run.should == "Aug 05 15:40:00 2009".to_time
136
143
  Period.new("Aug 05 14:39:23 2009".to_time).every.hour.at(40).next_run.should == "Aug 05 15:40:00 2009".to_time
137
-
138
- # lambda {period.from(5).to(1)}.should raise_error
139
- # lambda {period.to(1).from(5)}.should raise_error
140
144
  end
141
145
 
142
146
  def period
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vrinek-periodicity
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.2"
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kostas Karachalios