我想在我在mongodb shell中使用的shell脚本中使用luxon.js夏令时和时区特性。这是
DateTime.isInDST()函数--如果这个失败了,我会满足于
moment.js 和一个等价的实现。
运行时环境是Mongo3.6,运行在linux上的docker容器中,VirtualBOX脚本从命令行提交(从cygwin csh内部)
我调出了一个本地副本
https://moment.github.io/luxon/global-filled/luxon.js 它(我认为)应该包含所有的依赖项。
脚本通过load();语句访问此信息
但是,我得到了一个错误
TypeError: "_cache.has is not a function"查看源文件,我在这里看到了令人不快的行-第2008行。
if (typeof _cache !== "undefined") {
if (_cache.has(Class)) return _cache.get(Class);
_cache.set(Class, Wrapper);
}
....
}变量_cache在这里早些时候声明了几行- 1998行。
function _wrapNativeSuper(Class) {
var _cache = typeof Map === "function" ? new Map() : undefined;
...
}我的猜测是"Map“是预先定义的。所以我把代码改成了
var _cache = undefined; //I read somewhere that it doesn't need to be pre-defined
....我还检查了我所有的代码,没有发现任何定义为"Map“的东西-所以我不认为有本地名称冲突。
在这一点上,我似乎步履蹒跚。我可以创建实例并访问函数
DateTime.local(); and
DateTime.toString(); 并获得正确的UTC值。
但是,请注意,我发现我必须使用"DateTime“作为全局变量(正如文档中所述)
luxon.DateTime(因为"luxon“是在源代码中声明的变量)
但是,当我编写代码时
var now = luxon.DateTime.local();
var now_tz = now.setZone( "America/Los_Angeles" );
trace("time after tz:"+ now_tz.toString()+" reason:" +now_tz.invalidReason+ " explanation:"+now_tz.invalidExplanation);
trace("zone support is:"+luxon.Info.features().zones);我得到了
time after tz:Invalid DateTime reason:unsupported zone explanation:the zone "America/Los_Angeles" is not supported
zone support is:false这表明Mongodb shell没有专区支持(除非之前的黑客以某种方式使该专区支持无效)。
我的问题是:如何添加专区支持。为什么通过luxon.js的实例化不能像文档中描述的那样工作。
感谢您的建议
发布于 2019-05-02 22:50:07
以下是一些事情:
Map。而且那个东西没有全局构建导出luxon,所以luxon.DateTime是可以预期的。例如,查看此处:https://moment.github.io/luxon/来填充它
https://stackoverflow.com/questions/55943375
复制相似问题