pgfgantt: How to display week numbers according to ISO 8601 counting scheme?

Since the 53-week year happens only occasionally and never in quick succession, I think in this case, it is easier to hardwire 53 weeks for the particular case when \ifnum\startyear=2020 rather than develop an ISO 8601-compliant version. It is the former course which I have done in the MWE.

\documentclass{standalone}
\usepackage{pgfgantt}

\newcounter{resetWeekNum}
\stepcounter{resetWeekNum}
\newcommand{\resetWeek}{ %
    \theresetWeekNum
    \stepcounter{resetWeekNum}
    \ifnum\startyear=2020
      \ifnum\theresetWeekNum=54
      \setcounter{resetWeekNum}{1}
      \else\fi
    \else
      \ifnum\theresetWeekNum=53
      \setcounter{resetWeekNum}{1}
      \else\fi
    \fi
}

\begin{document}

    \setcounter{resetWeekNum}{27}
    \ganttset{calendar week text=\scriptsize{\resetWeek{}}}

    \begin{ganttchart}
                        [   time slot format    =   isodate,
                            x unit              =   2mm,
                            vgrid               =   true,
                        ]   {2019-07-01}{2021-05-16}

        \gantttitlecalendar{year, month=name,week=1 day} \\ % weekday=letter
        \ganttbar{WP1}{2019-04-01}{2020-12-27} \\
        \ganttbar{WP2}{2019-04-01}{2020-12-31} \\
        \ganttbar{WP2}{2019-04-01}{2021-01-03} \\

    \end{ganttchart}

\end{document}

enter image description here

enter image description here


I agree with Steven that this may be some sort of an overkill. On the other hand the calendar library has the nice \pgfcalendarifdate built in, so...

\documentclass{standalone}
\usepackage{pgfgantt}
\newif\ifspecialweek
\newcounter{resetWeekNum}
\stepcounter{resetWeekNum}
\newcommand{\resetWeek}{ %
    \theresetWeekNum
    \stepcounter{resetWeekNum}
    \specialweekfalse
    \pgfcalendarifdate{31-12-\startyear}{Thursday}{\global\specialweektrue}{}
    \pgfcalendarifdate{31-12-\startyear}{Friday}{\global\specialweektrue}{}
    \pgfcalendarifdate{31-12-\startyear}{Saturday}{\global\specialweektrue}{}
    \pgfcalendarifdate{31-12-\startyear}{Sunday}{\global\specialweektrue}{}
    \ifspecialweek
      \ifnum\theresetWeekNum=54
      \setcounter{resetWeekNum}{1}
      \fi
    \else
      \ifnum\theresetWeekNum=53
      \setcounter{resetWeekNum}{1}
      \fi
    \fi
}

\begin{document}

    \setcounter{resetWeekNum}{27}
    \ganttset{calendar week text=\scriptsize{\resetWeek}}

    \begin{ganttchart}
                        [   time slot format    =   isodate,
                            x unit              =   2mm,
                            vgrid               =   true,
                        ]   {2019-07-01}{2021-05-16}

        \gantttitlecalendar{year, month=name,week=1 day} \\ % weekday=letter
        \ganttbar{WP1}{2019-04-01}{2020-12-27} \\
        \ganttbar{WP2}{2019-04-01}{2020-12-31} \\
        \ganttbar{WP2}{2019-04-01}{2021-01-03} \\

    \end{ganttchart}

\end{document}

enter image description here

enter image description here