Hi folks,
I'm new to couchdb (so please don't hurt me ;)). I want to build a
view of valid documents. Valid, in this case, means that those
documents have a "valid_from" and a "valid_until" date and "now" must
be within this range.
I've written a map script to do the work for me, but I do not know if
this is a good way for couchdb...? The dates are in mysql datetime
format (for historical reason)
function(doc) {
var convert = {
"do": function(timestamp) {
var regex = /^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9]) (?:
([0-2][0-9]):([0-5][0-9]):([0-5][0-9]))?$/;
var parts = timestamp.replace(regex, "$1 $2 $3 $4 $5
$6").split(' ');
return new Date(parts[0], parts[1] - 1, parts[2],
parts[3], parts[4], parts[5]).getTime();
},
};
var iT = new Date().getTime();
var iS = convert.do(doc.valid_from);
var iEnd = convert.do(doc.valid_unitl);
if (iS < iT < iEnd) {
emit(doc._id, null);
}
}
I'll be thankful for any kind of comment.
Thanks!
Mario
------------------------------------
Mario Mueller
Ellerstraße 130
40227 Duesseldorf, Germany
mail. [email protected]
phon. 0049 176 83016418
icq. 436092688
xing. http://tinyurl.com/MarioMueller
blog. http://tinyurl.com/MariosBlog
Attached to this mail you may find a PGP Key file (PGP.sig).
If you are not using PGP anyway you can ignore it.