Class: Java::Date

Inherits:
SimpleDelegator
  • Object
show all
Extended by:
JavaObject
Defined in:
lib/javaobs.rb

Overview

The custom serialization of the Java Date class

Instance Method Summary collapse

Methods included from JavaObject

javaClass

Constructor Details

#initializeDate

Returns a new instance of Date.



108
109
110
# File 'lib/javaobs.rb', line 108

def initialize
  super(Time)
end

Instance Method Details

#dataObject

Get the data in the form needed for the Java date serialization.



126
127
128
129
# File 'lib/javaobs.rb', line 126

def data
  t = __getobj__.tv_sec * 1000 + __getobj__.tv_usec / 1000
  [t].pack("Q")
end

#time=(time) ⇒ Object

Set the time with a Time object or a Java binary serialized date.



114
115
116
117
118
119
120
121
122
123
# File 'lib/javaobs.rb', line 114

def time=(time)
  case time
  when Time
    __setobj__(time)
    
  when String
    t, = time.unpack("Q")
    __setobj__(Time.at(t / 1000, (t % 1000) * 1000))
  end
end