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 +4 -4
- data/.codeclimate.yml +1 -1
- data/.rubocop.yml +1 -0
- data/CHANGELOG.md +6 -0
- data/lib/montrose/frequency.rb +10 -0
- data/lib/montrose/frequency/daily.rb +4 -0
- data/lib/montrose/frequency/hourly.rb +4 -0
- data/lib/montrose/frequency/monthly.rb +4 -0
- data/lib/montrose/frequency/weekly.rb +5 -0
- data/lib/montrose/frequency/yearly.rb +5 -0
- data/lib/montrose/options.rb +16 -2
- data/lib/montrose/utils.rb +20 -4
- data/lib/montrose/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5a8b52963ae6bea219f278406b83d675e619e52
|
4
|
+
data.tar.gz: f1be3f8c5ba5b6154ff9ada19429774bb130df41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52a9b066ba034e9985e6516485fecbaa1a3bd84f7b5aeb71bfda2ece9ffd421a37a69fdc57e7baf4cbf6e4818333cb6452a6f5f6d203863371416f791ce79c33
|
7
|
+
data.tar.gz: e055001efa95ea285de0bcc40bb7fd868041210bf4faef22103f3af190567f2b41fec3d138bf2da4a27588febc74abd11eb19d53d1240174cb1102094ee404e2
|
data/.codeclimate.yml
CHANGED
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/lib/montrose/frequency.rb
CHANGED
data/lib/montrose/options.rb
CHANGED
@@ -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) ||
|
169
|
+
@starts = normalize_time(as_time(time)) || default_starts
|
160
170
|
end
|
161
171
|
|
162
172
|
def until=(time)
|
163
|
-
@until = as_time(time) ||
|
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
|
data/lib/montrose/utils.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
data/lib/montrose/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2018-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|