timerizer 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/timerizer.rb +12 -3
- metadata +1 -1
data/lib/timerizer.rb
CHANGED
@@ -65,6 +65,15 @@ class RelativeTime
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
+
# Compares two RelativeTimes to determine if they are equal
|
69
|
+
# @param [RelativeTime] time The RelativeTime to compare
|
70
|
+
# @return [Boolean] True if both RelativeTimes are equal
|
71
|
+
# @note Be weary of rounding; this method compares both RelativeTimes' base units
|
72
|
+
def ==(time)
|
73
|
+
raise ArgumentError unless time.is_a?(RelativeTime)
|
74
|
+
return @seconds == time.get(:seconds) && @months == time.get(:months)
|
75
|
+
end
|
76
|
+
|
68
77
|
# Return the number of base units in a RelativeTime.
|
69
78
|
# @param [Symbol] unit The unit to return, either :seconds or :months
|
70
79
|
# @return [Fixnum] The requested unit count
|
@@ -293,7 +302,7 @@ class Time
|
|
293
302
|
# @see Time#since
|
294
303
|
# @see Time#between
|
295
304
|
def self.until(time)
|
296
|
-
raise TimeIsInThePastException if Time.now > time
|
305
|
+
raise TimeIsInThePastException if Time.now > time.to_time
|
297
306
|
|
298
307
|
Time.between(Time.now, time)
|
299
308
|
end
|
@@ -308,7 +317,7 @@ class Time
|
|
308
317
|
# @see Time#since
|
309
318
|
# @see Time#between
|
310
319
|
def self.since(time)
|
311
|
-
raise TimeIsInTheFutureException if time > Time.now
|
320
|
+
raise TimeIsInTheFutureException if time.to_time > Time.now
|
312
321
|
|
313
322
|
Time.between(Time.now, time)
|
314
323
|
end
|
@@ -324,7 +333,7 @@ class Time
|
|
324
333
|
# @see Time#until
|
325
334
|
# @see Time#since
|
326
335
|
def self.between(time1, time2)
|
327
|
-
time_between = (time2 - time1).abs
|
336
|
+
time_between = (time2.to_time - time1.to_time).abs
|
328
337
|
|
329
338
|
RelativeTime.new(time_between.round)
|
330
339
|
end
|