Class: EventQ::SerializationProviders::JRuby::Oj::DateTimeWriter

Inherits:
AttributeWriter
  • Object
show all
Defined in:
lib/eventq_base/serialization_providers/jruby/oj/date_time_writer.rb

Instance Method Summary collapse

Methods inherited from AttributeWriter

descendants, exec

Instance Method Details

#exec(obj) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/eventq_base/serialization_providers/jruby/oj/date_time_writer.rb', line 9

def exec(obj)
  seconds = obj.strftime('%S%N')
  d = 1_000_000_000
  if seconds.start_with?('0')
    seconds[0] = ''
    d = 100_000_000
  end

  {
    '^O': 'DateTime',
    year: obj.year,
    month: obj.month,
    day: obj.day,
    hour: obj.hour,
    min: obj.min,
    sec: RationalWriter.new.exec(Rational(Integer(seconds), d)),
    offset: RationalWriter.new.exec(obj.offset),
    start: obj.start
  }
end

#valid?(obj) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/eventq_base/serialization_providers/jruby/oj/date_time_writer.rb', line 6

def valid?(obj)
  obj.is_a?(DateTime)
end