cronex 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YmM2NjgwNmY4ZTEyMmIzYmIyYjg4YmZjYTZlN2IwZTc4ZGZiMzkwZg==
4
+ YmQ2ZjA4NDk0NTQ1NGJiZWVjOTIxZWFkMWE1N2Y2NGI5YmEwNzBkZA==
5
5
  data.tar.gz: !binary |-
6
- ZTg1NDIxYjM0MmFiZGUzZmRlODVjMDc3ZTljNzcwNzY4ZTViNDk5Ng==
6
+ ZTI0YjcxMmU3MzlkMDUzNmVhN2EyNGEzZjRlMjk4OWM5ODdhYWM0Nw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjMzYzUzNDEzMjcwNWE2NjcyNzBmYWVhY2RkZDM1NDY5MjhlNWFhMjA3MjYx
10
- ZTc3Mzk5YmMzM2VhNTAyZjAyYmM0ZmJjZDIyZjkwMTkxM2Q4YmM2MTA4NTc2
11
- MTdjOTk3NjM0MjMwNjVhZjA5OGIzZWJjODMzYmM3NTZlZGM4MjE=
9
+ ZmY5ODY1ZGIwODkyZDcyNTNlYmZiODY4ZTk3ZmQxOWE3ZDcyMWE5YzRlMWNm
10
+ MzllNjIxYmEyZTcwOWI0MWRjMjJmZThhZTIxOTQ2N2RiYzY5YzVmM2UzMjky
11
+ YTc2ZWU5ZTk5N2RkZjIzMTNkMzU3MDAzMzJkOTBjZWM0ODVkOTI=
12
12
  data.tar.gz: !binary |-
13
- MDc4MTgwMmQwYjZhYWFiNjFiNWE2MzJiMDkzMjAyZGMzZGZiMTMwODY3ODBk
14
- MjhhMmYyNDYxZGJkMTgzZmNiMGZiZmM4N2Q1MzIyMWE0Y2ZjMTgxZDQwNTAw
15
- MzA3Mjg0ZGE2MTA5M2I4YzdiMjhiZjdkY2Q5ZTBhY2MzYTY2OTY=
13
+ Y2IxZDRlOGRhOGE3NDkyOTYwODI1ZGY4N2QwNWRkMDM4ODJkZmI0OGU0ODUw
14
+ NTMxNWM1MDI4YWQ1OGM0M2RlZGRmZTI1ZWI1NjJjZWNhNDA5N2IxNjk2ODFj
15
+ OTU4ZTZiMmM3ZGY2ZWQ5OTEyOGYwN2E3ODgwYjg1NWY3NGY5OTM=
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ### [0.4.0] - 2016-11-28
2
+ * Fix handling leading zeros in numbers
3
+
1
4
  ### [0.3.0] - 2016-03-02
2
5
  * Add pt_BR translation
3
6
 
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 2'
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 = Integer(exp)
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, Integer(expression), 1).strftime('%B').downcase)
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)
@@ -1,7 +1,7 @@
1
1
  module Cronex
2
2
  class YearDescription < Description
3
3
  def single_item_description(expression)
4
- DateTime.new(Integer(expression)).strftime('%Y')
4
+ DateTime.new(Cronex::Utils.integer(expression)).strftime('%Y')
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 = Integer(match[0].gsub('W', ''))
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 emtpy' unless Cronex::Utils.present?(exp)
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
- Integer(str) rescue nil
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 = Integer(hour_expression)
36
+ hour = integer(hour_expression)
31
37
  period = hour >= 12 ? 'PM' : 'AM'
32
38
  hour -= 12 if hour > 12
33
- minute = Integer(minute_expression)
39
+ minute = integer(minute_expression)
34
40
  minute = format('%02d', minute)
35
41
  second = ''
36
- if Cronex::Utils.present?(second_expression)
37
- second = Integer(second_expression)
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)
@@ -1,3 +1,3 @@
1
1
  module Cronex
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -55,8 +55,22 @@ module Cronex
55
55
  end
56
56
  end
57
57
 
58
- it 'daily at time' do
59
- expect(desc('30 11 * * *')).to eq('At 11:30 AM')
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
- it 'daily at time' do
60
- expect(desc_pt_br('30 11 * * *')).to eq('Às 11:30 AM')
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.3.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-03-04 00:00:00.000000000 Z
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 2
109
+ - Apache-2.0
110
110
  metadata: {}
111
111
  post_install_message:
112
112
  rdoc_options: []