Skip to content

Commit

Permalink
Merge 0a40156 into 02ae589
Browse files Browse the repository at this point in the history
  • Loading branch information
rossta committed Jul 4, 2016
2 parents 02ae589 + 0a40156 commit 35de8e3
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 40 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: ruby
rvm:
- 2.1
- 2.2
- 2.3.0
- 2.1.10
- 2.2.5
- 2.3.1
before_install: gem install bundler -v 1.11.2
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Rake::TestTask.new(:spec) do |t|
t.libs << "spec"
t.libs << "lib"
t.test_files = FileList["spec/**/*_spec.rb"]
t.warning = false
end

task test: :spec
Expand Down
5 changes: 2 additions & 3 deletions lib/montrose/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ module Utils
def as_time(time)
return nil unless time

case
when time.is_a?(String)
if time.is_a?(String)
parse_time(time)
when time.respond_to?(:to_time)
elsif time.respond_to?(:to_time)
time.to_time
else
Array(time).flat_map { |d| as_time(d) }
Expand Down
8 changes: 4 additions & 4 deletions montrose.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = ">= 2.1.0"

spec.add_dependency "activesupport"
spec.add_dependency "activesupport", "~> 4.0"

spec.add_development_dependency "bundler", "~> 1.10"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "minitest", "~> 5.8"
spec.add_development_dependency "rake", "~> 11.0"
spec.add_development_dependency "minitest", "~> 5.9"
spec.add_development_dependency "m", "~> 1.4"
spec.add_development_dependency "rubocop", "~> 0.36"
spec.add_development_dependency "rubocop", "~> 0.41"
spec.add_development_dependency "timecop"
end
10 changes: 5 additions & 5 deletions spec/montrose/recurrence_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,19 @@
recurrence = new_recurrence(every: :week, on: "tuesday", at: "5:00", starts: "2016-06-23")

recurrence.events.take(3).must_pair_with [
Time.local(2016, 6, 28, 5, 00),
Time.local(2016, 7, 5, 5, 00),
Time.local(2016, 7, 12, 5, 00)
Time.local(2016, 6, 28, 5, 0o0),
Time.local(2016, 7, 5, 5, 0o0),
Time.local(2016, 7, 12, 5, 0o0)
]
end

it "multiple at values" do
recurrence = new_recurrence(every: :day, at: ["7:00am", "3:30pm"])

recurrence.events.take(3).must_pair_with [
Time.local(2015, 9, 1, 7, 00),
Time.local(2015, 9, 1, 7, 0o0),
Time.local(2015, 9, 1, 15, 30),
Time.local(2015, 9, 2, 7, 00)
Time.local(2015, 9, 2, 7, 0o0)
]
end
end
Expand Down
75 changes: 50 additions & 25 deletions spec/rfc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
every: :year,
month: :january,
day: [:sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday],
until: ends_at)
until: ends_at
)

dates = recurrence.events.to_a

Expand Down Expand Up @@ -127,7 +128,8 @@
every: :week,
day: [:tuesday, :thursday],
starts: Date.parse("September 1, 2015"),
until: Date.parse("October 5, 2015"))
until: Date.parse("October 5, 2015")
)

expected_dates = cherry_pick 2015 => { 9 => [1, 3, 8, 10, 15, 17, 22, 24, 29], 10 => [1] }
dates = recurrence.events.to_a
Expand All @@ -141,7 +143,8 @@
every: :week,
day: [:tuesday, :thursday],
starts: Date.parse("Nov 22, 2015"),
total: 10)
total: 10
)

expected_dates = cherry_pick 2015 => { 11 => [24, 26], 12 => [1, 3, 8, 10, 15, 17, 22, 24] }
dates = recurrence.events.to_a
Expand All @@ -158,7 +161,8 @@
day: [:monday, :wednesday, :friday],
starts: Date.parse("September 1, 2015"),
until: Date.parse("December 23, 2015"),
interval: 2)
interval: 2
)

# TODO: Non-interval start date not supported
# September 1 is omitted for now: need to implement OR interval grouping
Expand All @@ -181,7 +185,8 @@
starts: Date.parse("September 1, 2015"),
until: Date.parse("December 23, 2015"),
total: 8,
interval: 2)
interval: 2
)

expected_dates = cherry_pick 2015 => { 9 => [1, 3, 15, 17, 29], 10 => [1, 13, 15] }

Expand All @@ -195,7 +200,8 @@
recurrence = new_recurrence(
every: :month,
day: { friday: [1] },
total: 10)
total: 10
)

expected_dates = cherry_pick(
2015 => { 9 => [4], 10 => [2], 11 => [6], 12 => [4] },
Expand All @@ -212,7 +218,8 @@
recurrence = new_recurrence(
every: :month,
day: { friday: [1] },
until: Date.parse("December 23, 2015"))
until: Date.parse("December 23, 2015")
)

expected_dates = cherry_pick(
2015 => { 9 => [4], 10 => [2], 11 => [6], 12 => [4] }
Expand All @@ -233,7 +240,8 @@
starts: starts,
day: { sunday: [1, -1] },
interval: 2,
total: 10)
total: 10
)

expected_dates = cherry_pick(
2015 => { 9 => [6, 27], 11 => [1, 29] },
Expand All @@ -250,7 +258,8 @@
recurrence = new_recurrence(
every: :month,
day: { monday: [-2] },
total: 6)
total: 6
)

expected_dates = cherry_pick(
2015 => { 9 => [21], 10 => [19], 11 => [23], 12 => [21] },
Expand All @@ -268,7 +277,8 @@

expected_dates = cherry_pick(
2015 => { 9 => [28], 10 => [29], 11 => [28], 12 => [29] },
2016 => { 1 => [29], 2 => [27] }).map { |t| t + 12.hours }
2016 => { 1 => [29], 2 => [27] }
).map { |t| t + 12.hours }

dates = recurrence.events.take(6)

Expand All @@ -281,7 +291,8 @@

expected_dates = cherry_pick(
2015 => { 9 => [2, 15], 10 => [2, 15], 11 => [2, 15], 12 => [2, 15] },
2016 => { 1 => [2, 15] }).map { |t| t + 12.hours }
2016 => { 1 => [2, 15] }
).map { |t| t + 12.hours }

dates = recurrence.events.to_a

Expand All @@ -295,7 +306,8 @@

expected_dates = cherry_pick(
2015 => { 9 => [30], 10 => [1, 31], 11 => [1, 30], 12 => [1, 31] },
2016 => { 1 => [1, 31], 2 => [1] })
2016 => { 1 => [1, 31], 2 => [1] }
)

dates = recurrence.events.to_a

Expand All @@ -309,7 +321,8 @@

expected_dates = cherry_pick(
2015 => { 9 => [10, 11, 12, 13, 14, 15] },
2017 => { 3 => [10, 11, 12, 13] })
2017 => { 3 => [10, 11, 12, 13] }
)

dates = recurrence.events.to_a

Expand All @@ -323,7 +336,8 @@

expected_dates = cherry_pick(
2015 => { 9 => [1, 8, 15, 22, 29], 11 => [3, 10, 17, 24] },
2016 => { 1 => [5, 12, 19, 26], 3 => [1, 8, 15, 22, 29] })
2016 => { 1 => [5, 12, 19, 26], 3 => [1, 8, 15, 22, 29] }
)

dates = recurrence.events.take(expected_dates.size)

Expand All @@ -338,7 +352,8 @@
2017 => { 6 => [1], 7 => [1] },
2018 => { 6 => [1], 7 => [1] },
2019 => { 6 => [1], 7 => [1] },
2020 => { 6 => [1], 7 => [1] }).map { |i| i + 12.hours }
2020 => { 6 => [1], 7 => [1] }
).map { |i| i + 12.hours }

dates = recurrence.events.to_a

Expand All @@ -353,13 +368,15 @@
starts: starts,
month: [:january, :february, :march],
interval: 2,
total: 10)
total: 10
)

expected_dates = cherry_pick(
2015 => { 3 => [10] },
2017 => { 1 => [10], 2 => [10], 3 => [10] },
2019 => { 1 => [10], 2 => [10], 3 => [10] },
2021 => { 1 => [10], 2 => [10], 3 => [10] })
2021 => { 1 => [10], 2 => [10], 3 => [10] }
)

dates = recurrence.events.to_a

Expand All @@ -371,13 +388,15 @@
recurrence = new_recurrence(
every: :year,
yday: [1, 100, 200],
total: 10)
total: 10
)

expected_dates = cherry_pick(
2016 => { 1 => [1], 4 => [9], 7 => [18] },
2017 => { 1 => [1], 4 => [10], 7 => [19] },
2018 => { 1 => [1], 4 => [10], 7 => [19] },
2019 => { 1 => [1] }).map { |i| i + 12.hours }
2019 => { 1 => [1] }
).map { |i| i + 12.hours }

dates = recurrence.events.to_a

Expand All @@ -391,7 +410,8 @@
expected_dates = cherry_pick(
2016 => { 5 => [16] },
2017 => { 5 => [15] },
2018 => { 5 => [14] }).map { |i| i + 12.hours }
2018 => { 5 => [14] }
).map { |i| i + 12.hours }

dates = recurrence.events.take(3)
dates.must_pair_with expected_dates
Expand All @@ -403,7 +423,8 @@
expected_dates = cherry_pick(
2016 => { 5 => [16] },
2017 => { 5 => [15] },
2018 => { 5 => [14] }).map { |i| i + 12.hours }
2018 => { 5 => [14] }
).map { |i| i + 12.hours }

dates = recurrence.events.take(3)

Expand All @@ -417,7 +438,8 @@
expected_dates = cherry_pick(
2016 => { 3 => [10, 17, 24, 31] },
2017 => { 3 => [2, 9, 16, 23, 30] },
2018 => { 3 => [1, 8, 15, 22, 29] }).map { |i| i + 12.hours }
2018 => { 3 => [1, 8, 15, 22, 29] }
).map { |i| i + 12.hours }

dates = recurrence.events.take(expected_dates.size)
dates.must_pair_with expected_dates
Expand All @@ -429,7 +451,8 @@
expected_dates = cherry_pick(
2016 => { 6 => [2, 9, 16, 23, 30], 7 => [7, 14, 21, 28], 8 => [4, 11, 18, 25] },
2017 => { 6 => [1, 8, 15, 22, 29], 7 => [6, 13, 20, 27], 8 => [3, 10, 17, 24, 31] },
2018 => { 6 => [7, 14, 21, 28], 7 => [5, 12, 19, 26], 8 => [2, 9, 16, 23, 30] }).map { |i| i + 12.hours }
2018 => { 6 => [7, 14, 21, 28], 7 => [5, 12, 19, 26], 8 => [2, 9, 16, 23, 30] }
).map { |i| i + 12.hours }

dates = recurrence.events.take(expected_dates.size)

Expand All @@ -443,7 +466,8 @@
2015 => { 11 => [13] },
2016 => { 5 => [13] },
2017 => { 1 => [13], 10 => [13] },
2018 => { 4 => [13], 7 => [13] }).map { |i| i + 12.hours }
2018 => { 4 => [13], 7 => [13] }
).map { |i| i + 12.hours }

dates = recurrence.events.take(expected_dates.size)

Expand All @@ -470,7 +494,8 @@
expected_dates = cherry_pick(
2016 => { 11 => [8] },
2020 => { 11 => [3] },
2024 => { 11 => [5] })
2024 => { 11 => [5] }
)

dates = recurrence.events.take(expected_dates.size)

Expand Down

0 comments on commit 35de8e3

Please sign in to comment.