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

Returns an integer between 0 and 24, the number of full hours since midnight that this time represents.

Returns:

  • (Integer)

    an integer between 0 and 24, the number of full hours since midnight that this time represents



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

def hours
  @nanoseconds / NANOSECONDS_IN_HOUR
end

#milisecondsInteger

Returns an integer between 0 and 60, the number of full miliseconds since the last full second that this time represents.

Returns:

  • (Integer)

    an integer between 0 and 60, the number of full miliseconds since the last full second that this time represents



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

Returns an integer between 0 and 60, the number of full minutes since the last full hour that this time represents.

Returns:

  • (Integer)

    an integer between 0 and 60, the number of full minutes since the last full hour that this time represents



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

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

#secondsInteger

Returns an integer between 0 and 60, the number of full seconds since the last full minutes that this time represents.

Returns:

  • (Integer)

    an integer between 0 and 60, the number of full seconds since the last full minutes that this time represents



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

Returns an integer between 0 and 86400000000000, the number of nanoseconds since midnight that this time represents.

Returns:

  • (Integer)

    an integer between 0 and 86400000000000, the number of nanoseconds since midnight that this time represents



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

def to_nanoseconds
  @nanoseconds
end

#to_sString

Returns a "%H:%M%S.%3N" formatted time string.

Returns:

  • (String)

    a "%H:%M%S.%3N" formatted time string



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

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