cron_format 0.4.0 → 0.5.0
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 +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/cron_format.rb +52 -11
- metadata +24 -4
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5ae188fa6fbdd52dfef8995dc0b9b1f164d036bd77e9a15c5e30e9acc5ae8575
|
4
|
+
data.tar.gz: 362ebbce43c0f775441efb0106a611b175cae5ecceccd803ebc8b583b92ae408
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48cb5f44186323f31f2ed2d3cec40a0031955c4de6bd1a66cc19fb5ef05f30d3e6059f2788e786c75f3dffc9e1f088ae6253a87c7a333a3dd618f654d261dcb5
|
7
|
+
data.tar.gz: 4774ef323ddcdcc36f4313b2bd5ee91f5b5d2b5a8a5bdbb02c6fec79ce4e06b3bd806b34647ce6182eaf18492c58744a91ebae2ade7da3b929983c210b7e1dc5
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/cron_format.rb
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
|
5
5
|
require 'date'
|
6
6
|
require 'time'
|
7
|
+
require 'c32'
|
7
8
|
|
8
9
|
|
9
10
|
MINUTE = 60
|
@@ -14,12 +15,17 @@ TF = "%s-%s-%s %s:%s"
|
|
14
15
|
|
15
16
|
|
16
17
|
class CronFormat
|
18
|
+
using ColouredText
|
17
19
|
|
18
20
|
attr_reader :to_time, :to_expression
|
19
21
|
|
20
22
|
def initialize(cron_string, now=Time.now, debug: false)
|
21
|
-
|
23
|
+
|
24
|
+
puts 'inside CronFormat'.info if debug
|
25
|
+
@cron_string, @now, @debug = cron_string, now, debug
|
26
|
+
@to_time = @now
|
22
27
|
parse()
|
28
|
+
|
23
29
|
end
|
24
30
|
|
25
31
|
# supply a Time object. Modifying the date can be helpful when
|
@@ -51,7 +57,7 @@ class CronFormat
|
|
51
57
|
def nudge()
|
52
58
|
|
53
59
|
t1 = @to_time
|
54
|
-
puts 't1: ' + t1.inspect if @debug
|
60
|
+
puts ('t1: ' + t1.inspect).debug if @debug
|
55
61
|
a = @cron_string.split
|
56
62
|
|
57
63
|
val = if @cron_string =~ %r{[/,-]} then
|
@@ -62,7 +68,7 @@ class CronFormat
|
|
62
68
|
|
63
69
|
index, n = 0, 1
|
64
70
|
|
65
|
-
puts 'val: ' + val.inspect if @debug
|
71
|
+
puts ('val: ' + val.inspect).debug if @debug
|
66
72
|
|
67
73
|
if val then
|
68
74
|
index = a.index(val)
|
@@ -83,7 +89,7 @@ class CronFormat
|
|
83
89
|
end
|
84
90
|
end
|
85
91
|
|
86
|
-
puts 'index: ' + index.inspect if @debug
|
92
|
+
puts ('index: ' + index.inspect).debug if @debug
|
87
93
|
|
88
94
|
month_proc = lambda {|t1,n|
|
89
95
|
a = t1.to_a
|
@@ -104,13 +110,13 @@ class CronFormat
|
|
104
110
|
]
|
105
111
|
|
106
112
|
if @debug then
|
107
|
-
puts '@to_time: ' + @to_time.inspect
|
108
|
-
puts 'n: ' + n.inspect
|
113
|
+
puts ('@to_time: ' + @to_time.inspect).debug
|
114
|
+
puts ('n: ' + n.inspect).debug
|
109
115
|
end
|
110
116
|
|
111
117
|
r = units[index].call @to_time, n
|
112
118
|
|
113
|
-
puts 'r: ' + r.inspect if @debug
|
119
|
+
puts ('r: ' + r.inspect).debug if @debug
|
114
120
|
|
115
121
|
@to_time = if n > 1 then
|
116
122
|
|
@@ -125,6 +131,8 @@ class CronFormat
|
|
125
131
|
end
|
126
132
|
|
127
133
|
def parse()
|
134
|
+
|
135
|
+
puts ('0. @to_time: ' + @to_time.inspect).debug if @debug
|
128
136
|
|
129
137
|
raw_a = @cron_string.split
|
130
138
|
raw_a << '*' if raw_a.length <= 5 # add the year?
|
@@ -135,9 +143,28 @@ class CronFormat
|
|
135
143
|
@to_time.month == month.to_i
|
136
144
|
end
|
137
145
|
|
146
|
+
puts ('1. @to_time: ' + @to_time.inspect).debug if @debug
|
147
|
+
|
148
|
+
#
|
149
|
+
|
150
|
+
if @debug then
|
151
|
+
puts ('1.5 @to_time: ' + @to_time.inspect).debug
|
152
|
+
puts ('hours: ' + hours.inspect).debug
|
153
|
+
puts ('mins: ' + mins.inspect).debug
|
154
|
+
end
|
155
|
+
|
138
156
|
if mins[/^\d+$/] and hours[/^\d+$/] then
|
139
|
-
|
140
|
-
|
157
|
+
|
158
|
+
if @to_time.to_date != @now.to_date then
|
159
|
+
@to_time = Time.local(@to_time.year, @to_time.month, @to_time.day)
|
160
|
+
end
|
161
|
+
|
162
|
+
until (@to_time.min == mins.to_i and @to_time.hour == hours.to_i) \
|
163
|
+
or (@to_time - 1).isdst != @to_time.isdst do
|
164
|
+
|
165
|
+
puts ('1.7 @to_time: ' + @to_time.inspect).debug if @debug
|
166
|
+
@to_time += MINUTE
|
167
|
+
end
|
141
168
|
@to_time -= MINUTE
|
142
169
|
else
|
143
170
|
|
@@ -147,7 +174,9 @@ class CronFormat
|
|
147
174
|
end
|
148
175
|
|
149
176
|
@to_time += HOUR until @to_time.hour == hours.to_i if hours[/^\d+$/]
|
150
|
-
end
|
177
|
+
end
|
178
|
+
|
179
|
+
puts ('2. @to_time: ' + @to_time.inspect).debug if @debug
|
151
180
|
|
152
181
|
if wday[/^[0-6]$/] and @to_time.wday != wday.to_i then
|
153
182
|
@to_time += DAY until @to_time.wday == wday.to_i
|
@@ -163,6 +192,8 @@ class CronFormat
|
|
163
192
|
|
164
193
|
@to_time = dt2.to_time
|
165
194
|
end
|
195
|
+
|
196
|
+
puts ('3. @to_time: ' + @to_time.inspect).debug if @debug
|
166
197
|
|
167
198
|
units = @to_time.to_a.values_at(1..4) + [nil, @to_time.year]
|
168
199
|
|
@@ -239,7 +270,9 @@ class CronFormat
|
|
239
270
|
end
|
240
271
|
end
|
241
272
|
|
242
|
-
dates = inflate(raw_date)
|
273
|
+
dates = inflate(raw_date)
|
274
|
+
|
275
|
+
puts ('dates: ' + dates.inspect).debug if @debug
|
243
276
|
|
244
277
|
a = dates.map do |date|
|
245
278
|
|
@@ -278,6 +311,11 @@ class CronFormat
|
|
278
311
|
# starting from the biggest unit, attempt to increment that
|
279
312
|
# unit where it is equal to '*'
|
280
313
|
|
314
|
+
if @debug then
|
315
|
+
puts ('t: ' + t.inspect).debug
|
316
|
+
puts ('@to_time: ' + @to_time.inspect).debug
|
317
|
+
end
|
318
|
+
|
281
319
|
if t < @to_time then
|
282
320
|
|
283
321
|
if t.month < @to_time.month and raw_a[4] == '*' then
|
@@ -285,6 +323,7 @@ class CronFormat
|
|
285
323
|
# increment the year
|
286
324
|
d[4].succ!
|
287
325
|
t = Time.parse(TF % d.reverse)
|
326
|
+
puts 't: ' + t.inspect if @debug
|
288
327
|
|
289
328
|
if repeaters[4] then
|
290
329
|
|
@@ -345,6 +384,8 @@ class CronFormat
|
|
345
384
|
|
346
385
|
t
|
347
386
|
end
|
387
|
+
|
388
|
+
puts ('a: ' + a.inspect).debug if @debug
|
348
389
|
|
349
390
|
@to_time = a.compact.min
|
350
391
|
end
|
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.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -30,8 +30,28 @@ cert_chain:
|
|
30
30
|
Jde8bC6zoA/f/DUUzBf2TtjXPuoAdtsV3CT3nIo880mXyihT9CL9ulTHMJCBR73I
|
31
31
|
fsk=
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date:
|
34
|
-
dependencies:
|
33
|
+
date: 2019-01-09 00:00:00.000000000 Z
|
34
|
+
dependencies:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: c32
|
37
|
+
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0.1'
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 0.1.2
|
45
|
+
type: :runtime
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - "~>"
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0.1'
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.1.2
|
35
55
|
description:
|
36
56
|
email: james@jamesrobertson.eu
|
37
57
|
executables: []
|
@@ -59,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
79
|
version: '0'
|
60
80
|
requirements: []
|
61
81
|
rubyforge_project:
|
62
|
-
rubygems_version: 2.6
|
82
|
+
rubygems_version: 2.7.6
|
63
83
|
signing_key:
|
64
84
|
specification_version: 4
|
65
85
|
summary: Accepts a cron expression and outputs the relative time (e.g. 0 7 1 1 * *
|
metadata.gz.sig
CHANGED
Binary file
|