src/utils/time/periodISO.js
function yearWeek (y, yd) {
    const dow = isoDow(y, 1, 1);
    const start = dow > 4 ? 9 - dow : 2 - dow;
    if ((Math.abs(yd - start) % 7) !== 0) {
        // y yd is not the start of any week
        return [];
    }
    if (yd < start) {
        // The week starts before the first week of the year => go back one year
        yd += Math.round((Date.UTC(y, 0, 1) - Date.UTC(y - 1, 0, 1)) / MS_PER_DAY);
        return yearWeek(y - 1, yd);
    } else if (Date.UTC(y, 0, 1) + (yd - 1 + 3) * MS_PER_DAY >= Date.UTC(y + 1, 0, 1)) {
        // The Wednesday (start of week + 3) lies in the next year => advance one year
        yd -= Math.round((Date.UTC(y + 1, 0, 1) - Date.UTC(y, 0, 1)) / MS_PER_DAY);
        return yearWeek(y + 1, yd);
    }
    return [y, 1 + Math.round((yd - start) / 7)];
}
function yearWeek (y, yd) {
    const dow = isoDow(y, 1, 1);
    const start = dow > 4 ? 9 - dow : 2 - dow;
    if ((Math.abs(yd - start) % 7) !== 0) {
        // y yd is not the start of any week
        return [];
    }
    if (yd < start) {
        // The week starts before the first week of the year => go back one year
        yd += Math.round((Date.UTC(y, 0, 1) - Date.UTC(y - 1, 0, 1)) / MS_PER_DAY);
        return yearWeek(y - 1, yd);
    } else if (Date.UTC(y, 0, 1) + (yd - 1 + 3) * MS_PER_DAY >= Date.UTC(y + 1, 0, 1)) {
        // The Wednesday (start of week + 3) lies in the next year => advance one year
        yd -= Math.round((Date.UTC(y + 1, 0, 1) - Date.UTC(y, 0, 1)) / MS_PER_DAY);
        return yearWeek(y + 1, yd);
    }
    return [y, 1 + Math.round((yd - start) / 7)];
}
function yearWeek ( y , yd ) { const dow = isoDow ( y , 1 , 1 ) ; const start = dow > 4 ? 9 - dow : 2 - dow ; if ( ( Math . abs ( yd - start ) % 7 ) !== 0 ) { // y yd is not the start of any week return [ ] ; } if ( yd < start ) { // The week starts before the first week of the year => go back one year yd += Math . round ( ( Date . UTC ( y , 0 , 1 ) - Date . UTC ( y - 1 , 0 , 1 ) ) / MS_PER_DAY ) ; return yearWeek ( y - 1 , yd ) ; } else if ( Date . UTC ( y , 0 , 1 ) + ( yd - 1 + 3 ) * MS_PER_DAY >= Date . UTC ( y + 1 , 0 , 1 ) ) { // The Wednesday (start of week + 3) lies in the next year => advance one year yd -= Math . round ( ( Date . UTC ( y + 1 , 0 , 1 ) - Date . UTC ( y , 0 , 1 ) ) / MS_PER_DAY ) ; return yearWeek ( y + 1 , yd ) ; } return [ y , 1 + Math . round ( ( yd - start ) / 7 ) ] ; }
Return year and week number given year and day number
Return year and week number given year and day number