Skip to content

Commit bba5f51

Browse files
author
Antoine Augusti
committed
Every to_s always return seconds #22
1 parent c799256 commit bba5f51

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/zhong/every.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def initialize(period)
2020

2121
def to_s
2222
EVERY_KEYWORDS.to_a.reverse.each do |friendly, period|
23-
next unless @period % period == 0
23+
next unless @period.to_i % period.to_i == 0
2424

2525
rem = @period / period
2626

test/test_every.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ def test_string_week
7777
assert_equal time_in_day(0, 0, 7, 10), every.next_at(time_in_day(0, 0, 0, 10))
7878
end
7979

80+
def test_to_s
81+
assert_equal "3 minutes", Zhong::Every.parse(3.minute).to_s
82+
assert_equal "3 hours", Zhong::Every.parse(3.hour).to_s
83+
assert_equal "1 hour", Zhong::Every.parse(1.hour).to_s
84+
assert_equal "3 days", Zhong::Every.parse(3.day).to_s
85+
assert_equal "3 weeks", Zhong::Every.parse(3.week).to_s
86+
assert_equal "3 months", Zhong::Every.parse(3.month).to_s
87+
assert_equal "1 month", Zhong::Every.parse(1.month).to_s
88+
assert_equal "3 years", Zhong::Every.parse(3.year).to_s
89+
assert_equal "3 decades", Zhong::Every.parse(30.years).to_s
90+
end
91+
8092
def test_invalid_string_foo
8193
assert_raises Zhong::Every::FailedToParse do
8294
Zhong::Every.parse("foo")

0 commit comments

Comments
 (0)