couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Anderson <jch...@apache.org>
Subject Re: json2.js (was Re: Time processing difference between 0.11.0b898401 and 0.11.0b903617)
Date Thu, 28 Jan 2010 07:32:57 GMT
On Wed, Jan 27, 2010 at 11:18 PM, Dirkjan Ochtman <djc.ochtman@gmail.com> wrote:
> On Thu, Jan 28, 2010 at 01:06, Chris Anderson <jchris@apache.org> wrote:
>> Is anyone else having trouble with views that emit Date objects in the
>> key (running latest trunk)?
>
> From memory, I wonder if emitting Date objects for
> JSON.stringification is valid according to the spec. I remember that
> the Firefox JSON implementation was somewhat restrictive about what it
> allowed to be passed to JSON.stringify at first, but I don't remember
> the exact rules.
>
> One difference I think is that in SpiderMonkey 1.7 you don't have
> built-in JSON (so you fall back to actual json2.js). I'm not sure
> exactly when that was introduced, but it might well be in SM 1.8.
>
> Cheers,
>
> Dirkjan
>

I think we can help here by defining some prototypes, like:


Date.prototype.toJSON = function(k) {
  var v = this;
  var f = function(n) { return n < 10 ? '0' + n : n };
  return '"' + v.getUTCFullYear()   + '-' +
             f(v.getUTCMonth() + 1) + '-' +
             f(v.getUTCDate())      + 'T' +
             f(v.getUTCHours())     + ':' +
             f(v.getUTCMinutes())   + ':' +
             f(v.getUTCSeconds())   + 'Z"';
}

David, you could even try defining this in your map view and see if that helps.

Chris

-- 
Chris Anderson
http://jchrisa.net
http://couch.io

Mime
View raw message