Class: UtilityPack::DateTimeHelpers::HourMinSec

Inherits:
Time
  • Object
show all
Defined in:
lib/utility_pack/datetime.rb

Instance Method Summary collapse

Instance Method Details

#<=>(other) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/utility_pack/datetime.rb', line 6

def <=>(other)
  # only compare based on hour, minutes, and seconds (leave date portion off)
  self_seconds = (self.hour * (60 * 60)) + (self.min * 60) + self.sec
  other_seconds = (other.hour * (60 * 60)) + (other.min * 60) + other.sec

  if self_seconds < other_seconds
    return -1
  elsif self_seconds == other_seconds
      return 0
  else
    return 1
  end
end