(date: string)
| 5 | * never shifts with the viewer's timezone. |
| 6 | */ |
| 7 | export const getIsoWeekNumber = (date: string): number => { |
| 8 | const [year, month, day] = date.split('-').map(Number); |
| 9 | const target = new Date(Date.UTC(year, month - 1, day)); |
| 10 | // The week belongs to the year of its Thursday. |
| 11 | target.setUTCDate(target.getUTCDate() + 4 - (target.getUTCDay() || 7)); |
| 12 | const yearStart = Date.UTC(target.getUTCFullYear(), 0, 1); |
| 13 | |
| 14 | return Math.ceil(((target.getTime() - yearStart) / DAY_MS + 1) / 7); |
| 15 | }; |
| 16 | |
| 17 | /** This ISO week's Monday as YYYY-MM-DD in UTC, the way the API keys picks. */ |
| 18 | export const getCurrentWeekStart = (now: Date = new Date()): string => { |
no outgoing calls
no test coverage detected