简体   繁体   English

ClojureScript + momentjs(node.js)失败了.format(“dddd,MMMM Do YYYY,h:mm:ss a”)

[英]ClojureScript + momentjs (node.js) fails with .format(“dddd, MMMM Do YYYY, h:mm:ss a”)

I'm trying to show current datetime format to console on node.js + clojure deploying momentjs . 我试图在node.js + clojure部署momentjs上显示当前日期时间格式。

The working node js code: 工作节点js代码:

var moment = require("./lib/moment/moment.js");
console.log(moment().format("dddd, MMMM Do YYYY, h:mm:ss a"));

Console output: 控制台输出:

$ node app1              
Friday, July 5th 2013, 9:57:07 am

so, I tried a clojureScript code as below: 所以,我尝试了如下的clojureScript代码:

(ns rxcljs.core
  (:use [cljs.nodejs :only [require]])
)
(def log #(.log js/console %))
(def moment (require "./lib/moment/moment.js"))

(->> (-> (moment) 
          (.format "dddd, MMMM Do YYYY, h:mm:ss a")
      )
     (log) 
 ) 

The Console output becomes 控制台输出变为

$ node app            
FridaynullundefinedJulyundefined5thundefined2013nullundefined9null56null31undefinedam

Datetime is partially presented with bunch of null and undefined for some reason. 由于某种原因,日期时间部分呈现为一堆nullundefined

Compiled js code: 编译的js代码:

var rxcljs = {core:{}};
rxcljs.core.log = function(a) {
  return console.log(a)
}; 
rxcljs.core.moment = cljs.nodejs.require.call(null, "./lib/moment/moment.js");
rxcljs.core.log.call(null, rxcljs.core.moment.call(null).format("dddd, MMMM Do YYYY, h:mm:ss a"));

The point the problem occurred looks not that problematic: 问题发生的重点看起来没有问题:

rxcljs.core.moment.call(null).format("dddd, MMMM Do YYYY, h:mm:ss a")

Any idea? 任何想法? Thanks. 谢谢。

This is due to a known incompatibility of Moment.js 2.0.0 with ClojureScript, fixed in this commit by David Altenburg . 这是由于Moment.js 2.0.0与ClojureScript的已知不兼容性,由David Altenburg此提交中修复。 Here's the commit message: 这是提交消息:

Format function now uses "instanceof" on a var rather than "typeof" on that var's call to determine if the variable is a function. 格式函数现在在var上使用“instanceof”而不是var的调用上的“typeof”来确定变量是否是函数。

This fixes an incompatibility with ClojureScript, which defines String.prototype.call as a function. 这修复了与ClojureScript的不兼容性,ClojureScript将String.prototype.call定义为函数。

The version currently in the develop branch works fine. 当前在开发分支中的版本工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在node.js中将datetime:1518427800转换为hh:mm:ss dd / mm / yyyy? - How can I convert datetime : 1518427800 to hh:mm:ss dd/mm/yyyy in node.js? node.js mysql - 以 YYYY-MM-DDThh:mm:ssZ 格式提取日期时间,无毫秒 - node.js mysql - Extract datetime in YYYY-MM-DDThh:mm:ssZ format without milliseconds 如何使用 mongoose 和 node.js 将 mongodb 时间戳转换为 dd-mm-yyyy 格式? - How to convert mongodb timestamps to dd-mm-yyyy format using mongoose and node.js? 在node.js中添加HH:MM:SS值数组 - Add array of HH:MM:SS values in node.js moment.js函数在节点中为日期格式“ dddd Do MMM”返回NaN - moment.js function returning NaN for date format “dddd Do MMM” in node node.js上的ClojureScript,代码 - ClojureScript on node.js, code Sequelize 如何将日期格式化为 YYYY-MM-DD HH:mm:ss 并将列保持为蛇形 - Sequelize How do you format date to YYYY-MM-DD HH:mm:ss and keep the columns as snake case 将node.js API惯用转换为ClojureScript - Idiomatic conversion of node.js APIs to ClojureScript 如何使用矩获取DD-MM-YYYY h:mm:ss:ssss中的日期 - how to get date in DD-MM-YYYY h:mm:ss:ssss using moment 如何检查字符串是否为有效日期格式(格式应为:YYYY-MM-DD HH:mm:ss) - how to check the string is valid date format or not (format should be in : YYYY-MM-DD HH:mm:ss)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM