]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
creationData for issue #2443
authoralburthoffman <alburthoffman@gmail.com>
Tue, 18 Aug 2015 17:33:18 +0000 (01:33 +0800)
committerIskren Chernev <iskren.chernev@gmail.com>
Mon, 9 Nov 2015 04:51:36 +0000 (20:51 -0800)
Make a function creationData(), that returns an object with input,
format, isUTC, locale

src/lib/moment/creation-data.js [new file with mode: 0644]
src/lib/moment/prototype.js
src/test/moment/creation-data.js [new file with mode: 0644]

diff --git a/src/lib/moment/creation-data.js b/src/lib/moment/creation-data.js
new file mode 100644 (file)
index 0000000..4734413
--- /dev/null
@@ -0,0 +1,8 @@
+export function creationData() {
+    return {
+        input: this._i,
+        format: this._f,
+        locale: this._locale,
+        isUTC: this._isUTC
+    };
+}
index 85c7e82177d66157a0c42560bba884512b290afc..fe7bc9dc61471ae4b401c8c9e9374dcb6305e5e0 100644 (file)
@@ -16,6 +16,7 @@ import { prototypeMin, prototypeMax } from './min-max';
 import { startOf, endOf } from './start-end-of';
 import { valueOf, toDate, toArray, toObject, toJSON, unix } from './to-type';
 import { isValid, parsingFlags, invalidAt } from './valid';
+import { creationData } from './creation-data';
 
 proto.add          = add;
 proto.calendar     = calendar;
@@ -51,6 +52,7 @@ proto.toJSON       = toJSON;
 proto.toString     = toString;
 proto.unix         = unix;
 proto.valueOf      = valueOf;
+proto.creationData = creationData;
 
 // Year
 import { getSetYear, getIsLeapYear } from '../units/year';
diff --git a/src/test/moment/creation-data.js b/src/test/moment/creation-data.js
new file mode 100644 (file)
index 0000000..a7e75a0
--- /dev/null
@@ -0,0 +1,29 @@
+import { module, test } from '../qunit';
+import moment from '../../moment';
+
+module('creation data');
+
+test('valid date', function (assert) {
+    var dat = moment('1992-10-22');
+    var orig = dat.creationData();
+
+    assert.equal(dat.isValid(), true, '1992-10-22 is valid');
+    assert.equal(orig.input, '1992-10-22', 'original input is not correct.');
+    assert.equal(orig.format, 'YYYY-MM-DD', 'original format is defined.');
+    assert.equal(orig.locale._abbr, 'en', 'default locale is en');
+    assert.equal(orig.isUTC, false, 'not a UTC date');
+});
+
+test('valid date at fr locale', function (assert) {
+    var dat = moment('1992-10-22', 'YYYY-MM-DD', 'fr');
+    var orig = dat.creationData();
+
+    assert.equal(orig.locale._abbr, 'fr', 'locale is fr');
+});
+
+test('valid date with formats', function (assert) {
+    var dat = moment('29-06-1995', ['MM-DD-YYYY', 'DD-MM', 'DD-MM-YYYY']);
+    var orig = dat.creationData();
+
+    assert.equal(orig.format, 'DD-MM-YYYY', 'DD-MM-YYYY format is defined.');
+});