cronex 0.3.0 → 0.4.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 +8 -8
- data/CHANGELOG.md +3 -0
- data/cronex.gemspec +1 -1
- data/lib/cronex/description/day_of_week.rb +1 -1
- data/lib/cronex/description/month.rb +1 -1
- data/lib/cronex/description/year.rb +1 -1
- data/lib/cronex/exp_descriptor.rb +1 -1
- data/lib/cronex/parser.rb +1 -1
- data/lib/cronex/utils.rb +13 -7
- data/lib/cronex/version.rb +1 -1
- data/spec/exp_descriptor_en_spec.rb +16 -2
- data/spec/exp_descriptor_pt_BR_spec.rb +16 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YmQ2ZjA4NDk0NTQ1NGJiZWVjOTIxZWFkMWE1N2Y2NGI5YmEwNzBkZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTI0YjcxMmU3MzlkMDUzNmVhN2EyNGEzZjRlMjk4OWM5ODdhYWM0Nw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZmY5ODY1ZGIwODkyZDcyNTNlYmZiODY4ZTk3ZmQxOWE3ZDcyMWE5YzRlMWNm
|
10
|
+
MzllNjIxYmEyZTcwOWI0MWRjMjJmZThhZTIxOTQ2N2RiYzY5YzVmM2UzMjky
|
11
|
+
YTc2ZWU5ZTk5N2RkZjIzMTNkMzU3MDAzMzJkOTBjZWM0ODVkOTI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Y2IxZDRlOGRhOGE3NDkyOTYwODI1ZGY4N2QwNWRkMDM4ODJkZmI0OGU0ODUw
|
14
|
+
NTMxNWM1MDI4YWQ1OGM0M2RlZGRmZTI1ZWI1NjJjZWNhNDA5N2IxNjk2ODFj
|
15
|
+
OTU4ZTZiMmM3ZGY2ZWQ5OTEyOGYwN2E3ODgwYjg1NWY3NGY5OTM=
|
data/CHANGELOG.md
CHANGED
data/cronex.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
|
14
14
|
spec.required_ruby_version = '>= 1.9.3'
|
15
15
|
|
16
|
-
spec.license = 'Apache
|
16
|
+
spec.license = 'Apache-2.0'
|
17
17
|
|
18
18
|
spec.files = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR)
|
19
19
|
spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
|
@@ -9,7 +9,7 @@ module Cronex
|
|
9
9
|
end
|
10
10
|
|
11
11
|
if Cronex::Utils.number?(exp)
|
12
|
-
dow_num =
|
12
|
+
dow_num = Cronex::Utils.integer(exp)
|
13
13
|
zero_based_dow = options[:zero_based_dow]
|
14
14
|
invalid_dow = !zero_based_dow && dow_num <= 1
|
15
15
|
if invalid_dow || (zero_based_dow && dow_num == 0)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Cronex
|
2
2
|
class MonthDescription < Description
|
3
3
|
def single_item_description(expression)
|
4
|
-
resources.get(DateTime.new(Time.now.year,
|
4
|
+
resources.get(DateTime.new(Time.now.year, Cronex::Utils.integer(expression), 1).strftime('%B').downcase)
|
5
5
|
end
|
6
6
|
|
7
7
|
def interval_description_format(expression)
|
@@ -113,7 +113,7 @@ module Cronex
|
|
113
113
|
else
|
114
114
|
match = exp.match(/(\d{1,2}W)|(W\d{1,2})/)
|
115
115
|
if match
|
116
|
-
day_num =
|
116
|
+
day_num = Cronex::Utils.integer(match[0].gsub('W', ''))
|
117
117
|
day_str = day_num == 1 ? resources.get('first_weekday') : format(resources.get('weekday_nearest_day'), day_num)
|
118
118
|
description = format(', ' + resources.get('on_the_of_the_month'), day_str)
|
119
119
|
else
|
data/lib/cronex/parser.rb
CHANGED
@@ -20,7 +20,7 @@ module Cronex
|
|
20
20
|
def parse(exp = expression)
|
21
21
|
parsed_parts = Array.new(7, '')
|
22
22
|
|
23
|
-
fail ExpressionError, 'Error: Expression null or
|
23
|
+
fail ExpressionError, 'Error: Expression null or empty' unless Cronex::Utils.present?(exp)
|
24
24
|
parts = sanitize(exp).split(' ')
|
25
25
|
len = parts.size
|
26
26
|
|
data/lib/cronex/utils.rb
CHANGED
@@ -11,7 +11,13 @@ module Cronex
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def number?(str)
|
14
|
-
|
14
|
+
integer(str) rescue nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def integer(str)
|
18
|
+
# strip leading zeros in numbers to prevent '08', '09'
|
19
|
+
# from being treated as invalid octals
|
20
|
+
Integer(str.sub(/^0*(\d+)/, '\1'))
|
15
21
|
end
|
16
22
|
|
17
23
|
def day_of_week_name(number)
|
@@ -20,21 +26,21 @@ module Cronex
|
|
20
26
|
|
21
27
|
def format_minutes(minute_expression)
|
22
28
|
if minute_expression.include?(',')
|
23
|
-
minute_expression.split(',').map { |m| format('%02d', m) }.join(',')
|
29
|
+
minute_expression.split(',').map { |m| format('%02d', integer(m)) }.join(',')
|
24
30
|
else
|
25
|
-
format('%02d', minute_expression)
|
31
|
+
format('%02d', integer(minute_expression))
|
26
32
|
end
|
27
33
|
end
|
28
34
|
|
29
35
|
def format_time(hour_expression, minute_expression, second_expression = '')
|
30
|
-
hour =
|
36
|
+
hour = integer(hour_expression)
|
31
37
|
period = hour >= 12 ? 'PM' : 'AM'
|
32
38
|
hour -= 12 if hour > 12
|
33
|
-
minute =
|
39
|
+
minute = integer(minute_expression)
|
34
40
|
minute = format('%02d', minute)
|
35
41
|
second = ''
|
36
|
-
if
|
37
|
-
second =
|
42
|
+
if present?(second_expression)
|
43
|
+
second = integer(second_expression)
|
38
44
|
second = ':' + format('%02d', second)
|
39
45
|
end
|
40
46
|
format('%s:%s%s %s', hour, minute, second, period)
|
data/lib/cronex/version.rb
CHANGED
@@ -55,8 +55,22 @@ module Cronex
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
|
59
|
-
|
58
|
+
context 'daily:' do
|
59
|
+
it 'daily at /\d\d/:/\d\d/' do
|
60
|
+
expect(desc('30 11 * * *')).to eq('At 11:30 AM')
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'daily at /\d/:/\d/' do
|
64
|
+
expect(desc('9 8 * * *')).to eq('At 8:09 AM')
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'daily at /0[89]/:/0[89]/' do
|
68
|
+
expect(desc('09 08 * * *')).to eq('At 8:09 AM')
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'daily at /0[1-7]/ /0[1-7/' do
|
72
|
+
expect(desc('02 01 * * *')).to eq('At 1:02 AM')
|
73
|
+
end
|
60
74
|
end
|
61
75
|
|
62
76
|
context 'time of day certain days of week:' do
|
@@ -56,8 +56,22 @@ module Cronex
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
|
60
|
-
|
59
|
+
context 'daily:' do
|
60
|
+
it 'daily at /\d\d/:/\d\d/' do
|
61
|
+
expect(desc_pt_br('30 11 * * *')).to eq('Às 11:30 AM')
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'daily at /\d/:/\d/' do
|
65
|
+
expect(desc_pt_br('9 8 * * *')).to eq('Às 8:09 AM')
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'daily at /0[89]/:/0[89]/' do
|
69
|
+
expect(desc_pt_br('09 08 * * *')).to eq('Às 8:09 AM')
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'daily at /0[1-7]/ /0[1-7/' do
|
73
|
+
expect(desc_pt_br('02 01 * * *')).to eq('Às 1:02 AM')
|
74
|
+
end
|
61
75
|
end
|
62
76
|
|
63
77
|
context 'time of day certain days of week:' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cronex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrian Kazaku
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unicode
|
@@ -106,7 +106,7 @@ files:
|
|
106
106
|
- spec/spec_helper.rb
|
107
107
|
homepage: https://github.com/alpinweis/cronex
|
108
108
|
licenses:
|
109
|
-
- Apache
|
109
|
+
- Apache-2.0
|
110
110
|
metadata: {}
|
111
111
|
post_install_message:
|
112
112
|
rdoc_options: []
|