return key ? key.toLowerCase().replace('_', '-') : key;
}
+ // Return a moment from input, that is local/utc/zone equivalent to model.
+ function makeAs(input, model) {
+ return model._isUTC ? moment(input).zone(model._offset || 0) :
+ moment(input).local();
+ }
+
/************************************
Languages
************************************/
},
diff : function (input, units, asFloat) {
- var that = this._isUTC ? moment(input).zone(this._offset || 0) : moment(input).local(),
+ var that = makeAs(input, this),
zoneDiff = (this.zone() - that.zone()) * 6e4,
diff, output;
},
isSame: function (input, units) {
- units = typeof units !== 'undefined' ? units : 'millisecond';
- return +this.clone().startOf(units) === +moment(input).startOf(units);
+ units = units || 'ms';
+ return +this.clone().startOf(units) === +makeAs(input, this).startOf(units);
},
min: function (other) {
test.equal(m.isSame(m, 'millisecond'), true, "same moments are in the same millisecond");
test.equal(+m, +mCopy, "isSame millisecond should not change moment");
test.done();
+ },
+
+ "is same with zone'd moments" : function (test) {
+ test.expect(3);
+ test.ok(moment.parseZone('2013-01-01T-05:00').isSame(moment('2013-01-01'), 'year'), "zoned vs local moment");
+ test.ok(moment('2013-01-01').isSame(moment('2013-01-01').zone('-05:00'), 'year'), "local vs zoned moment");
+ test.ok(moment.parseZone('2013-01-01T-05:00').isSame(moment.parseZone('2013-01-01T-06:30'), 'year'),
+ "zoned vs (differently) zoned moment");
+ test.done();
}
};