File tree 2 files changed +14
-4
lines changed
2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,11 @@ describe Lucky::TimeHelpers do
30
30
view.distance_of_time_in_words(from_time, from_time + 2 .years).should eq " over 2 years"
31
31
view.distance_of_time_in_words(from_time, from_time + 10 .years).should eq " almost 10 years"
32
32
end
33
+
34
+ it " takes a Time::Span" do
35
+ span = 4 .minutes
36
+ view.distance_of_time_in_words(span).should eq " 4 minutes"
37
+ end
33
38
end
34
39
35
40
describe " time_ago_in_words" do
Original file line number Diff line number Diff line change @@ -16,10 +16,15 @@ module Lucky::TimeHelpers
16
16
# # => "almost 42 years"
17
17
# ```
18
18
def distance_of_time_in_words (from : Time , to : Time ) : String
19
- minutes = (to - from).minutes
20
- seconds = (to - from).seconds
21
- hours = (to - from).hours
22
- days = (to - from).days
19
+ distance_of_time_in_words(to - from)
20
+ end
21
+
22
+ # :ditto:
23
+ def distance_of_time_in_words (span : Time ::Span ) : String
24
+ minutes = span.minutes
25
+ seconds = span.seconds
26
+ hours = span.hours
27
+ days = span.days
23
28
24
29
return distance_in_days(days) if days != 0
25
30
return distance_in_hours(hours, minutes) if hours != 0
You can’t perform that action at this time.
0 commit comments