kronparser 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +60 -0
- data/Rakefile +1 -0
- data/kronparser.gemspec +24 -0
- data/lib/kronparser.rb +159 -0
- data/lib/kronparser/simple_process.rb +19 -0
- data/lib/kronparser/version.rb +3 -0
- data/spec/kronparser_spec.rb +122 -0
- data/spec/spec_helper.rb +8 -0
- metadata +68 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
Kronparser
|
2
|
+
======================
|
3
|
+
|
4
|
+
datermine next scheduled crontab run
|
5
|
+
|
6
|
+
Installation
|
7
|
+
------------
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'kronparser'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install kronparser
|
20
|
+
|
21
|
+
Usage
|
22
|
+
-----
|
23
|
+
* Example1
|
24
|
+
|
25
|
+
```
|
26
|
+
require 'kronparser'
|
27
|
+
require 'time'
|
28
|
+
|
29
|
+
KronParser.parser("* * * * *").next(Time.parse("Fri Oct 26 11:27:44 +0900 2012"))
|
30
|
+
# => Fri Oct 26 11:28:00 +0900 2012
|
31
|
+
```
|
32
|
+
|
33
|
+
* Example2
|
34
|
+
|
35
|
+
```
|
36
|
+
require 'kronparser'
|
37
|
+
|
38
|
+
KronParser.parser("* * * * *").next
|
39
|
+
# => Fri Oct 26 11:28:00 +0900 2012
|
40
|
+
# Default value is Time.now
|
41
|
+
```
|
42
|
+
|
43
|
+
* Additional Example
|
44
|
+
|
45
|
+
```
|
46
|
+
gem 'kronparser'
|
47
|
+
require 'kronparser'
|
48
|
+
|
49
|
+
KronParser::SimpleProcess.every("* * * * *") do
|
50
|
+
puts Time.now
|
51
|
+
end
|
52
|
+
|
53
|
+
while true
|
54
|
+
sleep 10
|
55
|
+
end
|
56
|
+
|
57
|
+
# => Fri Oct 26 11:27:00 +0900 2012
|
58
|
+
# => Fri Oct 26 11:28:00 +0900 2012
|
59
|
+
# => ...
|
60
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/kronparser.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "kronparser/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "kronparser"
|
7
|
+
s.version = KronParser::VERSION
|
8
|
+
s.authors = ["mechamogera"]
|
9
|
+
s.email = [""]
|
10
|
+
s.homepage = "https://github.com/mechamogera/kronparser"
|
11
|
+
s.summary = %q{datermine next scheduled crontab run}
|
12
|
+
s.description = %q{datermine next scheduled crontab run}
|
13
|
+
|
14
|
+
s.rubyforge_project = "kronparser"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
end
|
data/lib/kronparser.rb
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
require File.expand_path('kronparser/simple_process', File.dirname(__FILE__))
|
2
|
+
require File.expand_path("kronparser/version", File.dirname(__FILE__))
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
class KronParser
|
6
|
+
TIME_RANGE = {
|
7
|
+
:min => 0..59,
|
8
|
+
:hour => 0..23,
|
9
|
+
:day => 1..31,
|
10
|
+
:mon => 1..12,
|
11
|
+
:wday => 0..6,
|
12
|
+
}
|
13
|
+
|
14
|
+
def self.parse(cron_time_format)
|
15
|
+
return KronParser.new(cron_time_format)
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(cron_time_format)
|
19
|
+
elems = cron_time_format.split
|
20
|
+
@data = {}
|
21
|
+
[:min, :hour, :day, :mon, :wday].each_with_index do |t, idx|
|
22
|
+
@data[t] = parse_elem(elems[idx], TIME_RANGE[t])
|
23
|
+
end
|
24
|
+
|
25
|
+
if elems[4] == "*"
|
26
|
+
@day_type = :day
|
27
|
+
elsif elems[2] == "*"
|
28
|
+
@day_type = :wday
|
29
|
+
else
|
30
|
+
@day_type = :each
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def next(time = Time.now)
|
35
|
+
forward = 1
|
36
|
+
time_items = [:min, :hour, :day, :mon]
|
37
|
+
time_data = {}
|
38
|
+
time_items.each_with_index do |time_item, idx|
|
39
|
+
time_data[time_item], forward = next_elem(time_item,
|
40
|
+
time.send(time_item) + forward,
|
41
|
+
:mon => time.mon,
|
42
|
+
:year => time.year)
|
43
|
+
if (forward == 1) || (time_data[time_item] != time.send(time_item))
|
44
|
+
idx.times do |i|
|
45
|
+
time_data[time_items[i]] = first_elem(time_items[i], :mon => time.mon, :year => time.year)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
time_data[:year] = time.year + forward
|
51
|
+
|
52
|
+
date = nil
|
53
|
+
while date.nil?
|
54
|
+
date = Date.new(time_data[:year], time_data[:mon], time_data[:day]) rescue nil
|
55
|
+
next if date
|
56
|
+
|
57
|
+
time_data[:min] = first_elem(:min)
|
58
|
+
time_data[:hour] = first_elem(:hour)
|
59
|
+
|
60
|
+
time_data[:day], forward = next_elem(:day, time_data[:day] + 1, time_data)
|
61
|
+
time_data[:mon], forward = next_elem(:mon, time_data[:mon] + forward)
|
62
|
+
time_data[:year] += forward
|
63
|
+
end
|
64
|
+
|
65
|
+
return Time.local(time_data[:year], time_data[:mon], time_data[:day], time_data[:hour], time_data[:min])
|
66
|
+
end
|
67
|
+
|
68
|
+
def last(time = TIme.now)
|
69
|
+
Time.now
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def first_elem(type, options = {})
|
75
|
+
if (type != :day) || (@day_type == :day)
|
76
|
+
return @data[type].first
|
77
|
+
end
|
78
|
+
|
79
|
+
value = nil
|
80
|
+
next_mon, forward = next_elem(:mon, options[:mon] + 1)
|
81
|
+
date = Date.new(options[:year] + forward, next_mon, 1) rescue nil
|
82
|
+
next_wday = @data[:wday].find { |x| x >= date.wday }
|
83
|
+
value = 1 + (next_wday ? (next_wday - date.wday) : (7 - date.wday + @data[:wday].first))
|
84
|
+
|
85
|
+
case @day_type
|
86
|
+
when :wday
|
87
|
+
return value
|
88
|
+
when :each
|
89
|
+
return [value, @data[type].first].min
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def next_elem(type, value, options = {})
|
94
|
+
next_value = forward = nil
|
95
|
+
|
96
|
+
if (type != :day) || (@day_type != :wday)
|
97
|
+
next_value = @data[type].find { |x| x >= value }
|
98
|
+
forward = next_value.nil? ? 1 : 0
|
99
|
+
next_value = @data[type].first unless next_value
|
100
|
+
end
|
101
|
+
|
102
|
+
if (type != :day) || (@day_type == :day)
|
103
|
+
return next_value, forward
|
104
|
+
end
|
105
|
+
|
106
|
+
wday_forward = nil
|
107
|
+
next_wday_value = value
|
108
|
+
date = Date.new(options[:year], options[:mon], value) rescue nil
|
109
|
+
if date
|
110
|
+
next_wday = @data[:wday].find { |x| x >= date.wday }
|
111
|
+
next_wday_value += next_wday ? (next_wday - date.wday) : (7 - date.wday + @data[:wday].first)
|
112
|
+
if next_wday_value <= 31
|
113
|
+
wday_forward = 0
|
114
|
+
else
|
115
|
+
next_wday_value, wday_forward = first_elem(type, options), 1
|
116
|
+
end
|
117
|
+
else
|
118
|
+
next_wday_value, wday_forward = first_elem(type, options), 1
|
119
|
+
end
|
120
|
+
|
121
|
+
case @day_type
|
122
|
+
when :wday
|
123
|
+
return next_wday_value, wday_forward
|
124
|
+
when :each
|
125
|
+
return *(((forward > wday_forward) || ((forward == wday_forward) && (next_value > next_wday_value))) ? [next_wday_value, wday_forward] : [next_value, forward])
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def parse_elem(format, range)
|
130
|
+
case format
|
131
|
+
when /,/
|
132
|
+
return format.split(",").inject([]) { |t, x| t += parse_elem(x, range); t }.sort.uniq
|
133
|
+
when "*"
|
134
|
+
return range.to_a
|
135
|
+
when /^\d+$/
|
136
|
+
return [format.to_i]
|
137
|
+
when /^(\d+)-(\d+)$/
|
138
|
+
first = $1.to_i
|
139
|
+
last = $2.to_i
|
140
|
+
if first <= last
|
141
|
+
return ($1.to_i..$2.to_i).to_a
|
142
|
+
else
|
143
|
+
return (range.first..last).to_a + (first..range.last).to_a
|
144
|
+
end
|
145
|
+
when /^(.+)\/(\d+)$/
|
146
|
+
targets = parse_elem($1.to_s, range)
|
147
|
+
num = $2.to_i
|
148
|
+
|
149
|
+
result = []
|
150
|
+
i = targets.first
|
151
|
+
while i <= targets.last
|
152
|
+
result << i
|
153
|
+
i += num
|
154
|
+
end
|
155
|
+
|
156
|
+
return result
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class KronParser
|
2
|
+
module SimpleProcess
|
3
|
+
def self.every(cron_format, &block)
|
4
|
+
parser = KronParser.parse(cron_format)
|
5
|
+
Thread.start(parser, block) do |p, proc|
|
6
|
+
while true
|
7
|
+
now = Time.now
|
8
|
+
span = p.next(now) - now
|
9
|
+
if span > 3600
|
10
|
+
sleep 3550
|
11
|
+
else
|
12
|
+
sleep span
|
13
|
+
proc.call
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'time'
|
3
|
+
|
4
|
+
describe KronParser do
|
5
|
+
it "could get next and last time" do
|
6
|
+
test_data = [
|
7
|
+
["1 * * * *", :next, "2011/12/21 12:31:52", "2011/12/21 13:01:00"],
|
8
|
+
["* 1 * * *", :next, "2011/12/21 12:31:52", "2011/12/22 01:00:00"],
|
9
|
+
["* * 1 * *", :next, "2011/12/21 12:31:52", "2012/01/01 00:00:00"],
|
10
|
+
["* * * 1 *", :next, "2011/12/21 12:31:52", "2012/01/01 00:00:00"],
|
11
|
+
["* * * * *", :next, "2011/12/21 12:31:52", "2011/12/21 12:32:00"],
|
12
|
+
|
13
|
+
["5,30 * * * *", :next, "2011/12/21 12:01:52", "2011/12/21 12:05:00"],
|
14
|
+
["5,30 * * * *", :next, "2011/12/21 12:05:52", "2011/12/21 12:30:00"],
|
15
|
+
["5,30 * * * *", :next, "2011/12/21 12:30:52", "2011/12/21 13:05:00"],
|
16
|
+
["*/20 * * * *", :next, "2011/12/21 12:30:52", "2011/12/21 12:40:00"],
|
17
|
+
["*/20 * * * *", :next, "2011/12/21 12:40:52", "2011/12/21 13:00:00"],
|
18
|
+
["41-43 * * * *", :next, "2011/12/21 12:00:52", "2011/12/21 12:41:00"],
|
19
|
+
["41-43 * * * *", :next, "2011/12/21 12:40:52", "2011/12/21 12:41:00"],
|
20
|
+
["41-43 * * * *", :next, "2011/12/21 12:41:52", "2011/12/21 12:42:00"],
|
21
|
+
["41-43 * * * *", :next, "2011/12/21 12:42:52", "2011/12/21 12:43:00"],
|
22
|
+
["41-43 * * * *", :next, "2011/12/21 12:43:52", "2011/12/21 13:41:00"],
|
23
|
+
["15-30/7 * * * *", :next, "2011/12/21 12:04:52", "2011/12/21 12:15:00"],
|
24
|
+
["15-30/7 * * * *", :next, "2011/12/21 12:14:52", "2011/12/21 12:15:00"],
|
25
|
+
["15-30/7 * * * *", :next, "2011/12/21 12:15:52", "2011/12/21 12:22:00"],
|
26
|
+
["15-30/7 * * * *", :next, "2011/12/21 12:16:52", "2011/12/21 12:22:00"],
|
27
|
+
["15-30/7 * * * *", :next, "2011/12/21 12:21:52", "2011/12/21 12:22:00"],
|
28
|
+
["15-30/7 * * * *", :next, "2011/12/21 12:22:52", "2011/12/21 12:29:00"],
|
29
|
+
["15-30/7 * * * *", :next, "2011/12/21 12:23:52", "2011/12/21 12:29:00"],
|
30
|
+
["15-30/7 * * * *", :next, "2011/12/21 12:28:52", "2011/12/21 12:29:00"],
|
31
|
+
["15-30/7 * * * *", :next, "2011/12/21 12:29:52", "2011/12/21 13:15:00"],
|
32
|
+
["15-30/7 * * * *", :next, "2011/12/21 12:30:52", "2011/12/21 13:15:00"],
|
33
|
+
["15-30/7 * * * *", :next, "2011/12/21 12:31:52", "2011/12/21 13:15:00"],
|
34
|
+
["15-30/7 * * * *", :next, "2011/12/21 12:40:52", "2011/12/21 13:15:00"],
|
35
|
+
["15-30/9,3 * * * *", :next, "2011/12/21 12:02:52", "2011/12/21 12:03:00"],
|
36
|
+
["15-30/9,3 * * * *", :next, "2011/12/21 12:03:52", "2011/12/21 12:15:00"],
|
37
|
+
["15-30/9,3 * * * *", :next, "2011/12/21 12:04:52", "2011/12/21 12:15:00"],
|
38
|
+
["15-30/9,3 * * * *", :next, "2011/12/21 12:14:52", "2011/12/21 12:15:00"],
|
39
|
+
["15-30/9,3 * * * *", :next, "2011/12/21 12:15:52", "2011/12/21 12:24:00"],
|
40
|
+
["15-30/9,3 * * * *", :next, "2011/12/21 12:16:52", "2011/12/21 12:24:00"],
|
41
|
+
["15-30/9,3 * * * *", :next, "2011/12/21 12:23:52", "2011/12/21 12:24:00"],
|
42
|
+
["15-30/9,3 * * * *", :next, "2011/12/21 12:24:52", "2011/12/21 13:03:00"],
|
43
|
+
["15-30/9,3 * * * *", :next, "2011/12/21 12:25:52", "2011/12/21 13:03:00"],
|
44
|
+
|
45
|
+
["5 * * * *", :next, "2011/12/31 23:25:52", "2012/01/01 00:05:00"],
|
46
|
+
["5 * * * *", :next, "2011/12/30 23:25:52", "2011/12/31 00:05:00"],
|
47
|
+
["5 * * * *", :next, "2011/12/30 22:25:52", "2011/12/30 23:05:00"],
|
48
|
+
["5 * * * *", :next, "2011/12/30 22:03:52", "2011/12/30 22:05:00"],
|
49
|
+
["* 5 * * *", :next, "2011/12/31 23:06:52", "2012/01/01 05:00:00"],
|
50
|
+
["* 5 * * *", :next, "2011/12/30 23:06:52", "2011/12/31 05:00:00"],
|
51
|
+
["* 5 * * *", :next, "2011/12/30 01:06:52", "2011/12/30 05:00:00"],
|
52
|
+
["3,5 5 * * *", :next, "2011/12/31 23:06:52", "2012/01/01 05:03:00"],
|
53
|
+
["3,5 5 * * *", :next, "2011/12/30 23:06:52", "2011/12/31 05:03:00"],
|
54
|
+
["3,5 5 * * *", :next, "2011/12/30 01:06:52", "2011/12/30 05:03:00"],
|
55
|
+
["* * 5 * *", :next, "2011/12/31 01:06:52", "2012/01/05 00:00:00"],
|
56
|
+
["* * 5 * *", :next, "2011/12/01 01:06:52", "2011/12/05 00:00:00"],
|
57
|
+
["6-10 * 5 * *", :next, "2011/12/31 01:06:52", "2012/01/05 00:06:00"],
|
58
|
+
["6-10 * 5 * *", :next, "2011/12/01 01:06:52", "2011/12/05 00:06:00"],
|
59
|
+
["*/4 9-13 5 * *", :next, "2011/12/01 01:06:52", "2011/12/05 09:00:00"],
|
60
|
+
["*/4 9-13 5 * *", :next, "2011/12/31 01:06:52", "2012/01/05 09:00:00"],
|
61
|
+
["10-40/5 9 5 * *", :next, "2011/12/01 01:06:52", "2011/12/05 09:10:00"],
|
62
|
+
["10-40/5 9 5 * *", :next, "2011/12/31 01:06:52", "2012/01/05 09:10:00"],
|
63
|
+
["* * 31 * *", :next, "2012/02/01 01:06:52", "2012/03/31 00:00:00"],
|
64
|
+
["* * 31 * *", :next, "2012/03/31 23:59:59", "2012/05/31 00:00:00"],
|
65
|
+
["5 5 29 * *", :next, "2012/02/28 05:05:59", "2012/02/29 05:05:00"],
|
66
|
+
["5 5 29 * *", :next, "2012/02/29 05:05:59", "2012/03/29 05:05:00"],
|
67
|
+
["* * * 5 *", :next, "2012/03/06 06:03:22", "2012/05/01 00:00:00"],
|
68
|
+
["* * * 5 *", :next, "2012/05/06 06:03:22", "2012/05/06 06:04:00"],
|
69
|
+
["* * * 5 *", :next, "2012/06/06 06:03:22", "2013/05/01 00:00:00"],
|
70
|
+
["5 * * 5 *", :next, "2012/03/06 06:03:22", "2012/05/01 00:05:00"],
|
71
|
+
["5 * * 5 *", :next, "2012/05/06 06:03:22", "2012/05/06 06:05:00"],
|
72
|
+
["5 * * 5 *", :next, "2012/05/06 06:05:22", "2012/05/06 07:05:00"],
|
73
|
+
["5 * * 5 *", :next, "2012/05/31 23:05:22", "2013/05/01 00:05:00"],
|
74
|
+
["5 * * 5 *", :next, "2012/06/06 06:03:22", "2013/05/01 00:05:00"],
|
75
|
+
["* 5 * 5 *", :next, "2012/04/06 04:03:22", "2012/05/01 05:00:00"],
|
76
|
+
["* 5 * 5 *", :next, "2012/05/06 05:03:22", "2012/05/06 05:04:00"],
|
77
|
+
["* 5 * 5 *", :next, "2012/06/06 05:03:22", "2013/05/01 05:00:00"],
|
78
|
+
["* 5 * 5 *", :next, "2012/05/31 05:58:22", "2012/05/31 05:59:00"],
|
79
|
+
["* 5 * 5 *", :next, "2012/05/31 05:59:22", "2013/05/01 05:00:00"],
|
80
|
+
["* * 5 5 *", :next, "2012/05/04 05:59:22", "2012/05/05 00:00:00"],
|
81
|
+
["* * 5 5 *", :next, "2012/05/05 05:59:22", "2012/05/05 06:00:00"],
|
82
|
+
["* * 5 5 *", :next, "2012/05/06 05:59:22", "2013/05/05 00:00:00"],
|
83
|
+
["* * 5 5 *", :next, "2012/05/05 23:59:22", "2013/05/05 00:00:00"],
|
84
|
+
["* * 5 5 *", :next, "2012/05/05 23:58:22", "2012/05/05 23:59:00"],
|
85
|
+
["5 5 * 5 *", :next, "2012/05/05 05:05:22", "2012/05/06 05:05:00"],
|
86
|
+
["5 5 * 5 *", :next, "2012/05/31 05:05:22", "2013/05/01 05:05:00"],
|
87
|
+
["5 * 5 5 *", :next, "2012/05/31 05:05:22", "2013/05/05 00:05:00"],
|
88
|
+
["5 * 5 5 *", :next, "2012/04/31 05:05:22", "2012/05/05 00:05:00"],
|
89
|
+
["10 10 29 2 *", :next, "2007/01/01 05:05:59", "2008/02/29 10:10:00"],
|
90
|
+
["10 10 29 2 *", :next, "2008/01/01 05:05:59", "2008/02/29 10:10:00"],
|
91
|
+
["10 10 29 2 *", :next, "2008/02/29 10:10:59", "2012/02/29 10:10:00"],
|
92
|
+
|
93
|
+
["* * * * 3", :next, "2012/10/07 10:10:59", "2012/10/10 00:00:00"],
|
94
|
+
["* * * * 3", :next, "2012/10/10 10:10:59", "2012/10/10 10:11:00"],
|
95
|
+
["* * * * 3", :next, "2012/10/10 23:59:59", "2012/10/17 00:00:00"],
|
96
|
+
["* * * * 3", :next, "2012/10/11 13:59:59", "2012/10/17 00:00:00"],
|
97
|
+
["* * * * 3", :next, "2012/10/31 23:59:59", "2012/11/07 00:00:00"],
|
98
|
+
["* * * * 3", :next, "2012/12/27 23:59:59", "2013/01/02 00:00:00"],
|
99
|
+
["* * * * 3", :next, "2012/07/31 23:59:59", "2012/08/01 00:00:00"],
|
100
|
+
["* * * * */3", :next, "2012/07/01 23:59:59", "2012/07/04 00:00:00"],
|
101
|
+
["* * * * */3", :next, "2012/07/02 23:59:59", "2012/07/04 00:00:00"],
|
102
|
+
["* * * * */3", :next, "2012/07/03 23:59:59", "2012/07/04 00:00:00"],
|
103
|
+
["* * * * */3", :next, "2012/07/04 23:59:59", "2012/07/07 00:00:00"],
|
104
|
+
["* * * * */3", :next, "2012/07/05 23:59:59", "2012/07/07 00:00:00"],
|
105
|
+
["* * * * */3", :next, "2012/07/06 23:59:59", "2012/07/07 00:00:00"],
|
106
|
+
["* * * * */3", :next, "2012/07/07 23:59:59", "2012/07/08 00:00:00"],
|
107
|
+
["10 * * * */3", :next, "2012/07/07 23:59:59", "2012/07/08 00:10:00"],
|
108
|
+
["* 10 * * */3", :next, "2012/07/07 23:59:59", "2012/07/08 10:00:00"],
|
109
|
+
["* * * 10 */3", :next, "2012/07/07 23:59:59", "2012/10/03 00:00:00"],
|
110
|
+
|
111
|
+
["* * 29 2 5", :next, "2011/07/07 23:59:59", "2012/02/03 00:00:00"],
|
112
|
+
["* * 29 2 5", :next, "2012/02/03 23:59:59", "2012/02/10 00:00:00"],
|
113
|
+
["* * 29 2 5", :next, "2012/02/24 23:59:59", "2012/02/29 00:00:00"],
|
114
|
+
["* * 29 2 5", :next, "2012/02/29 23:59:59", "2013/02/01 00:00:00"],
|
115
|
+
]
|
116
|
+
|
117
|
+
test_data.each do |cron_time_format, target_method, now_date, get_date|
|
118
|
+
result_date = KronParser.parse(cron_time_format).send(target_method, Time.parse(now_date))
|
119
|
+
result_date.should == Time.parse(get_date)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kronparser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- mechamogera
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &2160350020 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2160350020
|
25
|
+
description: datermine next scheduled crontab run
|
26
|
+
email:
|
27
|
+
- ''
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- README.md
|
35
|
+
- Rakefile
|
36
|
+
- kronparser.gemspec
|
37
|
+
- lib/kronparser.rb
|
38
|
+
- lib/kronparser/simple_process.rb
|
39
|
+
- lib/kronparser/version.rb
|
40
|
+
- spec/kronparser_spec.rb
|
41
|
+
- spec/spec_helper.rb
|
42
|
+
homepage: https://github.com/mechamogera/kronparser
|
43
|
+
licenses: []
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project: kronparser
|
62
|
+
rubygems_version: 1.8.17
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: datermine next scheduled crontab run
|
66
|
+
test_files:
|
67
|
+
- spec/kronparser_spec.rb
|
68
|
+
- spec/spec_helper.rb
|