Module: Neo4j::Driver::Internal::DurationNormalizer

Defined in:
lib/neo4j/driver/internal/duration_normalizer.rb

Class Method Summary collapse

Class Method Details

.milliseconds(duration) ⇒ Object



20
21
22
# File 'lib/neo4j/driver/internal/duration_normalizer.rb', line 20

def milliseconds(duration)
  duration&.in_milliseconds&.round
end

.normalize(object) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/neo4j/driver/internal/duration_normalizer.rb', line 8

def normalize(object)
  parts = object.parts.to_h
  parts.default = 0
  months_i, months_remainder_seconds = divmod(months(parts), ActiveSupport::Duration::SECONDS_PER_MONTH)
  months_days, months_remainder_seconds =
    months_remainder_seconds.divmod(ActiveSupport::Duration::SECONDS_PER_DAY)
  days_i, days_remainder_seconds = divmod(months_days + days(parts), ActiveSupport::Duration::SECONDS_PER_DAY)
  seconds_i, nonanoseconds = divmod(months_remainder_seconds + days_remainder_seconds + seconds(parts),
                                    1_000_000_000)
  [months_i, days_i, seconds_i, nonanoseconds.round]
end