如何将luxon时区功能加载到mongo shell中

时间:2019-05-01 22:14:39

标签: mongodb momentjs luxon

我想使用     luxon.js 我在mongodb shell中使用的shell脚本中的夏令时和时区功能。是

DateTime.isInDST()

我追求的功能-未能解决这个问题

moment.js 

和等效的实现。

运行时环境为 Mongo 3.6在Linux VM VirtualBOX上的Docker容器中运行 从命令行(从cygwin csh内部)提交的脚本

我已经提取了

的本地副本
https://moment.github.io/luxon/global-filled/luxon.js  

(我认为)应该包括所有依赖项。

脚本通过以下方式访问此信息:     加载(); 声明

但是我遇到错误

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;
  ...
}

我的猜测是“地图”是先前定义的。所以我修改了代码

var _cache = undefined;  //I read somewhere that it doesn't need to be pre-defined
....

我还检查了所有代码,找不到定义为“地图”的任何内容-因此,我认为不存在本地名称冲突。

在这一点上,我似乎正在步。 我可以创建实例并访问功能

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 按记录工作。

感谢任何建议

1 个答案:

答案 0 :(得分:0)

几件事: