Class: Hotwire::Response::Json::DateTime

Inherits:
Object
  • Object
show all
Defined in:
lib/hotwire/response/json.rb

Overview

Utility class to produce a JSON rendering of datetimes compatible with what the Wire APIs expect ( a Javascript date object )

Instance Method Summary collapse

Constructor Details

#initialize(datetime) ⇒ DateTime

Returns a new instance of DateTime.



84
85
86
# File 'lib/hotwire/response/json.rb', line 84

def initialize(datetime)
  @datetime = datetime
end

Instance Method Details

#to_json(options = nil) ⇒ Object



88
89
90
# File 'lib/hotwire/response/json.rb', line 88

def to_json(options=nil)
  @datetime.nil? ? "" : "new Date(#{@datetime.year}, #{@datetime.month-1}, #{@datetime.day}, #{@datetime.hour}, #{@datetime.min}, #{@datetime.sec})"
end