( billingPeriodStart: Date, now: Date = new Date(), )
| 122 | * Weeks start on the same day-of-week as the billing period started. |
| 123 | */ |
| 124 | export function getWeekStart( |
| 125 | billingPeriodStart: Date, |
| 126 | now: Date = new Date(), |
| 127 | ): Date { |
| 128 | const billingDayOfWeek = billingPeriodStart.getUTCDay() |
| 129 | const currentDayOfWeek = now.getUTCDay() |
| 130 | const daysBack = (currentDayOfWeek - billingDayOfWeek + 7) % 7 |
| 131 | return startOfDay(addDays(now, -daysBack)) |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * Get the end of the current billing-aligned week (start of next week). |
no test coverage detected