couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave Cottlehuber <...@jsonified.com>
Subject Re: CouchDB: Timestamp inaccurate and seems to be cached
Date Wed, 08 Jan 2014 16:07:45 GMT
It seems this is a common request; instead of computing it expensively in
JS,  perhaps you'd like to open a jira ticket at
https://issues.apache.org/jira/browse/COUCHDB  with some use case details,
and we could generate it using a cheap & efficient erlang function,  and
include its output in e.g. GET / .

A+
Dave



On 8 January 2014 15:42, Jean-Felix Girard <jeanfelixg@icloud.com> wrote:

> Hi,
> To get server time from the client, I use a update function...  You could
> do something like this:
> {
>    "_id": "_design/js",
>    "_rev": "2-17d3cd5c245d45d1232ee95176d2e792",
>    "language": "javascript",
>    "updates": {
>        "time": "function(doc, req) {  return [null, Math.round(new
> Date().getTime()/1000) + ''];}"
>    }
> }
> and query it like that:
>
> curl localhost:5984/data_test/_design/js/_update/time -X POST
> 1389192069
> ~:$
>
> Jeff
>
> On Jan 8, 2014, at 9:17 AM, Hank Knight <hknight555@gmail.com> wrote:
>
> > I use this Map Function to get the current Unix timestamp:
> >
> > function(doc) {emit(Math.round(new Date().getTime()/1000), null  );}
> >
> > The odd thing is, it returns a correct timestamp the first time I run
> > a query but it returns the exact same timestamp one minute later even
> > though 60 seconds have passed!  Is this due to caching or something
> > else?  What is the best way for me to always get the current Unix
> > timestamp?
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message