Jacek Caban (@jacek) commented about dlls/vbscript/global.c:
+ int locale_firstday = 0; + GetLocaleInfoW(This->ctx->lcid, LOCALE_RETURN_NUMBER | LOCALE_IFIRSTDAYOFWEEK, + (LPWSTR)&locale_firstday, sizeof(locale_firstday) / sizeof(WCHAR)); + firstday_wday = (locale_firstday + 1) % 7; + } + + day1 = (LONG)date1; + day2 = (LONG)date2; + /* anchor is any day number whose day-of-week equals firstday_wday. + * Day 0 (12/30/1899) is Saturday (wday 6), so dow(d) = (d + 6) % 7. + * We need (anchor + 6) % 7 == firstday_wday, i.e. anchor = (firstday_wday + 1) % 7. */ + anchor = (firstday_wday + 1) % 7; + + /* Use floor division so negative day numbers are handled correctly */ + result = (LONG)floor((double)(day2 - anchor) / 7.0) + - (LONG)floor((double)(day1 - anchor) / 7.0); I'm not sure if floating point makes it easier to read. I guess we could also do something like:
if(day1 < anchor) day1 -= 6;
if(day2 < anchor) day2 -= 6;
result = (day2 - anchor) / 7 - (day1 - anchor) / 7;
It would be nice to have a test case for negative value handling of this. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10459#note_139076