Rails gives you the possibility to include a field in your tables with the date in wich a record has been updated: updated-at. Well, I can access this filed via xml (I''m developing an Ajax application) so I have it in plain text form and looks something like this: 2008-07-05T19:47:32+02:00 I would like to parse this text into a Javascript Date object like this: Date.parse(''2008-07-05T19:47:32+02:00'') // DOESN''T WORK But before I resort to write (and then test) my own parser, I would like to know if there''s a built in parser for it in Javascript or in some extern library or, at least, the name for this particular format so I can Google it. Thanks. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Abel wrote:> Rails gives you the possibility to include a field in your tables with > the date in wich a record has been updated: updated-at. Well, I can > access this filed via xml (I''m developing an Ajax application) so I > have it in plain text form and looks something like this: > > 2008-07-05T19:47:32+02:00 > > I would like to parse this text into a Javascript Date object like > this: > > Date.parse(''2008-07-05T19:47:32+02:00'') // DOESN''T WORK > > But before I resort to write (and then test) my own parser, I would > like to know if there''s a built in parser for it in Javascript or in > some extern library or, at least, the name for this particular format > so I can Google it. > > Thanks.Hi Abel. If I were facing this dilemma, I would add a method on the model that returns the date in the format that you need it: def updated_at_js updated_at.strftime(<some format>) end Then call to_xml like this: p = Person.find_by_id(params[:id]) p.to_xml :methods => :updated_at_js so the properly formatted date is included in the xml packet. Then just use that one in your JS. Peace, Phillip -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks Phillip, that''s a wonderful idea. I didn''t know how to use the strftime method, but I found a workaround that''s working nicely: On the server I format the date like this: (Model) def updated_at_utc updated_at.to_s # returns date in the same format Javascript recognizes. Example: Fri May 23 20:52:39 +0200 2008 end (Controller) def search @ads = MY SEARCH format.xml { render :xml => @ads.to_xml(:methods => [:created_at_utc, :updated_at_utc])} end And this is how you parse the date in Javascript: (application.js) Date.prototype parseUTC = function(number_of_seconds) { return Date(0).setTime(numbre_of_seconds); }; To use it: (any Javascript in the app) var fetched_date = FETCH THE DATE USING XML, AJAX... var my_date = Date.parseUTC(fetched_date); Hope it will be of help to someone in the future. On Jul 6, 2:35 am, Phillip Koebbe <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Abel wrote: > > Rails gives you the possibility to include a field in your tables with > > the date in wich a record has been updated: updated-at. Well, I can > > access this filed via xml (I''m developing an Ajax application) so I > > have it in plain text form and looks something like this: > > > 2008-07-05T19:47:32+02:00 > > > I would like to parse this text into a Javascript Date object like > > this: > > > Date.parse(''2008-07-05T19:47:32+02:00'') // DOESN''T WORK > > > But before I resort to write (and then test) my own parser, I would > > like to know if there''s a built in parser for it in Javascript or in > > some extern library or, at least, the name for this particular format > > so I can Google it. > > > Thanks. > > Hi Abel. If I were facing this dilemma, I would add a method on the > model that returns the date in the format that you need it: > > def updated_at_js > updated_at.strftime(<some format>) > end > > Then call to_xml like this: > > p = Person.find_by_id(params[:id]) > p.to_xml :methods => :updated_at_js > > so the properly formatted date is included in the xml packet. Then just > use that one in your JS. > > Peace, > Phillip > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Abel wrote:> I didn''t know how to use the strftime method, but I found a workaround > that''s working nicely:http://www.ruby-doc.org/core-1.8.6/classes/Time.html#M000297 Glad you got it all working! Peace, Phillip -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---