Add from-week-date conversion functions

This commit is contained in:
Laurence Withers 2006-10-15 19:41:04 +01:00
commit 582b960e0b
2 changed files with 40 additions and 8 deletions

View file

@ -128,7 +128,7 @@ int try_weeks(void)
// starting position
int weekcount = 52, weekday = 5, isoyear = -1;
int y, wk, wd, ret = 0;
struct iso8601_date dt;
struct iso8601_date dt, dt2;
for(dt.day = 0; dt.day < MAX_YEAR_COUNT * 366; ++dt.day) {
iso8601_to_week(&y, &wk, &wd, &dt);
@ -141,9 +141,17 @@ int try_weeks(void)
++isoyear;
}
}
if(wk != weekcount || y != isoyear) goto discont;
if(wk != weekcount || y != isoyear) goto discont;
weekday = wd;
iso8601_from_week(&dt2, isoyear, weekcount, weekday);
if(dt2.day != dt.day) {
printf("[weekmismatch ] %04d-W%02d-%d: should be %d, got %d\n",
isoyear, weekcount, weekday, dt.day, dt2.day);
if(++ret > 20) return ret;
}
continue;
discont: