Class: Cassandra::Time

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/cassandra/time.rb

Overview

Represents a Cassandra time type.

Instance Method Summary collapse

Instance Method Details

#hoursInteger



47
48
49
# File 'lib/cassandra/time.rb', line 47

def hours
  @nanoseconds / NANOSECONDS_IN_HOUR
end

#milisecondsInteger



67
68
69
70
71
72
# File 'lib/cassandra/time.rb', line 67

def miliseconds
  (@nanoseconds -
      (hours * NANOSECONDS_IN_HOUR) -
      (minutes * NANOSECONDS_IN_MINUTE) -
      (seconds * NANOSECONDS_IN_SECOND)) / NANOSECONDS_IN_MILISECOND
end

#minutesInteger



53
54
55
# File 'lib/cassandra/time.rb', line 53

def minutes
  (@nanoseconds - (hours * NANOSECONDS_IN_HOUR)) / NANOSECONDS_IN_MINUTE
end

#secondsInteger



59
60
61
62
63
# File 'lib/cassandra/time.rb', line 59

def seconds
  (@nanoseconds -
      (hours * NANOSECONDS_IN_HOUR) -
      (minutes * NANOSECONDS_IN_MINUTE)) / NANOSECONDS_IN_SECOND
end

#to_nanosecondsInteger



81
82
83
# File 'lib/cassandra/time.rb', line 81

def to_nanoseconds
  @nanoseconds
end

#to_sString



75
76
77
# File 'lib/cassandra/time.rb', line 75

def to_s
  format('%.2d:%.2d:%.2d.%.3d', hours, minutes, seconds, miliseconds)
end