Epoch (Unix Time) based Dates in View map() Functions!

7 views
Skip to first unread message

scalabl3

unread,
Oct 24, 2012, 3:49:31 PM10/24/12
to couchba...@googlegroups.com
[meant to post this as it's own topic, must be some hidden metadata that makes this group in other Discussions!]

A little tip when working with Epoch based Dates:

function (doc, meta) {
  if (meta.type == "json" && doc.type == "grouplevel") {

    // create a new date
    var dt = new Date(0)
    
    // set number of seconds from epoch time in doc
    dt.setUTCSeconds(doc.timestamp);
    
    // convert to array
    var da = dateToArray(dt)
        
    emit(da, meta.id);
  }
}

Results of the Indexed Key : [2012,10,24,19,12,11] 


If you just do (for epoch times)
var dt = new Date(doc.timestamp)
var da = dateToArray(dt)
emit(da, meta.id);        

You'd get: [1970,1,16,15,18,25]

Which isn't what you're looking for!

Jasdeep Jaitla
@scalabl3
Reply all
Reply to author
Forward
0 new messages