Class: Time

Inherits:
Object show all
Defined in:
lib/to-javascript/encoders/time.rb

Instance Method Summary collapse

Instance Method Details

#to_js(options = nil) ⇒ Object

Returns a Javascript string to create a Date object of the same time.

Example:

Time.utc(2005,2,1,15,15,10).to_js
# => "new Date(2005/02/01 15:15:10 +0000)"


7
8
9
# File 'lib/to-javascript/encoders/time.rb', line 7

def to_js(options = nil)
  ActiveSupport::JS::Code.new "new Date('#{strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)}')"
end