cron_format 0.1.7 → 0.1.8

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: eec1b88cd1412621c71ddd48e4c271199c591cc0
4
- data.tar.gz: ef8bca9680ccaa41a9057b3f7ad2be11ede7c115
3
+ metadata.gz: bc5b124e93e76533580f0693d394e7c14c42b63d
4
+ data.tar.gz: c86bf9db1516e6a0136d171a849d590fbe5654fa
5
5
  SHA512:
6
- metadata.gz: 6cff4440b17a9f8cd24df5631a10fd5fffc282dd94567102b7e390a40842c742d74b5a3b2830fb665eba9de5670d8b56680e447038ae0d3952f7c6809752b6ea
7
- data.tar.gz: a264ffbec7eb404e88fb29822af4d2577ca90b02af85483165d850d4e864c79dd87452d010e66adcd0e6fb64ba32e43e342a5bfea992fec9adbb995b0384d3eb
6
+ metadata.gz: 9d961fcb2c332f4196bb865bf993008eb2f49ad4af902e5b5b970fafedfe1ee35ce1081b165fa9c913bc825bb794f5117427d95f44c2106f615247ceeceb2ee6
7
+ data.tar.gz: 4fd8d28ba6ea17a6a625f76f634891f0062011c37fda5aec18e15532866bda9442f579341d39670197ab436bf7f4ef574c99b3e029fee7e2bfa75d6e4a0a0a17
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/cron_format.rb CHANGED
@@ -115,23 +115,27 @@ class CronFormat
115
115
  raw_units << v1
116
116
  repeaters << v2
117
117
  end
118
-
119
- r = /(sun|mon|tues|wed|thurs|fri|satur|sun)(day)?|tue|thu|sat/i
120
- raw_units[4].gsub!(r) do |x|
121
- a = Date::DAYNAMES
122
- a.index a.grep(/#{x}/i).first
118
+
119
+ if raw_units[4] then
120
+ r = /(sun|mon|tues|wed|thurs|fri|satur|sun)(day)?|tue|thu|sat/i
121
+
122
+ raw_units[4].gsub!(r) do |x|
123
+ a = Date::DAYNAMES
124
+ a.index a.grep(/#{x}/i).first
125
+ end
123
126
  end
124
127
 
125
128
  @to_expression = (raw_a[0..3] + [raw_units[4]])[0..4].join ' '
126
-
127
129
  raw_date = raw_units.map.with_index {|x,i| dt[i].call(x) }
128
-
130
+
129
131
  # expand the repeater
130
132
 
131
- ceil = {min: MINUTE, hour: 23, day: 31, month: 12}.values
133
+ ceil = {min: MINUTE, hour: 23, day: 31, month: 12}.values
132
134
 
133
135
  if repeaters.any? then
134
136
  repeaters.each_with_index do |x,i|
137
+ next if i == 4
138
+
135
139
  if x and not raw_a[i][/^\*/] then
136
140
  raw_date[i] = raw_date[i].map {|y|
137
141
  (y.to_i...ceil[i]).step(x.to_i).to_a.map(&:to_s)
@@ -142,25 +146,31 @@ class CronFormat
142
146
  end
143
147
  end
144
148
 
145
-
146
149
  dates = raw_date.inflate
147
150
 
148
151
  a = dates.map do |date|
149
152
 
150
153
  d = date.map{|x| x ? x.clone : nil}
151
154
  wday, year = d.pop(2)
152
-
153
155
  d << year
154
156
 
155
157
  next unless day_valid? d.reverse.take 3
156
- t = Time.parse(TF % d.reverse)
158
+ t = Time.parse(TF % d.reverse)
159
+
160
+ # if there is a defined weekday, increment a day at
161
+ # a time to match that weekday
162
+ #jr050813 if t < @to_time and wday and wday != t.wday then
163
+ if wday and wday != t.wday then
157
164
 
158
- if t < @to_time and wday and wday != t.wday then
159
165
  d[2], d[3] = @to_time.to_a.values_at(3,4).map(&:to_s)
166
+
160
167
  t = Time.parse(TF % d.reverse)
161
- t += DAY until t.wday == wday.to_i
168
+ t += DAY until t.wday == wday.to_i
169
+ t += (7 + repeaters[4].to_i) * DAY if t < @to_time and repeaters[4]
162
170
  end
163
-
171
+
172
+ # increment the month, day, hour, and minute for
173
+ # expressions which match '* * * *' consecutively
164
174
  i = 3
165
175
  while t < @to_time and i >= 0 and raw_a[i][/\*/]
166
176
 
@@ -169,6 +179,8 @@ class CronFormat
169
179
  i -= 1
170
180
  end
171
181
 
182
+ # starting from the biggest unit, attempt to increment that
183
+ # unit where it is equal to '*'
172
184
  if t < @to_time then
173
185
 
174
186
  if t.month < @to_time.month and raw_a[4] == '*' then
@@ -197,7 +209,6 @@ class CronFormat
197
209
 
198
210
  # increment the day
199
211
  t += DAY * ((@to_time.day - d[2].to_i) + 1)
200
- #jr070713 elsif t.min < @to_time.min and raw_a[1] == '*' then
201
212
  elsif t.min < @to_time.min and raw_a[1] == '*' then
202
213
 
203
214
  # increment the hour
@@ -210,13 +221,18 @@ class CronFormat
210
221
 
211
222
  end
212
223
 
224
+ # after the units have been incremented we need to
225
+ # increment the weekday again if need be
213
226
  if wday then
214
227
  t += DAY until t.wday == wday.to_i
215
228
  end
216
229
 
230
+ # finally, if the date is still less than the current time we can
231
+ # increment the date using any repeating intervals
217
232
  if t <= @to_time and repeaters.any? then
218
233
 
219
234
  repeaters.each_with_index do |x,i|
235
+
220
236
  if x then
221
237
  t = procs.values[i].call(t, x.to_i)
222
238
  end
data.tar.gz.sig CHANGED
@@ -1 +1,2 @@
1
- nM����v��K*]5l}�%�Z]�
1
+ �Aa9YX�l���h�U���W��j�!~���@STkh�kUy>4#�+\2A�-z�H�r��Q�`I[�;��X���
2
+ ��p������o ��(�����P��#G8】�M�Ы�M oԑAF� \�,^����؎�E����@��5�̓�:�ө!���Cog�UT*wz6�1v<y��nd�T2���t��q�7t��}�R���ITNQ=��ӶL��r�/ �b��SA��R9�����= L(�B-
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.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file