| 55 | * //=> 53 |
| 56 | */ |
| 57 | export function getWeek( |
| 58 | date: DateArg<Date> & {}, |
| 59 | options?: GetWeekOptions | undefined, |
| 60 | ): number { |
| 61 | const _date = toDate(date, options?.in); |
| 62 | const diff = +startOfWeek(_date, options) - +startOfWeekYear(_date, options); |
| 63 | |
| 64 | // Round the number of weeks to the nearest integer because the number of |
| 65 | // milliseconds in a week is not constant (e.g. it's different in the week of |
| 66 | // the daylight saving time clock shift). |
| 67 | return Math.round(diff / millisecondsInWeek) + 1; |
| 68 | } |