I cannot use the headers because cross-domain issues. I need the results to be returned in JSONP format with a callback.
Using a show function for this seems like a good idea but it does not work either! Here is an example. Notice how the time does not refresh! https://zuhqtr5.couchappy.com/test/_design/showtimestamp/_show/serverTime Here is my show function: { "_id": "_design/showtimestamp", "shows": { "timestamp": "function(doc, req) {return ''+String(Math.round(new Date().getTime()/1000));}", "serverTime": "function(doc, req) {return 'serverTime({\"timestamp\": '+String(Math.round(new Date().getTime()/1000))+'});';}" } } On Wed, Jan 8, 2014 at 3:40 PM, Jean-Felix Girard <[email protected]> wrote: > I just noticed that Couchdb returns a "Date" response header. > > < HTTP/1.1 200 OK > < Transfer-Encoding: chunked > < Server: CouchDB/1.5.0 (Erlang OTP/R16B02) > < ETag: "4E9MYK7J4X9CKM0EUK0V1K7IZ" > < Date: Wed, 08 Jan 2014 19:34:38 GMT > < Content-Type: text/plain; charset=utf-8 > < Cache-Control: must-revalidate > > You can parse that date (from the GET request on the view) and compare it to > the document date to find out theirs age. > > Jeff > > > On Jan 8, 2014, at 1:58 PM, Hank Knight <[email protected]> wrote: > >> I want to get the current timestamp according to the CouchDB server >> using a GET request. When new documents are created, an update >> function is used to add a timestamp to a document. When I get a >> result set, it is important to know the server's current timestamp so >> the age of the documents in the result set can be correctly >> determined. >> >> On Wed, Jan 8, 2014 at 10:17 AM, Hank Knight <[email protected]> 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? >
