Class: Neo4j::Driver::Types::LocalTime
- Inherits:
-
TemporalValue
- Object
- TemporalValue
- Neo4j::Driver::Types::LocalTime
- Defined in:
- lib/neo4j/driver/types/local_time.rb
Overview
Bolt LocalTime — time of day without timezone, stored as nanoseconds since midnight.
Constant Summary
Constants inherited from TemporalValue
TemporalValue::NANOS_PER_DAY, TemporalValue::NANOS_PER_HOUR, TemporalValue::NANOS_PER_MINUTE, TemporalValue::NANOS_PER_SECOND
Instance Attribute Summary collapse
-
#nanoseconds ⇒ Object
readonly
Returns the value of attribute nanoseconds.
Class Method Summary collapse
- .from_nanos(nanoseconds) ⇒ Object
-
.from_time(time) ⇒ Object
Build from a Ruby Time, taking its displayed wall clock (so the host zone / .utc of the Time decides which time-of-day is captured).
-
.parse(string) ⇒ Object
Accepts "12:34:56.123456789" or any string containing such a time component (so a full datetime works too — we just take the time fields).
- .significant_fields ⇒ Object
Instance Method Summary collapse
-
#+(other) ⇒ Object
Add a numeric or ActiveSupport::Duration.
- #hour ⇒ Object
-
#initialize(nanoseconds) ⇒ LocalTime
constructor
A new instance of LocalTime.
- #minute ⇒ Object
- #nanosecond ⇒ Object
- #second ⇒ Object
- #to_s ⇒ Object
Methods inherited from TemporalValue
#<=>, #==, #hash, #significant
Constructor Details
#initialize(nanoseconds) ⇒ LocalTime
Returns a new instance of LocalTime.
13 14 15 |
# File 'lib/neo4j/driver/types/local_time.rb', line 13 def initialize(nanoseconds) @nanoseconds = nanoseconds % NANOS_PER_DAY end |
Instance Attribute Details
#nanoseconds ⇒ Object (readonly)
Returns the value of attribute nanoseconds.
9 10 11 |
# File 'lib/neo4j/driver/types/local_time.rb', line 9 def nanoseconds @nanoseconds end |
Class Method Details
.from_nanos(nanoseconds) ⇒ Object
17 |
# File 'lib/neo4j/driver/types/local_time.rb', line 17 def self.from_nanos(nanoseconds) = new(nanoseconds) |
.from_time(time) ⇒ Object
Build from a Ruby Time, taking its displayed wall clock (so the host zone / .utc of the Time decides which time-of-day is captured). Mirrors LocalDateTime.from_time.
22 23 24 25 |
# File 'lib/neo4j/driver/types/local_time.rb', line 22 def self.from_time(time) new(time.hour * NANOS_PER_HOUR + time.min * NANOS_PER_MINUTE + time.sec * NANOS_PER_SECOND + time.nsec) end |
.parse(string) ⇒ Object
Accepts "12:34:56.123456789" or any string containing such a time component (so a full datetime works too — we just take the time fields).
30 31 32 33 34 35 |
# File 'lib/neo4j/driver/types/local_time.rb', line 30 def self.parse(string) match = string.match(/(\d{1,2}):(\d{2})(?::(\d{2})(?:\.(\d+))?)?/) raise ArgumentError, "Invalid LocalTime format: #{string}" unless match new(parse_nanos(match[1].to_i, match[2].to_i, (match[3] || 0).to_i, match[4] || '0')) end |
.significant_fields ⇒ Object
11 |
# File 'lib/neo4j/driver/types/local_time.rb', line 11 def self.significant_fields = %i[nanoseconds] |
Instance Method Details
#+(other) ⇒ Object
Add a numeric or ActiveSupport::Duration. Sub-second precision preserved by going through to_f (NOT to_i, which dropped 0.5s).
52 53 54 |
# File 'lib/neo4j/driver/types/local_time.rb', line 52 def +(other) self.class.new(@nanoseconds + (other.to_f * NANOS_PER_SECOND).round) end |
#hour ⇒ Object
45 |
# File 'lib/neo4j/driver/types/local_time.rb', line 45 def hour = (@nanoseconds / NANOS_PER_HOUR) % 24 |
#minute ⇒ Object
46 |
# File 'lib/neo4j/driver/types/local_time.rb', line 46 def minute = (@nanoseconds / NANOS_PER_MINUTE) % 60 |
#nanosecond ⇒ Object
48 |
# File 'lib/neo4j/driver/types/local_time.rb', line 48 def nanosecond = @nanoseconds % NANOS_PER_SECOND |
#second ⇒ Object
47 |
# File 'lib/neo4j/driver/types/local_time.rb', line 47 def second = (@nanoseconds / NANOS_PER_SECOND) % 60 |
#to_s ⇒ Object
56 57 58 |
# File 'lib/neo4j/driver/types/local_time.rb', line 56 def to_s format('%02d:%02d:%02d.%09d', hour, minute, second, nanosecond) end |