},
diff : function (input, val, asFloat) {
- var inputMoment = moment(input),
+ var inputMoment = this._isUTC ? moment(input).utc() : moment(input).local(),
zoneDiff = (this.zone() - inputMoment.zone()) * 6e4,
diff = this._d - inputMoment._d - zoneDiff,
year = this.year() - inputMoment.year(),
if (val === 'months') {
output = year * 12 + month + date / 30;
} else if (val === 'years') {
- output = year + month / 12;
+ output = year + (month + date / 30) / 12;
} else {
output = val === 'seconds' ? diff / 1e3 : // 1000
val === 'minutes' ? diff / 6e4 : // 1000 * 60
test.done();
},
+ "cloning carrying over utc mode" : function(test) {
+ test.expect(8);
+
+ test.equal(moment().local().clone()._isUTC, false, "An explicit cloned local moment should have _isUTC == false");
+ test.equal(moment().utc().clone()._isUTC, true, "An cloned utc moment should have _isUTC == true");
+ test.equal(moment().clone()._isUTC, false, "An explicit cloned local moment should have _isUTC == false");
+ test.equal(moment.utc().clone()._isUTC, true, "An explicit cloned utc moment should have _isUTC == true");
+ test.equal(moment(moment().local())._isUTC, false, "An implicit cloned local moment should have _isUTC == false");
+ test.equal(moment(moment().utc())._isUTC, true, "An implicit cloned utc moment should have _isUTC == true");
+ test.equal(moment(moment())._isUTC, false, "An implicit cloned local moment should have _isUTC == false");
+ test.equal(moment(moment.utc())._isUTC, true, "An implicit cloned utc moment should have _isUTC == true");
+
+ test.done();
+ },
+
"parsing iso" : function(test) {
var offset = moment([2011, 9, 08]).zone();
var pad = function(input) {
test.equal(moment([2010, 0, 2]).diff([2010], 'hours'), 24, "hour diff");
test.equal(moment([2010, 0, 1, 2]).diff([2010], 'minutes'), 120, "minute diff");
test.equal(moment([2010, 0, 1, 0, 4]).diff([2010], 'seconds'), 240, "second diff");
+ test.done();
+ },
+
+ "diff between utc and local" : function(test) {
+ test.expect(7);
+
+ test.equal(moment([2011]).utc().diff([2010], 'years'), 1, "year diff");
+ test.equal(moment([2010, 2]).utc().diff([2010], 'months'), 2, "month diff");
+ test.equal(moment([2010, 0, 4]).utc().diff([2010], 'days'), 3, "day diff");
+ test.equal(moment([2010, 0, 21]).utc().diff([2010], 'weeks'), 3, "week diff");
+ test.equal(moment([2010, 0, 1, 4]).utc().diff([2010], 'hours'), 4, "hour diff");
+ test.equal(moment([2010, 0, 1, 0, 5]).utc().diff([2010], 'minutes'), 5, "minute diff");
+ test.equal(moment([2010, 0, 1, 0, 0, 6]).utc().diff([2010], 'seconds'), 6, "second diff");
+
+ test.done();
+ },
+
+ "year diffs include dates" : function(test) {
+ test.expect(1);
+
+ test.ok(moment([2012, 1, 19]).diff(moment([2002, 1, 20]), 'years', true) < 10, "year diff should include date of month");
+
test.done();
}
};