import { locale, localeData, lang } from './locale';
import { prototypeMin, prototypeMax } from './min-max';
import { startOf, endOf } from './start-end-of';
-import { valueOf, toDate, toArray, unix } from './to-type';
+import { valueOf, toDate, toArray, toObject, unix } from './to-type';
import { isValid, parsingFlags, invalidAt } from './valid';
proto.add = add;
proto.startOf = startOf;
proto.subtract = subtract;
proto.toArray = toArray;
+proto.toObject = toObject;
proto.toDate = toDate;
proto.toISOString = toISOString;
proto.toJSON = toISOString;
var m = this;
return [m.year(), m.month(), m.date(), m.hour(), m.minute(), m.second(), m.millisecond()];
}
+
+export function toObject () {
+ var m = this;
+ return {
+ years: m.year(),
+ months: m.month(),
+ date: m.date(),
+ hours: m.hours(),
+ minutes: m.minutes(),
+ seconds: m.seconds(),
+ milliseconds: m.milliseconds()
+ };
+}
--- /dev/null
+import { module, test } from '../qunit';
+import moment from '../../moment';
+
+module('to type');
+
+test('toObject', function (assert) {
+ var expected = {
+ years:2010,
+ months:3,
+ date:5,
+ hours:15,
+ minutes:10,
+ seconds:3,
+ milliseconds:123
+ };
+ assert.deepEqual(moment(expected).toObject(), expected, 'toObject invalid');
+});
+
+test('toArray', function (assert) {
+ var expected = [2014, 11, 26, 11, 46, 58, 17];
+ assert.deepEqual(moment(expected).toArray(), expected, 'toArray invalid');
+});