parse-cron 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cron_parser.rb +13 -8
- data/lib/parse-cron.rb +2 -0
- data/lib/parse-cron/version.rb +1 -1
- data/spec/cron_parser_spec.rb +9 -0
- metadata +33 -52
data/lib/cron_parser.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'set'
|
1
2
|
#
|
2
3
|
# Parses cron expressions and computes the next occurence of the "job"
|
3
4
|
#
|
@@ -5,17 +6,20 @@ class CronParser
|
|
5
6
|
# internal "mutable" time representation
|
6
7
|
class InternalTime
|
7
8
|
attr_accessor :year, :month, :day, :hour, :min
|
9
|
+
attr_accessor :time_source
|
8
10
|
|
9
|
-
def initialize(time)
|
11
|
+
def initialize(time,time_source = Time)
|
10
12
|
@year = time.year
|
11
13
|
@month = time.month
|
12
14
|
@day = time.day
|
13
15
|
@hour = time.hour
|
14
16
|
@min = time.min
|
17
|
+
|
18
|
+
@time_source = time_source
|
15
19
|
end
|
16
20
|
|
17
21
|
def to_time
|
18
|
-
|
22
|
+
time_source.local(@year, @month, @day, @hour, @min, 0)
|
19
23
|
end
|
20
24
|
|
21
25
|
def inspect
|
@@ -46,21 +50,22 @@ class CronParser
|
|
46
50
|
"sat" => "6"
|
47
51
|
}
|
48
52
|
|
49
|
-
def initialize(source)
|
53
|
+
def initialize(source,time_source = Time)
|
50
54
|
@source = source
|
55
|
+
@time_source = time_source
|
51
56
|
end
|
52
57
|
|
53
58
|
|
54
59
|
# returns the next occurence after the given date
|
55
|
-
def next(now =
|
56
|
-
t = InternalTime.new(now)
|
60
|
+
def next(now = @time_source.now)
|
61
|
+
t = InternalTime.new(now,@time_source)
|
57
62
|
|
58
63
|
unless time_specs[:month][0].include?(t.month)
|
59
64
|
nudge_month(t)
|
60
65
|
t.day = 0
|
61
66
|
end
|
62
67
|
|
63
|
-
unless
|
68
|
+
unless interpolate_weekdays(t.year, t.month)[0].include?(t.day)
|
64
69
|
nudge_date(t)
|
65
70
|
t.hour = -1
|
66
71
|
end
|
@@ -76,8 +81,8 @@ class CronParser
|
|
76
81
|
end
|
77
82
|
|
78
83
|
# returns the last occurence before the given date
|
79
|
-
def last(now =
|
80
|
-
t = InternalTime.new(now)
|
84
|
+
def last(now = @time_source.now)
|
85
|
+
t = InternalTime.new(now,@time_source)
|
81
86
|
|
82
87
|
unless time_specs[:month][0].include?(t.month)
|
83
88
|
nudge_month(t, :last)
|
data/lib/parse-cron.rb
ADDED
data/lib/parse-cron/version.rb
CHANGED
data/spec/cron_parser_spec.rb
CHANGED
@@ -41,6 +41,7 @@ describe "CronParser#next" do
|
|
41
41
|
["0 0 1 1 *", "2010-04-15 10:15", "2011-01-01 00:00"],
|
42
42
|
["0 0 * * 1", "2011-08-01 00:00", "2011-08-08 00:00"],
|
43
43
|
["0 0 * * 1", "2011-07-25 00:00", "2011-08-01 00:00"],
|
44
|
+
["45 23 7 3 *", "2011-01-01 00:00", "2011-03-07 23:45"],
|
44
45
|
].each do |line, now, expected_next|
|
45
46
|
it "should return #{expected_next} for '#{line}' when now is #{now}" do
|
46
47
|
now = parse_date(now)
|
@@ -80,3 +81,11 @@ describe "CronParser#last" do
|
|
80
81
|
end
|
81
82
|
end
|
82
83
|
end
|
84
|
+
|
85
|
+
describe "time source" do
|
86
|
+
it "should use an alternate specified time source" do
|
87
|
+
ExtendedTime = Class.new(Time)
|
88
|
+
ExtendedTime.should_receive(:local).once
|
89
|
+
CronParser.new("* * * * *",ExtendedTime).next
|
90
|
+
end
|
91
|
+
end
|
metadata
CHANGED
@@ -1,93 +1,74 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: parse-cron
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 1
|
10
|
-
version: 0.1.1
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Michael Siebert
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2013-01-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: rspec
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
18
|
+
requirements:
|
27
19
|
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
hash: 23
|
30
|
-
segments:
|
31
|
-
- 2
|
32
|
-
- 6
|
33
|
-
- 0
|
20
|
+
- !ruby/object:Gem::Version
|
34
21
|
version: 2.6.0
|
35
22
|
type: :development
|
36
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.6.0
|
37
30
|
description: Parses cron expressions and calculates the next occurence
|
38
|
-
email:
|
31
|
+
email:
|
39
32
|
- siebertm85@googlemail.com
|
40
33
|
executables: []
|
41
|
-
|
42
34
|
extensions: []
|
43
|
-
|
44
35
|
extra_rdoc_files: []
|
45
|
-
|
46
|
-
files:
|
36
|
+
files:
|
47
37
|
- .gitignore
|
48
38
|
- .rspec
|
49
39
|
- Gemfile
|
50
40
|
- README
|
51
41
|
- Rakefile
|
52
42
|
- lib/cron_parser.rb
|
43
|
+
- lib/parse-cron.rb
|
53
44
|
- lib/parse-cron/version.rb
|
54
45
|
- parse-cron.gemspec
|
55
46
|
- spec/cron_parser_spec.rb
|
56
47
|
- spec/spec_helper.rb
|
57
|
-
has_rdoc: true
|
58
48
|
homepage: https://github.com/siebertm/parse-cron
|
59
49
|
licenses: []
|
60
|
-
|
61
50
|
post_install_message:
|
62
51
|
rdoc_options: []
|
63
|
-
|
64
|
-
require_paths:
|
52
|
+
require_paths:
|
65
53
|
- lib
|
66
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
55
|
none: false
|
68
|
-
requirements:
|
69
|
-
- -
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
|
72
|
-
|
73
|
-
- 0
|
74
|
-
version: "0"
|
75
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
61
|
none: false
|
77
|
-
requirements:
|
78
|
-
- -
|
79
|
-
- !ruby/object:Gem::Version
|
80
|
-
|
81
|
-
segments:
|
82
|
-
- 0
|
83
|
-
version: "0"
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
84
66
|
requirements: []
|
85
|
-
|
86
67
|
rubyforge_project: parse-cron
|
87
|
-
rubygems_version: 1.
|
68
|
+
rubygems_version: 1.8.23
|
88
69
|
signing_key:
|
89
70
|
specification_version: 3
|
90
71
|
summary: Parses cron expressions and calculates the next occurence
|
91
|
-
test_files:
|
72
|
+
test_files:
|
92
73
|
- spec/cron_parser_spec.rb
|
93
74
|
- spec/spec_helper.rb
|