| 30 | * //=> Jan 01 2010 00:00:00 |
| 31 | */ |
| 32 | export function startOfDecade< |
| 33 | DateType extends Date, |
| 34 | ResultDate extends Date = DateType, |
| 35 | >( |
| 36 | date: DateArg<DateType>, |
| 37 | options?: StartOfDecadeOptions<ResultDate> | undefined, |
| 38 | ): ResultDate { |
| 39 | // TODO: Switch to more technical definition in of decades that start with 1 |
| 40 | // end with 0. I.e. 2001-2010 instead of current 2000-2009. It's a breaking |
| 41 | // change, so it can only be done in 4.0. |
| 42 | const _date = toDate(date, options?.in); |
| 43 | const year = _date.getFullYear(); |
| 44 | const decade = Math.floor(year / 10) * 10; |
| 45 | _date.setFullYear(decade, 0, 1); |
| 46 | _date.setHours(0, 0, 0, 0); |
| 47 | return _date; |
| 48 | } |