/* Calculate the week number for the given date (9 January = week 2)  */
err_t rtcGetWeekNumber(rtcTime_t *t, uint8_t *weekNumber)
/* Calculate the week number for the given date (9 January = week 2)  */
err_t rtcGetWeekNumber(rtcTime_t *t, uint8_t *weekNumber)
{
    uint32_t NrOfDay = rtcGetEpochDate(t->years, 1, 1);
    uint8_t nextMondayDay = 8 - NrOfDay;
    if ((t->months == 1) && (t->days < nextMondayDay))
    {
        *weekNumber = 1;
    }
    else
    {
        *weekNumber = (rtcGetEpochDate(t->years, t->months, t->days)
            - rtcGetEpochDate(t->years, 1, nextMondayDay)) / 7 + 2;
    }
    return ERROR_NONE;
}