You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Dan Santner <da...@me.com> on 2014/01/29 23:13:46 UTC

confused about date parsing

My docs look something like this:

{
   "_id": "52e131783eb7a3.66772120",
   "_rev": "3-a734cbeb70ed87d5e84cd04c269149da",
   "billing": {
       "plan": "trial",
       "trialDays": 14,
       "trialEndDate": "2014-02-06 15:14:37",
       "nextDate": "",
       "stripeId": "",
       "cardId": "",
       "last4": "",
       "outstandingInvoice": "",
       "nextAmount": 0
   },
   "insightly": {
       "id": 50111485,
       "contactEmailId": 89501608,
       "contactPhoneId": 89501609
   },
 }

So I wrote a view to get all the docs where the trial end date has passed:

 "trialEnd": {
           "map": "function(doc){var outDoc = {}; 
                                var today = new Date(); 
				outDoc.trialEnd = Date.parse(doc.billing.trialEndDate); 
				outDoc.insightly = doc.insightly; 
				outDoc.expiryAge = today - outDoc.trialEnd; 
				emit(outDoc.expiryAge > 0,outDoc);}"
       }


And the parse obviously doesn't do what I think it does.  Help anyone?  I'm on bigcouch btw, but local couch 1.2 wouldn't do either.



Re: confused about date parsing

Posted by Dan Santner <da...@me.com>.
Alexander, your first response was very helpful.  Sorry I didn't search the archives first.  I get it now.

Thanks everyone.
Dan.
On Jan 29, 2014, at 4:57 PM, Alexander Shorin <kx...@gmail.com> wrote:

> On Thu, Jan 30, 2014 at 2:45 AM, Jens Alfke <je...@couchbase.com> wrote:
>> On Jan 29, 2014, at 2:17 PM, Alexander Shorin <kx...@gmail.com> wrote:
>> 
>>> On Thu, Jan 30, 2014 at 2:13 AM, Dan Santner <da...@me.com> wrote:
>>>>                               var today = new Date();
>>> 
>>> This value will be computed only once when document get indexed, not
>>> each time when you query the view.
>> 
>> Has anyone thought of modifying the JS global bindings when a map function runs, such that calling Date.new will throw an exception? Preferably an exception with a descriptive message like "It is illegal to use the current date in a map function"? It would save considerable support time — I believe this is the second time this issue has come up in the last week.
> 
> Making standard and expected things run with unexpected behaviour will
> annoy even more.
> 
> --
> ,,,^..^,,,


Re: confused about date parsing

Posted by Alexander Shorin <kx...@gmail.com>.
On Thu, Jan 30, 2014 at 2:45 AM, Jens Alfke <je...@couchbase.com> wrote:
> On Jan 29, 2014, at 2:17 PM, Alexander Shorin <kx...@gmail.com> wrote:
>
>> On Thu, Jan 30, 2014 at 2:13 AM, Dan Santner <da...@me.com> wrote:
>>>                                var today = new Date();
>>
>> This value will be computed only once when document get indexed, not
>> each time when you query the view.
>
> Has anyone thought of modifying the JS global bindings when a map function runs, such that calling Date.new will throw an exception? Preferably an exception with a descriptive message like "It is illegal to use the current date in a map function"? It would save considerable support time — I believe this is the second time this issue has come up in the last week.

Making standard and expected things run with unexpected behaviour will
annoy even more.

--
,,,^..^,,,

Re: confused about date parsing

Posted by Robert Samuel Newson <rn...@apache.org>.
That would prevent a user including "indexed at" timestamp. Admittedly an odd thing to do, but banning it seems a bit extreme.

B.

On 29 Jan 2014, at 22:45, Jens Alfke <je...@couchbase.com> wrote:

> 
> On Jan 29, 2014, at 2:17 PM, Alexander Shorin <kx...@gmail.com> wrote:
> 
>> On Thu, Jan 30, 2014 at 2:13 AM, Dan Santner <da...@me.com> wrote:
>>>                               var today = new Date();
>> 
>> This value will be computed only once when document get indexed, not
>> each time when you query the view. 
> 
> Has anyone thought of modifying the JS global bindings when a map function runs, such that calling Date.new will throw an exception? Preferably an exception with a descriptive message like "It is illegal to use the current date in a map function"? It would save considerable support time — I believe this is the second time this issue has come up in the last week.
> 
> (Yes, probably more appropriate on the dev list…)
> 
> —Jens
> 


Re: confused about date parsing

Posted by Mark Hahn <ma...@hahnca.com>.
It's not illegal, it's just something that would usually not make sense.
 The only use case I can think of is if you want a timestamp in a document
indicating when it was last put in the index.  Why one would need this is
beyond me, but it is certainly "legal".


On Wed, Jan 29, 2014 at 2:45 PM, Jens Alfke <je...@couchbase.com> wrote:

>
> On Jan 29, 2014, at 2:17 PM, Alexander Shorin <kx...@gmail.com> wrote:
>
> > On Thu, Jan 30, 2014 at 2:13 AM, Dan Santner <da...@me.com> wrote:
> >>                                var today = new Date();
> >
> > This value will be computed only once when document get indexed, not
> > each time when you query the view.
>
> Has anyone thought of modifying the JS global bindings when a map function
> runs, such that calling Date.new will throw an exception? Preferably an
> exception with a descriptive message like "It is illegal to use the current
> date in a map function"? It would save considerable support time -- I
> believe this is the second time this issue has come up in the last week.
>
> (Yes, probably more appropriate on the dev list...)
>
> --Jens
>
>

Re: confused about date parsing

Posted by Alexander Shorin <kx...@gmail.com>.
On Thu, Jan 30, 2014 at 3:01 AM, Mike Marino <mm...@gmail.com> wrote:
>> Am 29.01.2014 um 23:45 schrieb Jens Alfke <je...@couchbase.com>:
>> Has anyone thought of modifying the JS global bindings when a map function runs, such that calling Date.new will throw an exception? Preferably an exception with a descriptive message like "It is illegal to use the current date in a map function"? It would save considerable support time -- I believe this is the second time this issue has come up in the last week.
>
> I think it could be reasonable to write a tool that checks for common
> errors in views and advises based upon what it finds, e.g. an addition
> to the test suite. Running such a tool would have to be elective,
> though, I also don't think it's a good idea to take away
> functionality.

couchapp linter ? sounds very cool! I wonder if erica can have a plugin of such

--
,,,^..^,,,

Re: confused about date parsing

Posted by Mike Marino <mm...@gmail.com>.
> Am 29.01.2014 um 23:45 schrieb Jens Alfke <je...@couchbase.com>:
> Has anyone thought of modifying the JS global bindings when a map function runs, such that calling Date.new will throw an exception? Preferably an exception with a descriptive message like "It is illegal to use the current date in a map function"? It would save considerable support time -- I believe this is the second time this issue has come up in the last week.

I think it could be reasonable to write a tool that checks for common
errors in views and advises based upon what it finds, e.g. an addition
to the test suite. Running such a tool would have to be elective,
though, I also don't think it's a good idea to take away
functionality.

Re: confused about date parsing

Posted by Jens Alfke <je...@couchbase.com>.
On Jan 29, 2014, at 2:17 PM, Alexander Shorin <kx...@gmail.com> wrote:

> On Thu, Jan 30, 2014 at 2:13 AM, Dan Santner <da...@me.com> wrote:
>>                                var today = new Date();
> 
> This value will be computed only once when document get indexed, not
> each time when you query the view. 

Has anyone thought of modifying the JS global bindings when a map function runs, such that calling Date.new will throw an exception? Preferably an exception with a descriptive message like "It is illegal to use the current date in a map function"? It would save considerable support time — I believe this is the second time this issue has come up in the last week.

(Yes, probably more appropriate on the dev list…)

—Jens


Re: confused about date parsing

Posted by Alexander Shorin <kx...@gmail.com>.
On Thu, Jan 30, 2014 at 2:13 AM, Dan Santner <da...@me.com> wrote:
>                                 var today = new Date();

This value will be computed only once when document get indexed, not
each time when you query the view. You need to make key as
outDoc.expiryAge and pass current date with endkey query parameter to
fetch expired docs

--
,,,^..^,,,