ruby on rails - How to make Jbuilder to always return times in UTC? -
I have an app where a user presents many dates and times without timing information. Obtains, interprets them as a dataset in the Pacific region, and saves them in the database in UTC. Then the controller gives a JSON built with JBilder that contains these datasets. I want to return these datasets to UTC, but not to change each of them explicitly for UTC. Is there a way to assign this conversion to Jbuilder globally?
Here is some sample code to give an example of the question:
# ActiveRecord has a default configuration, i.e. UTC time.US_Zone ('Pacific Time (US & Canada) ') P = Party.New (: start_at = & gt; "2014-07-27 15:00") p.save end Jbuilder.encode do | Json | Json.started_at p.started_at.utc # = & gt; "{\" Start_at \ ": \" 2014-07-27 T-22: 00: 00.000Z \ "}" #include .. TC # = & gt; "{\" Start_at \ ": \" 2014-07-27T 15: 00: 00,000-07: 00 \ "}" Termination
How to return datasets to Zabulder ( Basically the Pacific Time Zone in UTC to add .utc
to each field explicitly)
Comments
Post a Comment