/* If 1 Jan is just 1-3 days past Monday,
* the previous week is also in this year. */
/* If 1 Jan is just 1-3 days past Monday,
* the previous week is also in this year. */
val++;
if (!val) {
val = 52;
/* If 31 December of prev year a Thursday,
* or Friday of a leap year, then the
* prev year has 53 weeks. */
val++;
if (!val) {
val = 52;
/* If 31 December of prev year a Thursday,
* or Friday of a leap year, then the
* prev year has 53 weeks. */
if (dec31 == 4 || (dec31 == 5 && is_leap(tm->tm_year%400-1)))
val++;
} else if (val == 53) {
/* If 1 January is not a Thursday, and not
* a Wednesday of a leap year, then this
* year has only 52 weeks. */
if (dec31 == 4 || (dec31 == 5 && is_leap(tm->tm_year%400-1)))
val++;
} else if (val == 53) {
/* If 1 January is not a Thursday, and not
* a Wednesday of a leap year, then this
* year has only 52 weeks. */
if (val >= 10000) {
*l = snprintf(*s, sizeof *s, "+%lld", val);
return *s;
if (val >= 10000) {
*l = snprintf(*s, sizeof *s, "+%lld", val);
return *s;