cron_format 0.1.12 → 0.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 25b1dd3e86e87a32c4e06964090b57ad12d624b4
4
- data.tar.gz: cbf9ee1f411e1fdad6fbacbb975fb00eaffa84c3
3
+ metadata.gz: 7b0a1a7edae8adf3f1df74f5d7b0faced458b328
4
+ data.tar.gz: cc7cbf448d1bd25646c296667557f9b28c12f037
5
5
  SHA512:
6
- metadata.gz: 5c45081af1e6c0d760e95c68d343f3aabb5920cec8036f65cb28a9fdab7d58b48267d7dff07f2f08585028b564697f82b29cd987de99ca899c88835029ba8c39
7
- data.tar.gz: 5e56e06139f06d875a279fcee2d9d7c4a2ca93305a97a3b6a6ada6534ec3ba5f947604ca5c6eac8a94f615e73855b6055fa134a9afad49b975ec4a55a3d3a27a
6
+ metadata.gz: 5df4e4d5f2eade9400532c2a2e3b6266bcc941d576fead073fbf40aef0cb0a02e7db935b7eb94af730195b1b3444de1a75876c34a20e7a943cd2e8d2373446a2
7
+ data.tar.gz: f1504a906b020fcb0b094396f99dfafb06ba0dc0060a190ac9db513a451cd12a686fc427ba0aa3e444deedd3bbf8b0309c736234d4bb349191b9fddb91339709
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/cron_format.rb CHANGED
@@ -23,6 +23,7 @@ class CronFormat
23
23
  end
24
24
 
25
25
  def next()
26
+
26
27
  nudge() unless @cron_string =~ %r{/}
27
28
  parse()
28
29
  end
@@ -59,7 +60,8 @@ class CronFormat
59
60
  day_proc
60
61
  ]
61
62
 
62
- @to_time = units[index].call @to_time, n
63
+ r = units[index].call @to_time, n
64
+ @to_time = r
63
65
 
64
66
  end
65
67
 
@@ -69,7 +71,7 @@ class CronFormat
69
71
  raw_a << '*' if raw_a.length <= 5 # add the year?
70
72
 
71
73
  units = @to_time.to_a.values_at(1..4) + [nil, @to_time.year]
72
-
74
+
73
75
  procs = {
74
76
  min: lambda {|x, interval| x += (interval * MINUTE).to_i},
75
77
  hour: lambda {|x, interval| x += (interval * HOUR).to_i},
@@ -101,7 +103,7 @@ class CronFormat
101
103
 
102
104
  # take any repeater out of the unit value
103
105
  raw_units, repeaters = [], []
104
-
106
+
105
107
  raw_a.each do |x|
106
108
  v1, v2 = x.split('/')
107
109
  raw_units << v1
@@ -128,6 +130,7 @@ class CronFormat
128
130
 
129
131
  if repeaters.any? then
130
132
  repeaters.each_with_index do |x,i|
133
+
131
134
  next if i == 4
132
135
 
133
136
  if x and not raw_a[i][/^\*/] then
@@ -139,9 +142,9 @@ class CronFormat
139
142
  end
140
143
  end
141
144
  end
142
-
145
+
143
146
  dates = inflate(raw_date)
144
-
147
+
145
148
  a = dates.map do |date|
146
149
 
147
150
  d = date.map{|x| x ? x.clone : nil}
@@ -150,15 +153,15 @@ class CronFormat
150
153
 
151
154
  next unless day_valid? d.reverse.take 3
152
155
  t = Time.parse(TF % d.reverse)
153
-
156
+
154
157
  # if there is a defined weekday, increment a day at
155
158
  # a time to match that weekday
156
159
  if wday and wday != t.wday then
157
160
 
158
161
  t = Time.parse(TF % d.reverse)
159
-
162
+
160
163
  if repeaters[4] then
161
- t += (7 + repeaters[4].to_i) * DAY while t < @to_time
164
+ t += repeaters[4].to_i * WEEK while t < @to_time
162
165
  else
163
166
  d[2], d[3] = @to_time.to_a.values_at(3,4).map(&:to_s)
164
167
  t += DAY until t.wday == wday.to_i
@@ -169,6 +172,7 @@ class CronFormat
169
172
  # increment the month, day, hour, and minute for
170
173
  # expressions which match '* * * *' consecutively
171
174
  i = 3
175
+
172
176
  while t < @to_time and i >= 0 and raw_a[i][/\*/]
173
177
 
174
178
  d[i] = @to_time.to_a[i+1].to_s
@@ -191,15 +195,7 @@ class CronFormat
191
195
  t = Time.parse(TF % d.reverse)
192
196
  end
193
197
  elsif t.day < @to_time.day and raw_a[3] == '*' then
194
-
195
- # increment the month
196
- if d[3].to_i <= 11 then
197
- d[3].succ!
198
- else
199
- d[3] = '1'
200
- d[4].succ!
201
- end
202
- t = Time.parse(TF % d.reverse)
198
+ t = increment_month d
203
199
  elsif (t.hour < @to_time.hour or (t.hour == @to_time.hour \
204
200
  and t.min < @to_time.min and raw_a[1] != '*') ) \
205
201
  and raw_a[2] == '*' then
@@ -214,6 +210,8 @@ class CronFormat
214
210
  # increment the minute
215
211
  t += MINUTE * ((@to_time.min - d[0].to_i) + 1)
216
212
  t = procs.values[i].call(t, repeaters[i].to_i) if repeaters[i]
213
+ elsif raw_a[3] == '*' then
214
+ t = increment_month d
217
215
  end
218
216
 
219
217
  end
@@ -221,7 +219,13 @@ class CronFormat
221
219
  # after the units have been incremented we need to
222
220
  # increment the weekday again if need be
223
221
  if wday then
224
- t += DAY until t.wday == wday.to_i
222
+
223
+ if raw_date[2].length > 1 then
224
+
225
+ t += DAY until t.wday == wday.to_i and raw_date[2].include? t.day.to_s
226
+ else
227
+ t += DAY until t.wday == wday.to_i
228
+ end
225
229
  end
226
230
 
227
231
  # finally, if the date is still less than the current time we can
@@ -231,7 +235,6 @@ class CronFormat
231
235
  repeaters.each_with_index do |x,i|
232
236
 
233
237
  if x then
234
-
235
238
  t = procs.values[i].call(t, x.to_i)
236
239
  end
237
240
  end
@@ -251,7 +254,22 @@ class CronFormat
251
254
  day.to_i <= last_day.day
252
255
  end
253
256
 
254
- def inflate(a)
257
+ def increment_month(d)
258
+
259
+ if d[3].to_i <= 11 then
260
+ d[3].succ!
261
+ else
262
+ d[3] = '1'
263
+ d[4].succ!
264
+ end
265
+
266
+ Time.parse(TF % d.reverse)
267
+ end
268
+
269
+ def inflate(raw_a)
270
+
271
+ a = raw_a.dclone
272
+
255
273
  Array.new(a.max_by {|x| x.length}.length).map do |x|
256
274
  a.map{|x| x.length <= 1 ? x.first : x.shift}
257
275
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cron_format
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  9DFxFCS6sgAw21S+V+ym9ft8kbqgy7zOGdPRRNlwgb/V+UWqH4yaCtk7yJT+n8vm
32
32
  LHkRlhnm0ScZYw==
33
33
  -----END CERTIFICATE-----
34
- date: 2014-01-13 00:00:00.000000000 Z
34
+ date: 2014-01-14 00:00:00.000000000 Z
35
35
  dependencies: []
36
36
  description:
37
37
  email: james@r0bertson.co.uk
metadata.gz.sig CHANGED
Binary file