Repository: you-dont-need/You-Dont-Need-Momentjs (language: javascript)

Issue:
Why are native ‘add’ and ‘subtract’ different?
Native add reads:

```js
const now = new Date();
now.setDate(now.getDate() + 7);
```

Native subtract reads:

```js
new Date(new Date().getTime() - 1000 * 60 * 60 * 24 * 7);
```

Why are they different? Would the approach used for add not work for subtract or vice-versa? (I tried them and they seemed to work, but when working with times there are so many edge cases that you can never be sure…)


Discussion / hints:
I came here wondering the same thing. For what it's worth, it looks like the [subtract](https://github.com/you-dont-need/You-Dont-Need-Momentjs/commit/5d1ce62af3eab4e552cf1e4f50949c13f7b1bf59) and [add](https://github.com/you-dont-need/You-Dont-Need-Momentjs/commit/757022226e784a09169d32ecf8ec7f3675187051) samples were written at different times, by different people, and add was written was later. Also, `date-fns`' implementation of [`subDays`](https://github.com/date-fns/date-fns/blob/master/src/subDays/index.ts) seems to use the `setDate` method, as it just calls `addDays`:

```js
// subDays.ts:
export default function subDays(dirtyDate: Date | number, dirtyAmount: number) {
  // [...]

  const amount = toInteger(dirtyAmount)
  return addDays(dirtyDate, -amount)
}

// addDays.ts:
export default function addDays(
  dirtyDate: Date | number,
  dirtyAmount: number
): Date {
  // [...]
  const date = toDate(dirtyDate)
  const amount = toInteger(dirtyAmount)
  // [...]
  date.setDate(date.getDate() + amount)
  return date
}
```

Fix patch:
diff --git a/README.md b/README.md
index 934531c..c258a5c 100644
--- a/README.md
+++ b/README.md
@@ -803,7 +803,8 @@ moment().subtract(7, 'days');
 // => "2018-09-02T09:12:49.695Z"
 
 // Native
-new Date(new Date().getTime() - 1000 * 60 * 60 * 24 * 7);
+const now = new Date();
+now.setDate(now.getDate() - 7);
 // => Sun Sep 09 2018 09:12:49
 
 // date-fns


Test patch: