Loading ...
Sorry, an error occurred while loading the content.
 

Re: YUI 2.4.0 YAHOO.lang.JSON date question

Expand Messages
  • y_lsmith
    ... Pass a filter function as the second argument to JSON.parse. This function will be passed each key:value
    Message 1 of 2 , Dec 21, 2007
      --- In ydn-javascript@yahoogroups.com, "kimandrew" <kimandrew@...> wrote:
      >
      > When date is stringified and then parsed, it becomes string instead of
      > date object.

      Pass a filter function  as the second argument to JSON.parse.  This function will be passed each key:value pair after the initial data transformation is done.

      var rebuildDates = function (key,val) {
        if (key === 'myDateField') {
          var bits = val.split(/\D/);
          bits[1] = (bits[1]|0) - 1;
          val = new Date();
          val.setUTCFullYear.apply(val,bits);
          val.setUTCHours.apply(val,bits.slice(3));
          return val;
        }
      }

      var myData = JSON.parse(myJSONString, rebuildDates);

      Hope this helps,
      Luke
    Your message has been successfully submitted and would be delivered to recipients shortly.