class Cassandra::Time

Represents a Cassandra time type.

Constants

NANOSECONDS_IN_DAY

@private

NANOSECONDS_IN_HOUR

@private

NANOSECONDS_IN_MILISECOND

@private

NANOSECONDS_IN_MINUTE

@private

NANOSECONDS_IN_SECOND

@private

Public Class Methods

new(nanoseconds = 0) click to toggle source

@private

   # File lib/cassandra/time.rb
36 def initialize(nanoseconds = 0)
37   if nanoseconds < 0 && nanoseconds > NANOSECONDS_IN_DAY - 1
38     raise ::ArgumentError, 'value must be between 0 and ' \
39                            "#{NANOSECONDS_IN_DAY}, #{value.inspect} given"
40   end
41 
42   @nanoseconds = nanoseconds
43 end

Public Instance Methods

<=>(other) click to toggle source

@private

   # File lib/cassandra/time.rb
92 def <=>(other)
93   other <=> nanoseconds
94 end
==(other)
Alias for: eql?
eql?(other) click to toggle source

@private

   # File lib/cassandra/time.rb
86 def eql?(other)
87   other.is_a?(Time) && other.to_nanoseconds == @nanoseconds
88 end
Also aliased as: ==
hash() click to toggle source

@private

    # File lib/cassandra/time.rb
 97 def hash
 98   # Modeled after http://developer.android.com/reference/java/lang/Object.html#writing_hashCode, but
 99   # simplified since only one field participates in the hash.
100   @hash ||= 31 * 17 + @nanoseconds.hash
101 end
hours() click to toggle source

@return [Integer] an integer between 0 and 24, the number of full hours

since midnight that this time represents
   # File lib/cassandra/time.rb
47 def hours
48   @nanoseconds / NANOSECONDS_IN_HOUR
49 end
miliseconds() click to toggle source

@return [Integer] an integer between 0 and 60, the number of full

miliseconds since the last full second that this time represents
   # File lib/cassandra/time.rb
67 def miliseconds
68   (@nanoseconds -
69       (hours * NANOSECONDS_IN_HOUR) -
70       (minutes * NANOSECONDS_IN_MINUTE) -
71       (seconds * NANOSECONDS_IN_SECOND)) / NANOSECONDS_IN_MILISECOND
72 end
minutes() click to toggle source

@return [Integer] an integer between 0 and 60, the number of full minutes

since the last full hour that this time represents
   # File lib/cassandra/time.rb
53 def minutes
54   (@nanoseconds - (hours * NANOSECONDS_IN_HOUR)) / NANOSECONDS_IN_MINUTE
55 end
seconds() click to toggle source

@return [Integer] an integer between 0 and 60, the number of full seconds

since the last full minutes that this time represents
   # File lib/cassandra/time.rb
59 def seconds
60   (@nanoseconds -
61       (hours * NANOSECONDS_IN_HOUR) -
62       (minutes * NANOSECONDS_IN_MINUTE)) / NANOSECONDS_IN_SECOND
63 end
to_nanoseconds() click to toggle source

@return [Integer] an integer between 0 and 86400000000000, the number of

nanoseconds since midnight that this time represents
   # File lib/cassandra/time.rb
81 def to_nanoseconds
82   @nanoseconds
83 end
to_s() click to toggle source

@return [String] a ā€œ%H:%M%S.%3Nā€ formatted time string

   # File lib/cassandra/time.rb
75 def to_s
76   format('%.2d:%.2d:%.2d.%.3d', hours, minutes, seconds, miliseconds)
77 end