1 | /**
|
2 | * @name startOfYesterday
|
3 | * @category Day Helpers
|
4 | * @summary Return the start of yesterday.
|
5 | * @pure false
|
6 | *
|
7 | * @description
|
8 | * Return the start of yesterday.
|
9 | *
|
10 | * @returns The start of yesterday
|
11 | *
|
12 | * @example
|
13 | * // If today is 6 October 2014:
|
14 | * const result = startOfYesterday()
|
15 | * //=> Sun Oct 5 2014 00:00:00
|
16 | */
|
17 | export function startOfYesterday() {
|
18 | const now = new Date();
|
19 | const year = now.getFullYear();
|
20 | const month = now.getMonth();
|
21 | const day = now.getDate();
|
22 |
|
23 | const date = new Date(0);
|
24 | date.setFullYear(year, month, day - 1);
|
25 | date.setHours(0, 0, 0, 0);
|
26 | return date;
|
27 | }
|
28 |
|
29 | // Fallback for modularized imports:
|
30 | export default startOfYesterday;
|