]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
toDate: remove ternary, add unit test
authorJonathan Gray <jonathan.sam.gray@gmail.com>
Sat, 21 May 2016 20:06:10 +0000 (13:06 -0700)
committerIskren Chernev <iskren.chernev@gmail.com>
Tue, 14 Jun 2016 09:49:13 +0000 (02:49 -0700)
src/lib/moment/to-type.js
src/test/moment/to_type.js

index 261225bc00548a22e1fe916700bf98c2ad3fc6fd..a990dd200b3a09a395d8dd97492561a5d47560e1 100644 (file)
@@ -7,7 +7,7 @@ export function unix () {
 }
 
 export function toDate () {
-    return this._offset ? new Date(this.valueOf()) : new Date(this._d);
+    return new Date(this.valueOf());
 }
 
 export function toArray () {
index bbe2b578954af7d677d4bc3ebed3568dcdfb9177..24d8e83395ebf9fbad05c13c778d2e309eff9f7e 100644 (file)
@@ -20,3 +20,10 @@ test('toArray', function (assert) {
     var expected = [2014, 11, 26, 11, 46, 58, 17];
     assert.deepEqual(moment(expected).toArray(), expected, 'toArray invalid');
 });
+
+test('toDate returns a copy of the internal date', function (assert) {
+    var m = moment();
+    var d = m.toDate();
+    m.year(0);
+    assert.notEqual(d, m.toDate());
+});