montrose 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 84030dd2ad699d4db2bb62011fa41867964f9e56
4
- data.tar.gz: 00a3b299b80f0cdfc0659bee39ff7266d6275d24
3
+ metadata.gz: b5a8b52963ae6bea219f278406b83d675e619e52
4
+ data.tar.gz: f1be3f8c5ba5b6154ff9ada19429774bb130df41
5
5
  SHA512:
6
- metadata.gz: 9d1e5813fba6d74ecdd137e32e911ccfb5642d939c5732e2e302489a66e964ea239175d74c43a3c1d8ffad235c5131a09f773c9bf072d27b4a9569597f5a695d
7
- data.tar.gz: 7bd9adae17eff3af8f6cc2d17de785f1ec851856fb5196c54bd9799f99bd70e4c863b23af7f31abe783c920a30c39aedfeb252743e320f925303fc853803476f
6
+ metadata.gz: 52a9b066ba034e9985e6516485fecbaa1a3bd84f7b5aeb71bfda2ece9ffd421a37a69fdc57e7baf4cbf6e4818333cb6452a6f5f6d203863371416f791ce79c33
7
+ data.tar.gz: e055001efa95ea285de0bcc40bb7fd868041210bf4faef22103f3af190567f2b41fec3d138bf2da4a27588febc74abd11eb19d53d1240174cb1102094ee404e2
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  engines:
3
3
  bundler-audit:
4
- enabled: true
4
+ enabled: false
5
5
  duplication:
6
6
  enabled: true
7
7
  config:
@@ -2,6 +2,7 @@ AllCops:
2
2
  Exclude:
3
3
  - 'bin/**/*'
4
4
  - 'gemfiles/**/*'
5
+ - 'tmp/**/*'
5
6
  TargetRubyVersion: '2.1.0'
6
7
 
7
8
  Lint/HandleExceptions:
@@ -1,3 +1,9 @@
1
+ ### 0.8.1 - (2018-05-29)
2
+
3
+ * bug fixes
4
+ * Fixes interval comparisons for secondly, hourly, minutely by zeroing usec
5
+ for recurrence start and end times
6
+
1
7
  ### 0.8.0 - (2018-05-29)
2
8
 
3
9
  * enhancements
@@ -55,6 +55,16 @@ module Montrose
55
55
  def matches_interval?(time_diff)
56
56
  (time_diff % @interval).zero?
57
57
  end
58
+
59
+ def to_cron
60
+ raise "abstract"
61
+ end
62
+
63
+ protected
64
+
65
+ def interval_str
66
+ @interval != 1 ? "*/#{@interval}" : "*"
67
+ end
58
68
  end
59
69
  end
60
70
 
@@ -6,6 +6,10 @@ module Montrose
6
6
  def include?(time)
7
7
  matches_interval? time.to_date - @starts.to_date
8
8
  end
9
+
10
+ def to_cron
11
+ "#{@starts.min} #{@starts.hour} #{interval_str} * *"
12
+ end
9
13
  end
10
14
  end
11
15
  end
@@ -6,6 +6,10 @@ module Montrose
6
6
  def include?(time)
7
7
  matches_interval?((time - @starts) / 1.hour)
8
8
  end
9
+
10
+ def to_cron
11
+ "#{@starts.min} #{interval_str} * * *"
12
+ end
9
13
  end
10
14
  end
11
15
  end
@@ -6,6 +6,10 @@ module Montrose
6
6
  def include?(time)
7
7
  matches_interval?((time.month - @starts.month) + (time.year - @starts.year) * 12)
8
8
  end
9
+
10
+ def to_cron
11
+ "#{@starts.min} #{@starts.hour} #{@starts.day} #{interval_str} *"
12
+ end
9
13
  end
10
14
  end
11
15
  end
@@ -7,6 +7,11 @@ module Montrose
7
7
  (weeks_since_start(time) % @interval).zero?
8
8
  end
9
9
 
10
+ def to_cron
11
+ raise "Intervals unsupported" unless @interval == 1
12
+ "#{@starts.min} #{@starts.hour} * * #{@starts.wday}"
13
+ end
14
+
10
15
  private
11
16
 
12
17
  def weeks_since_start(time)
@@ -6,6 +6,11 @@ module Montrose
6
6
  def include?(time)
7
7
  matches_interval? time.year - @starts.year
8
8
  end
9
+
10
+ def to_cron
11
+ raise "Intervals unsupported" unless @interval == 1
12
+ "#{@starts.min} #{@starts.hour} #{@starts.day} #{@starts.month} *"
13
+ end
9
14
  end
10
15
  end
11
16
  end
@@ -32,6 +32,11 @@ module Montrose
32
32
  # @example Recurrence.default_until #=> <Date>
33
33
  #
34
34
  def default_until
35
+ ::Montrose::Utils.normalize_time determine_default_until
36
+ end
37
+
38
+ # private
39
+ def determine_default_until
35
40
  case @default_until
36
41
  when String
37
42
  ::Montrose::Utils.parse_time(@default_until)
@@ -47,6 +52,11 @@ module Montrose
47
52
  # @example Recurrence.default_starts #=> <Date>
48
53
  #
49
54
  def default_starts
55
+ ::Montrose::Utils.normalize_time determine_default_starts
56
+ end
57
+
58
+ # private
59
+ def determine_default_starts
50
60
  case @default_starts
51
61
  when String
52
62
  ::Montrose::Utils.parse_time(@default_starts)
@@ -156,11 +166,11 @@ module Montrose
156
166
  alias frequency= every=
157
167
 
158
168
  def starts=(time)
159
- @starts = as_time(time) || self.class.default_starts
169
+ @starts = normalize_time(as_time(time)) || default_starts
160
170
  end
161
171
 
162
172
  def until=(time)
163
- @until = as_time(time) || self.class.default_until
173
+ @until = normalize_time(as_time(time)) || default_until
164
174
  end
165
175
 
166
176
  def hour=(hours)
@@ -229,6 +239,10 @@ module Montrose
229
239
  self.class.default_starts
230
240
  end
231
241
 
242
+ def default_until
243
+ self.class.default_until
244
+ end
245
+
232
246
  def nested_map_arg(arg, &block)
233
247
  case arg
234
248
  when Hash
@@ -5,6 +5,7 @@ module Montrose
5
5
  module_function
6
6
 
7
7
  MONTHS = ::Date::MONTHNAMES
8
+
8
9
  DAYS = ::Date::DAYNAMES
9
10
 
10
11
  MAX_HOURS_IN_DAY = 24
@@ -26,6 +27,11 @@ module Montrose
26
27
  end
27
28
  end
28
29
 
30
+ # Recurrence at fractions of a second are not recognized
31
+ def normalize_time(time)
32
+ time && time.change(usec: 0)
33
+ end
34
+
29
35
  def as_date(time)
30
36
  as_time(time).to_date
31
37
  end
@@ -41,15 +47,17 @@ module Montrose
41
47
  def month_number(name)
42
48
  case name
43
49
  when Symbol, String
44
- MONTHS.index(name.to_s.titleize)
50
+ string = name.to_s
51
+ MONTHS.index(string.titleize) || month_number(to_index(string))
45
52
  when 1..12
46
53
  name
47
54
  end
48
55
  end
49
56
 
50
57
  def month_number!(name)
58
+ month_numbers = MONTHS.map.with_index { |_n, i| i.to_s }.slice(1, 12)
51
59
  month_number(name) or fail ConfigurationError,
52
- "Did not recognize month #{name}, must be one of #{MONTHS.inspect}"
60
+ "Did not recognize month #{name}, must be one of #{(MONTHS + month_numbers).inspect}"
53
61
  end
54
62
 
55
63
  def day_number(name)
@@ -57,15 +65,17 @@ module Montrose
57
65
  when 0..6
58
66
  name
59
67
  when Symbol, String
60
- DAYS.index(name.to_s.titleize)
68
+ string = name.to_s
69
+ DAYS.index(string.titleize) || day_number(to_index(string))
61
70
  when Array
62
71
  day_number name.first
63
72
  end
64
73
  end
65
74
 
66
75
  def day_number!(name)
76
+ day_numbers = DAYS.map.with_index { |_n, i| i.to_s }
67
77
  day_number(name) or fail ConfigurationError,
68
- "Did not recognize day #{name}, must be one of #{DAYS.inspect}"
78
+ "Did not recognize day #{name}, must be one of #{(DAYS + day_numbers).inspect}"
69
79
  end
70
80
 
71
81
  def days_in_month(month, year = current_time.year)
@@ -79,5 +89,11 @@ module Montrose
79
89
  def days_in_year(year)
80
90
  ::Montrose::Utils.days_in_month(2, year) + 337
81
91
  end
92
+
93
+ # Returns string.to_i only if string fully matches an integer
94
+ # otherwise ensures that return value won't match a valid index
95
+ def to_index(string)
96
+ string =~ %r{^\d+} ? string.to_i : -1
97
+ end
82
98
  end
83
99
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Montrose
4
- VERSION = "0.8.0"
4
+ VERSION = "0.8.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: montrose
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ross Kaffenberger
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-29 00:00:00.000000000 Z
11
+ date: 2018-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport