Class: Neo4j::Driver::Types::LocalDateTime
Overview
Bolt LocalDateTime — a wall-clock datetime with no timezone
(java.time.LocalDateTime). Stored as the wire-format pair
(epoch_seconds, nanoseconds), where epoch_seconds encodes the
wall-clock components as if they were UTC — so the value reads the
same regardless of the host TZ.
There is deliberately no #to_time: a zone-less value cannot become a
zoned Ruby Time without inventing a zone, and every serious datetime
library refuses that implicit conversion (Java's LocalDateTime forces
.atZone/.atOffset; Python yields a naive datetime). Read the fields via
the component getters instead.
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
TemporalValue::NANOS_PER_DAY, TemporalValue::NANOS_PER_HOUR, TemporalValue::NANOS_PER_MINUTE, TemporalValue::NANOS_PER_SECOND
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#<=>, #==, #hash, #significant
Constructor Details
#initialize(epoch_seconds, nanoseconds) ⇒ LocalDateTime
Returns a new instance of LocalDateTime.
30
31
32
33
|
# File 'lib/neo4j/driver/types/local_date_time.rb', line 30
def initialize(epoch_seconds, nanoseconds)
@epoch_seconds = epoch_seconds
@nanoseconds = nanoseconds
end
|
Instance Attribute Details
#epoch_seconds ⇒ Object
Returns the value of attribute epoch_seconds.
26
27
28
|
# File 'lib/neo4j/driver/types/local_date_time.rb', line 26
def epoch_seconds
@epoch_seconds
end
|
#nanoseconds ⇒ Object
Returns the value of attribute nanoseconds.
26
27
28
|
# File 'lib/neo4j/driver/types/local_date_time.rb', line 26
def nanoseconds
@nanoseconds
end
|
Class Method Details
.from_epoch(epoch_seconds, nanoseconds) ⇒ Object
35
|
# File 'lib/neo4j/driver/types/local_date_time.rb', line 35
def self.from_epoch(epoch_seconds, nanoseconds) = new(epoch_seconds, nanoseconds)
|
.from_time(time) ⇒ Object
Store the Time's wall clock (its date and time-of-day in its own
zone), dropping the zone. We read that wall clock off the instant
using the offset the Time already carries — we never invent a zone,
so from_time(t) and from_time(t.utc) differ (they show different
clocks). epoch_seconds encodes it as-if-UTC per the class contract.
42
43
44
|
# File 'lib/neo4j/driver/types/local_date_time.rb', line 42
def self.from_time(time)
new(time.to_i + time.utc_offset, time.nsec)
end
|
.parse(string) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/neo4j/driver/types/local_date_time.rb', line 46
def self.parse(string)
naive = string.sub(/[Z+-]\d{2}:?\d{2}?$/, '')
time = PARSE_FORMATS.lazy.filter_map do |fmt|
::Time.strptime(naive, fmt)
rescue StandardError
nil
end.first
raise ArgumentError, "Invalid LocalDateTime format: #{string}" unless time
from_time(time)
end
|
.significant_fields ⇒ Object
28
|
# File 'lib/neo4j/driver/types/local_date_time.rb', line 28
def self.significant_fields = %i[epoch_seconds nanoseconds]
|
Instance Method Details
#+(other) ⇒ Object
Add a numeric or ActiveSupport::Duration. A wall clock has no DST,
so this is plain second arithmetic; sub-second precision preserved.
#day ⇒ Object
61
|
# File 'lib/neo4j/driver/types/local_date_time.rb', line 61
def day = wall_clock.day
|
#hour ⇒ Object
62
|
# File 'lib/neo4j/driver/types/local_date_time.rb', line 62
def hour = wall_clock.hour
|
#minute ⇒ Object
63
|
# File 'lib/neo4j/driver/types/local_date_time.rb', line 63
def minute = wall_clock.min
|
#month ⇒ Object
60
|
# File 'lib/neo4j/driver/types/local_date_time.rb', line 60
def month = wall_clock.month
|
#nanosecond ⇒ Object
65
|
# File 'lib/neo4j/driver/types/local_date_time.rb', line 65
def nanosecond = @nanoseconds
|
#second ⇒ Object
64
|
# File 'lib/neo4j/driver/types/local_date_time.rb', line 64
def second = wall_clock.sec
|
#to_s ⇒ Object
75
76
77
|
# File 'lib/neo4j/driver/types/local_date_time.rb', line 75
def to_s
wall_clock.strftime('%Y-%m-%d %H:%M:%S.%N')
end
|
#year ⇒ Object
59
|
# File 'lib/neo4j/driver/types/local_date_time.rb', line 59
def year = wall_clock.year
|