chronic_cron 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3b5058b12c2cb781f5788a5aef3de5f34b405d26
4
+ data.tar.gz: 6e71c3ca5e7dd59b04ab7644706c3769b7c95911
5
+ SHA512:
6
+ metadata.gz: 0ee877393bb0fdb6937ceeed1eae95cd1d1c320c25987ef0bea48a5fd05767b6737f77c47835970fda8e069b41b6165ab5b2bb5645cde8a66230785c2e90a90a
7
+ data.tar.gz: 787220c0fa7e8634dc7b5230ad2a2f57a1da83b10938b23a458b0d1cb77cf73af98a760920202cb5d140a28e2e5a5e82cc2d535820dff2dca9cfb5cba1f9a9f2
checksums.yaml.gz.sig ADDED
@@ -0,0 +1 @@
1
+ �]��E9*� u�Z����[&��-���1ɡ��BV3�.�ّ�^�׶6ܾK�Id� �p���_� ��������ӛ����TU�6����1ԗ�ZpJL�*#t��ǾX�b���"h����֣�V3��xŪ��{∸L�v���x�����iq�|�������Uٛ�'��x�Y#P��RYy�����1_@�� �����cy����;���mױm�C{�;Xp}>AM�2�f!��Lӡ������?�C�
data.tar.gz.sig CHANGED
Binary file
data/lib/chronic_cron.rb CHANGED
@@ -5,6 +5,10 @@
5
5
  require 'date'
6
6
  require 'time'
7
7
 
8
+ MINUTE = 60
9
+ HOUR = MINUTE * 60
10
+ DAY = HOUR * 24
11
+
8
12
  class Array
9
13
 
10
14
  def inflate()
@@ -23,17 +27,17 @@ class ChronicCron
23
27
  day.to_i <= last_day.day
24
28
  end
25
29
 
26
- def self.parse(object)
30
+ def self.parse(object, now=Time.now)
27
31
 
28
32
  raw_a = object.is_a?(String) ? object.split : object
29
33
  raw_a << '*' if raw_a.length <= 5 # add the year?
30
34
 
31
- units = Time.now.to_a.values_at(1..4) + [nil, Time.now.year]
35
+ units = now.to_a.values_at(1..4) + [nil, now.year]
32
36
 
33
37
  procs = {
34
- min: lambda{|x, interval| x += (interval * 60).to_i},
35
- hour: lambda{|x, interval| x += (interval * 60 * 60).to_i},
36
- day: lambda{|x, interval| x += (interval * 60 * 60 * 24).to_i},
38
+ min: lambda{|x, interval| x += (interval * MINUTE).to_i},
39
+ hour: lambda{|x, interval| x += (interval * HOUR).to_i},
40
+ day: lambda{|x, interval| x += (interval * DAY).to_i},
37
41
  month: lambda{|x, interval|
38
42
  date = x.to_a.values_at(1..5)
39
43
  interval.times { date[3].succ! }
@@ -68,10 +72,10 @@ class ChronicCron
68
72
  end
69
73
 
70
74
  raw_date = raw_units.map.with_index {|x,i| dt[i].call(x) }
71
-
75
+
72
76
  # expand the repeater
73
77
 
74
- ceil = {min: 60, hour: 23, day: 31, month: 12}.values
78
+ ceil = {min: MINUTE, hour: 23, day: 31, month: 12}.values
75
79
 
76
80
  if repeaters.any? then
77
81
  repeaters.each_with_index do |x,i|
@@ -86,7 +90,7 @@ class ChronicCron
86
90
  end
87
91
 
88
92
  dates = raw_date.inflate
89
-
93
+
90
94
  a = dates.map do |date|
91
95
  d = date.map{|x| x ? x.clone : nil}
92
96
  wday, year = d.pop(2)
@@ -95,22 +99,22 @@ class ChronicCron
95
99
  next unless day_valid? d.reverse.take 3
96
100
  t = Time.parse("%s-%s-%s %s:%s" % d.reverse)
97
101
 
98
- if t < Time.now and wday and wday != t.wday then
99
- d[2], d[3] = Time.now.to_a.values_at(3,4).map(&:to_s)
102
+ if t < now and wday and wday != t.wday then
103
+ d[2], d[3] = now.to_a.values_at(3,4).map(&:to_s)
100
104
  t = Time.parse("%s-%s-%s %s:%s" % d.reverse)
101
- t += (60 * 60 * 24) until t.wday == wday.to_i
105
+ t += DAY until t.wday == wday.to_i
102
106
  end
103
107
 
104
108
  i = 3
105
- while t < Time.now and i >= 0 and raw_a[i][/\*/]
106
- d[i] = Time.now.to_a[i+1].to_s
109
+ while t < now and i >= 0 and raw_a[i][/\*/]
110
+ d[i] = now.to_a[i+1].to_s
107
111
  t = Time.parse("%s-%s-%s %s:%s" % d.reverse)
108
112
  i -= 1
109
113
  end
110
114
 
111
- if t < Time.now then
115
+ if t < now then
112
116
 
113
- if t.month < Time.now.month and raw_a[4] == '*' then
117
+ if t.month < now.month and raw_a[4] == '*' then
114
118
  # increment the year
115
119
  d[4].succ!
116
120
  t = Time.parse("%s-%s-%s %s:%s" % d.reverse)
@@ -119,7 +123,7 @@ class ChronicCron
119
123
  d[4].succ!
120
124
  t = Time.parse("%s-%s-%s %s:%s" % d.reverse)
121
125
  end
122
- elsif t.day < Time.now.day and raw_a[3] == '*' then
126
+ elsif t.day < now.day and raw_a[3] == '*' then
123
127
  # increment the month
124
128
  if d[3].to_i <= 11 then
125
129
  d[3].succ!
@@ -128,25 +132,25 @@ class ChronicCron
128
132
  d[4].succ!
129
133
  end
130
134
  t = Time.parse("%s-%s-%s %s:%s" % d.reverse)
131
- elsif t.hour < Time.now.hour and raw_a[2] == '*' then
135
+ elsif t.hour < now.hour and raw_a[2] == '*' then
132
136
  # increment the day
133
- t += 60 * 60 * 24 * ((Time.now.day - d[2].to_i) + 1)
134
- elsif t.min < Time.now.min and raw_a[1] == '*' then
137
+ t += DAY * ((now.day - d[2].to_i) + 1)
138
+ elsif t.min < now.min and raw_a[1] == '*' then
135
139
  # increment the hour
136
- t += 60 * 60 * ((Time.now.hour - d[1].to_i) + 1)
140
+ t += HOUR * ((now.hour - d[1].to_i) + 1)
137
141
  elsif raw_a[0] == '*' then
138
142
  # increment the minute
139
- t += 60 * ((Time.now.min - d[0].to_i) + 1)
143
+ t += MINUTE * ((now.min - d[0].to_i) + 1)
140
144
  t = procs.values[i].call(t, repeaters[i].to_i) if repeaters[i]
141
145
  end
142
146
 
143
147
  end
144
148
 
145
149
  if wday then
146
- t += (60 * 60 * 24) until t.wday == wday.to_i
150
+ t += DAY until t.wday == wday.to_i
147
151
  end
148
152
 
149
- if t <= Time.now and repeaters.any? then
153
+ if t <= now and repeaters.any? then
150
154
 
151
155
  repeaters.each_with_index do |x,i|
152
156
  if x then
metadata CHANGED
@@ -1,14 +1,13 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: chronic_cron
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.1.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
6
5
  platform: ruby
7
- authors:
6
+ authors:
8
7
  - James Robertson
9
8
  autorequire:
10
9
  bindir: bin
11
- cert_chain:
10
+ cert_chain:
12
11
  - |
13
12
  -----BEGIN CERTIFICATE-----
14
13
  MIIDRDCCAiygAwIBAgIBADANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
@@ -30,46 +29,36 @@ cert_chain:
30
29
  aYYwh4InyS/QZr4LG0nh0TuYVP5vwm1cCSlLlo4dlv7bl7Q4y815j70z8O4oUrT8
31
30
  5oSIzmlVDEDmwAibYqdf+aHqmum1mkYW
32
31
  -----END CERTIFICATE-----
33
-
34
- date: 2013-02-06 00:00:00 Z
32
+ date: 2013-07-06 00:00:00.000000000 Z
35
33
  dependencies: []
36
-
37
34
  description:
38
35
  email:
39
36
  executables: []
40
-
41
37
  extensions: []
42
-
43
38
  extra_rdoc_files: []
44
-
45
- files:
39
+ files:
46
40
  - lib/chronic_cron.rb
47
41
  homepage:
48
42
  licenses: []
49
-
43
+ metadata: {}
50
44
  post_install_message:
51
45
  rdoc_options: []
52
-
53
- require_paths:
46
+ require_paths:
54
47
  - lib
55
- required_ruby_version: !ruby/object:Gem::Requirement
56
- none: false
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- version: "0"
61
- required_rubygems_version: !ruby/object:Gem::Requirement
62
- none: false
63
- requirements:
64
- - - ">="
65
- - !ruby/object:Gem::Version
66
- version: "0"
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
67
58
  requirements: []
68
-
69
59
  rubyforge_project:
70
- rubygems_version: 1.8.23
60
+ rubygems_version: 2.0.0.rc.2
71
61
  signing_key:
72
- specification_version: 3
62
+ specification_version: 4
73
63
  summary: chronic_cron
74
64
  test_files: []
75
-
metadata.gz.sig CHANGED
Binary file