]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Redo #2123 in es6
authorIskren Chernev <iskren.chernev@gmail.com>
Sun, 26 Jul 2015 03:00:04 +0000 (20:00 -0700)
committerIskren Chernev <iskren.chernev@gmail.com>
Sun, 26 Jul 2015 04:31:56 +0000 (21:31 -0700)
src/lib/moment/prototype.js
src/lib/moment/to-type.js
src/test/moment/to_type.js [new file with mode: 0644]

index 5601bc0bf3b3dfbf87da7f5db4b76f4255c7db40..d17f743addc4bfb7dbfdd8832277f8bd7607be58 100644 (file)
@@ -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;
index edc1338d1e6fb646bded90f2ec7180d5d7d2e81a..3008d95e3499e57f2d7851028adad250fcbc2362 100644 (file)
@@ -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 (file)
index 0000000..bbe2b57
--- /dev/null
@@ -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');
+});