Skip to content

Commit 7d5e975

Browse files
committed
Merge pull request #255 from code-mancers/fix-issue-with-passing-time-format-to-active-support
Allow -1 arity in Occurrence#to_s to comply with ActiveSupport::TimeWithZone
2 parents 7b3450f + c9cffa9 commit 7d5e975

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lib/ice_cube/occurrence.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def to_time
8484
# time formats and is only used when ActiveSupport is available.
8585
#
8686
def to_s(format=nil)
87-
if format && to_time.public_method(:to_s).arity > 0
87+
if format && to_time.public_method(:to_s).arity != 0
8888
t0, t1 = start_time.to_s(format), end_time.to_s(format)
8989
else
9090
t0, t1 = start_time.to_s, end_time.to_s

spec/examples/occurrence_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@
2828
end
2929

3030
it "accepts a format option to comply with ActiveSupport" do
31-
occurrence = Occurrence.new(Time.now)
31+
require 'active_support/core_ext/time'
32+
time_now = Time.current
33+
occurrence = Occurrence.new(time_now)
3234

33-
expect { occurrence.to_s(:short) }.not_to raise_error
35+
expect(occurrence.to_s(:short)).to eq time_now.to_s(:short)
3436
end
3537
end
3638

0 commit comments

Comments
 (0)