I found the answer that will work for me. The scope, after all, was limited to having this support in server-side mongo DB, and only on Linux.
@AsyaKamsky pointed to a greate J/S library, timezone-js, that does full and proper time zone support, considering that it uses actual time zone files from IANA. However, loading arbitrary java-script libraries into Mongo server environment is not that easy. You can only load global function definitions. timezone-js also needs to be provided with a custom transport mechanism to download the timezone files (I don't even know if MongoDB server environment provides files access), or the time zone files have to be precompiled into JSON objects, and served along with the library. I decided that this would be too tedious of an approach, and I will have to be responsible of providing mechanism to update time zone files when they are changed.
The other alternative I was looking into - is hacking the J/S implementation used in Mongo to add a function that will do the job I want it to do. That is what I have done. Things are actually as dismal in the world of glibc as they are in JavaScript, but there is a library for the job, icu.
I've made this patch, that adds a static Date.daytz() function, which, taken a UTC timestamp, and a time zone name, will return a yyyy-mm-dd string.
Considering the following map/reduce functions:
fmap = function () {
emit(Date.daytz(this.time * 1000, globtz), {count:1});
};
fred = function (k, v) {
var r = {count:0};
v.forEach(function (v0) {r.count += v0.count;});
return r;
};
I get exactly what I wanted, running these two map reduce commands:
{ "mapreduce" : "objects",
"map" : fmap,
"reduce" : fred,
"out" : { "inline" : 1 },
"scope" : { "globtz" : "Europe/London" } }
and
{ "mapreduce" : "objects",
"map" : fmap,
"reduce" : fred,
"out" : { "inline" : 1 },
"scope" : { "globtz" : "America/Los_Angeles" } }