diff --git a/README.md b/README.md index 94c2385f1..b102d2f61 100644 --- a/README.md +++ b/README.md @@ -252,6 +252,7 @@ _30s.average(1, 2, 3); * [`maxDate`](#maxdate) * [`minDate`](#mindate) * [`tomorrow`](#tomorrow) +* [`yesterday`](#yesterday) @@ -4579,6 +4580,32 @@ tomorrow(); // 2018-10-19 (if current date is 2018-10-18)
[⬆ Back to top](#contents) +### yesterday + +Results in a string representation of yesterday's date. + +Use `new Date()` to get the current date, decrement by one using `Date.getDate()` and set the value to the result using `Date.setDate()`. +Use `Date.prototype.toISOString()` to return a string in `yyyy-mm-dd` format. + +```js +const yesterday = () => { + let t = new Date(); + t.setDate(t.getDate() - 1); + return t.toISOString().split('T')[0]; +}; +``` + +
+Examples + +```js +yesterday(); // 2018-10-17 (if current date is 2018-10-18) +``` + +
+ +
[⬆ Back to top](#contents) + --- @@ -4736,6 +4763,7 @@ const checkProp = (predicate, prop) => obj => !!predicate(obj[prop]); + const lengthIs4 = checkProp(l => l === 4, 'length'); lengthIs4([]); // false lengthIs4([1,2,3,4]); // true diff --git a/docs/about.html b/docs/about.html index 205e32800..87edbc594 100644 --- a/docs/about.html +++ b/docs/about.html @@ -291,6 +291,7 @@
  • maxDate
  • minDate
  • tomorrow
  • +
  • yesterday
  • Function

    Function