cron_format 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d71309cad3ce363f9caa6acb54bd9db812dc478
4
- data.tar.gz: b31861bc243bf0a1fdf435c35f463c1aceb89a37
3
+ metadata.gz: 68d7f091de5a9dd5f4c75422b84c041db74258c9
4
+ data.tar.gz: 071ecfa7aad169c864ce1a67ffd5424c0227b302
5
5
  SHA512:
6
- metadata.gz: 704219aeee5658b323c3c3d38c436b8a7bce7fcfa110f01bbc177266b40df2581345cf83193f9978499d86e34fa4f6e50239063bb35a4fd56436433c2c12d533
7
- data.tar.gz: 3680a1f37ba2e619ba2afa8909b615834d80a771cfcf761a1745d6c5321fe85b97b2c7ba5a6d304a2b379c6503a4de026fdea2001686117a6e36d661c71a7c89
6
+ metadata.gz: 0062418d22527232e7d93a9a3294963d8c42924f0bb81139754a12f82e07bbb590e0402735145478eb4377a29c2ee95cc36855f31c91ffdc5c7e77ef0eaa2f6b
7
+ data.tar.gz: 7c3306a11ba674ac0b5017f79874b8dd08f51b0cb3dba4523aa8aa29fab62fea6de4961c3de74980c1fa5ae1e0dfa2dab829e022b2b29bbbbe30078ae2e37247
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/cron_format.rb CHANGED
@@ -9,6 +9,8 @@ require 'time'
9
9
  MINUTE = 60
10
10
  HOUR = MINUTE * 60
11
11
  DAY = HOUR * 24
12
+ TF = "%s-%s-%s %s:%s"
13
+
12
14
 
13
15
  class Array
14
16
 
@@ -51,7 +53,7 @@ class CronFormat
51
53
  month_proc = lambda {|t1,n|
52
54
  a = t1.to_a
53
55
  a[4] = a[4] + n <= 12 ? a[4] + n : a[4] + n - 12
54
- t = Time.parse("%s-%s-%s %s:%s" % a.values_at(5,4,3,2,1,0))
56
+ t = Time.parse(TF % a.values_at(5,4,3,2,1,0))
55
57
  t -= DAY until t.month == a[4]
56
58
  return t
57
59
  }
@@ -78,17 +80,17 @@ class CronFormat
78
80
  units = @to_time.to_a.values_at(1..4) + [nil, @to_time.year]
79
81
 
80
82
  procs = {
81
- min: lambda{|x, interval| x += (interval * MINUTE).to_i},
82
- hour: lambda{|x, interval| x += (interval * HOUR).to_i},
83
- day: lambda{|x, interval| x += (interval * DAY).to_i},
84
- month: lambda{|x, interval|
83
+ min: lambda {|x, interval| x += (interval * MINUTE).to_i},
84
+ hour: lambda {|x, interval| x += (interval * HOUR).to_i},
85
+ day: lambda {|x, interval| x += (interval * DAY).to_i},
86
+ month: lambda {|x, interval|
85
87
  date = x.to_a.values_at(1..5)
86
88
  interval.times { date[3].succ! }
87
- Time.parse("%s-%s-%s %s:%s" % date.reverse)},
88
- year: lambda{|x, interval|
89
+ Time.parse(TF % date.reverse)},
90
+ year: lambda {|x, interval|
89
91
  date = x.to_a.values_at(1..5)
90
92
  interval.times { date[4].succ! }
91
- Time.parse("%s-%s-%s %s:%s" % date.reverse)}
93
+ Time.parse(TF % date.reverse)}
92
94
  }
93
95
 
94
96
  dt = units.map do |start|
@@ -113,12 +115,13 @@ class CronFormat
113
115
  raw_units << v1
114
116
  repeaters << v2
115
117
  end
116
-
117
- raw_units[4].gsub!(/(sun|mon|tues|wed|thurs|fri|satur|sun)(day)?|tue|thu|sat/) do |x|
118
+
119
+ r = /(sun|mon|tues|wed|thurs|fri|satur|sun)(day)?|tue|thu|sat/i
120
+ raw_units[4].gsub!(r) do |x|
118
121
  a = %w(sunday monday tuesday wednesday thursday friday saturday)
119
122
  a.index a.grep(/#{x}/i).first
120
123
  end
121
-
124
+
122
125
  raw_date = raw_units.map.with_index {|x,i| dt[i].call(x) }
123
126
 
124
127
  # expand the repeater
@@ -137,6 +140,7 @@ class CronFormat
137
140
  end
138
141
  end
139
142
 
143
+
140
144
  dates = raw_date.inflate
141
145
 
142
146
  a = dates.map do |date|
@@ -147,11 +151,11 @@ class CronFormat
147
151
  d << year
148
152
 
149
153
  next unless day_valid? d.reverse.take 3
150
- t = Time.parse("%s-%s-%s %s:%s" % d.reverse)
154
+ t = Time.parse(TF % d.reverse)
151
155
 
152
156
  if t < @to_time and wday and wday != t.wday then
153
157
  d[2], d[3] = @to_time.to_a.values_at(3,4).map(&:to_s)
154
- t = Time.parse("%s-%s-%s %s:%s" % d.reverse)
158
+ t = Time.parse(TF % d.reverse)
155
159
  t += DAY until t.wday == wday.to_i
156
160
  end
157
161
 
@@ -159,7 +163,7 @@ class CronFormat
159
163
  while t < @to_time and i >= 0 and raw_a[i][/\*/]
160
164
 
161
165
  d[i] = @to_time.to_a[i+1].to_s
162
- t = Time.parse("%s-%s-%s %s:%s" % d.reverse)
166
+ t = Time.parse(TF % d.reverse)
163
167
  i -= 1
164
168
  end
165
169
 
@@ -169,11 +173,11 @@ class CronFormat
169
173
  # increment the year
170
174
 
171
175
  d[4].succ!
172
- t = Time.parse("%s-%s-%s %s:%s" % d.reverse)
176
+ t = Time.parse(TF % d.reverse)
173
177
 
174
178
  if repeaters[4] then
175
179
  d[4].succ!
176
- t = Time.parse("%s-%s-%s %s:%s" % d.reverse)
180
+ t = Time.parse(TF % d.reverse)
177
181
  end
178
182
  elsif t.day < @to_time.day and raw_a[3] == '*' then
179
183
 
@@ -184,7 +188,7 @@ class CronFormat
184
188
  d[3] = '1'
185
189
  d[4].succ!
186
190
  end
187
- t = Time.parse("%s-%s-%s %s:%s" % d.reverse)
191
+ t = Time.parse(TF % d.reverse)
188
192
  elsif (t.hour < @to_time.hour or (t.hour == @to_time.hour \
189
193
  and t.min < @to_time.min and raw_a[1] != '*') ) \
190
194
  and raw_a[2] == '*' then
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.2
4
+ version: 0.1.3
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: 2013-07-08 00:00:00.000000000 Z
34
+ date: 2013-07-11 00:00:00.000000000 Z
35
35
  dependencies: []
36
36
  description:
37
37
  email:
metadata.gz.sig CHANGED
@@ -1,2 +1 @@
1
- Hrnb�ܟ��Ǿ��C���_�5�]��zM��%s\�w����^�_��Q9��)�,V�~���I2,�t)݁�����} 2�_,�� O����)QEA�D�σ��Z���o�W'����k�u���}Y��mE��wX-3��F=�n��x��)U��ԐKcwI
2
- ��G�shw���k� �@.�H�9b��I:��x����{q\�����)߇�y~��tA(���4�
1
+ ��@�#vN%�ng3In���\<4���MTFL�Ԟ�o��5i��['�