小编Kha*_*ain的帖子

Moment.js月差异

我现在一直在使用moment.js,这使得日期操作变得容易多了但是我有一个特定的情况是失败的,我不明白为什么.

在计算今天(2013年10月31日)和2014年2月1日之间的差异时,虽然两个日期之间有3个完整的月份和一天,但是差异时间差异为2.

10月31日至1月31日之间的差异很好:3个月零天.

var mStartDate = moment([ periodStartDate.getFullYear(), periodStartDate.getMonth(), periodStartDate.getDate() ]);
var mTermDate = moment([ someDate.getFullYear(), someDate.getMonth(), someDate.getDate() ]);

console.log('periodStartDate: ' + periodStartDate);
console.log('someDate: ' + someDate);

// Years
var yearsDiff = mTermDate.diff(mStartDate, 'years');

// Months
var monthsDiff = mTermDate.diff(mStartDate, 'months', true);
Run Code Online (Sandbox Code Playgroud)

控制台记录以下内容:

periodStartDate: Thu Oct 31 2013 11:13:51 GMT+0000 (GMT)
someDate: Sat Feb 01 2014 11:13:51 GMT+0000 (GMT)
monthsDiff: 2
Run Code Online (Sandbox Code Playgroud)

如果我传递true作为布尔值而不是舍入,那么差异就是几个月

monthsDiff: 2.983050847457627 
Run Code Online (Sandbox Code Playgroud)

这只是Moment.js.diff()中的一个错误吗?我的其他测试用例中的每一个都成功通过.

javascript momentjs

42
推荐指数
3
解决办法
5万
查看次数

XML Schema - choice元素中的maxOccurs

我有以下架构声明:

<element name="container">
  <complexType>
    <choice minOccurs="0" maxOccurs="unbounded">
      <element name="action" minOccurs="0" maxOccurs="1" />
      <element name="query" minOccurs="0" maxOccurs="unbounded" />
      <element name="validator" minOccurs="0" maxOccurs="unbounded" />
    </choice>
  </complexType>
</element>
Run Code Online (Sandbox Code Playgroud)

我基本上想要<container>包含所需数量<query><validator>元素,但只包含一个<action>元素(可能没有).

据我所知,我不能把maxOccurs放在<choice>技术上,因为这个选择可以无限次地进行(由于查询和验证器上没有遮挡).

但是,这个XML在Eclipse中被认为是有效的(这可能只是Eclipse验证中的一个问题,尽管所有其他位工作正常)

<container>
  <action id="action1" name="action1" />
  <action id="action2" name="action2" />
  <query id="query1" />
  <validator id="testValidator" />
</container>
Run Code Online (Sandbox Code Playgroud)

不确定我是否遗漏了一些明显的东西.

xsd

7
推荐指数
1
解决办法
8318
查看次数

标签 统计

javascript ×1

momentjs ×1

xsd ×1