Class: Neo4j::Driver::Types::LocalDateTime
- Inherits:
-
TemporalValue
- Object
- TemporalValue
- Neo4j::Driver::Types::LocalDateTime
- Defined in:
- lib/neo4j/driver/types/local_date_time.rb
Overview
Bolt LocalDateTime — wall-clock datetime without timezone. Stored as the wire-format pair (epoch_seconds, nanoseconds), where epoch_seconds is the wall-clock components encoded as if they were UTC. Two LocalDateTimes representing the same wall-clock value always have the same field values regardless of the host TZ.
Constant Summary collapse
- PARSE_FORMATS =
[ '%Y-%m-%d %H:%M:%S.%N', '%Y-%m-%dT%H:%M:%S.%N', '%Y-%m-%d %H:%M:%S', '%Y-%m-%dT%H:%M:%S', '%Y-%m-%d %H:%M' ].freeze
Constants inherited from TemporalValue
TemporalValue::NANOS_PER_DAY, TemporalValue::NANOS_PER_HOUR, TemporalValue::NANOS_PER_MINUTE, TemporalValue::NANOS_PER_SECOND
Instance Attribute Summary collapse
-
#epoch_seconds ⇒ Object
readonly
Returns the value of attribute epoch_seconds.
-
#nanoseconds ⇒ Object
readonly
Returns the value of attribute nanoseconds.
Class Method Summary collapse
- .from_epoch(epoch_seconds, nanoseconds) ⇒ Object
- .from_time(time) ⇒ Object
- .parse(string) ⇒ Object
- .significant_fields ⇒ Object
Instance Method Summary collapse
-
#+(seconds) ⇒ Object
Add a numeric or ActiveSupport::Duration.
-
#initialize(epoch_seconds, nanoseconds) ⇒ LocalDateTime
constructor
A new instance of LocalDateTime.
- #to_s ⇒ Object
- #to_time ⇒ Object
Methods inherited from TemporalValue
#<=>, #==, #hash, #significant
Constructor Details
#initialize(epoch_seconds, nanoseconds) ⇒ LocalDateTime
Returns a new instance of LocalDateTime.
24 25 26 27 |
# File 'lib/neo4j/driver/types/local_date_time.rb', line 24 def initialize(epoch_seconds, nanoseconds) @epoch_seconds = epoch_seconds @nanoseconds = nanoseconds end |
Instance Attribute Details
#epoch_seconds ⇒ Object (readonly)
Returns the value of attribute epoch_seconds.
20 21 22 |
# File 'lib/neo4j/driver/types/local_date_time.rb', line 20 def epoch_seconds @epoch_seconds end |
#nanoseconds ⇒ Object (readonly)
Returns the value of attribute nanoseconds.
20 21 22 |
# File 'lib/neo4j/driver/types/local_date_time.rb', line 20 def nanoseconds @nanoseconds end |
Class Method Details
.from_epoch(epoch_seconds, nanoseconds) ⇒ Object
29 |
# File 'lib/neo4j/driver/types/local_date_time.rb', line 29 def self.from_epoch(epoch_seconds, nanoseconds) = new(epoch_seconds, nanoseconds) |
.from_time(time) ⇒ Object
31 32 33 |
# File 'lib/neo4j/driver/types/local_date_time.rb', line 31 def self.from_time(time) new(time.to_i, ((time.to_f - time.to_i) * NANOS_PER_SECOND).round) end |
.parse(string) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/neo4j/driver/types/local_date_time.rb', line 35 def self.parse(string) # Strip trailing timezone if present — naive datetime ignores it. naive = string.sub(/[Z+\-]\d{2}:?\d{2}?$/, '') time = PARSE_FORMATS.lazy.filter_map { |fmt| ::Time.strptime(naive, fmt) rescue nil }.first raise ArgumentError, "Invalid LocalDateTime format: #{string}" unless time from_time(::Time.utc(*time_components(time))) end |
.significant_fields ⇒ Object
22 |
# File 'lib/neo4j/driver/types/local_date_time.rb', line 22 def self.significant_fields = %i[epoch_seconds nanoseconds] |
Instance Method Details
#+(seconds) ⇒ Object
Add a numeric or ActiveSupport::Duration. Sub-second precision preserved by going through to_f.
54 55 56 |
# File 'lib/neo4j/driver/types/local_date_time.rb', line 54 def +(seconds) self.class.from_time(to_time + seconds.to_f) end |
#to_s ⇒ Object
58 59 60 |
# File 'lib/neo4j/driver/types/local_date_time.rb', line 58 def to_s to_time.strftime('%Y-%m-%d %H:%M:%S.%N') end |
#to_time ⇒ Object
48 49 50 |
# File 'lib/neo4j/driver/types/local_date_time.rb', line 48 def to_time ::Time.at(@epoch_seconds, @nanoseconds.to_i, :nanosecond) end |