From: Iskren Chernev Date: Sun, 26 Jul 2015 03:00:04 +0000 (-0700) Subject: Redo #2123 in es6 X-Git-Tag: 2.10.5~9^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4bea6c417821e010b3bb0a1ccb79f8b07ef0a072;p=thirdparty%2Fmoment.git Redo #2123 in es6 --- diff --git a/src/lib/moment/prototype.js b/src/lib/moment/prototype.js index 5601bc0bf..d17f743ad 100644 --- a/src/lib/moment/prototype.js +++ b/src/lib/moment/prototype.js @@ -14,7 +14,7 @@ import { getSet } from './get-set'; 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; @@ -44,6 +44,7 @@ proto.set = getSet; proto.startOf = startOf; proto.subtract = subtract; proto.toArray = toArray; +proto.toObject = toObject; proto.toDate = toDate; proto.toISOString = toISOString; proto.toJSON = toISOString; diff --git a/src/lib/moment/to-type.js b/src/lib/moment/to-type.js index edc1338d1..3008d95e3 100644 --- a/src/lib/moment/to-type.js +++ b/src/lib/moment/to-type.js @@ -14,3 +14,16 @@ export function toArray () { 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() + }; +} diff --git a/src/test/moment/to_type.js b/src/test/moment/to_type.js new file mode 100644 index 000000000..bbe2b5789 --- /dev/null +++ b/src/test/moment/to_type.js @@ -0,0 +1,22 @@ +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'); +});