Closed smemsh closed 3 months ago
The problem may be here:
void Datetime::resolve ()
{
...
// Convert week + weekday --> julian.
if (week)
{
julian = (week * 7) + weekday - dayOfWeek (year, 1, 4) - 3;
}
...
}
and:
// Using Zeller's Congruence.
// Static
int Datetime::dayOfWeek (int year, int month, int day)
{
int adj = (14 - month) / 12;
int m = month + 12 * adj - 2;
int y = year - adj;
return (day + (13 * m - 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7;
}
As mentioned in the wikipedia page for Zeller, for ISO weeks there needs to be:
d = ((h + 5) % 7) + 1
somewhere in there. I'll try to figure it out and make a patch conditioned on weekstart = 1
.
There seems to be an issue in this library regarding week numbers and starting day of week.
ISO weeks start on Monday. The code seems to agree:
In the tests from
test/datetime.t.cpp
there are some initialized variables:We can see the
local1
date is december 1:Now the following test is performed:
So the test's expectation is that 2013 week 49 is December 1:
Yet, it isn't:
The week number is wrong, December 1 is still week 48, not week 49. The problem seems to be that it's treating Sunday as the first day of week 49.
Timewarrior does not set or pass
weekstart
to libshared anywhere, so presumably the libshared default is always used (weekstart = 1
, Monday, ISO weeks, as initialized above in Datetime.cpp:62).Taskwarrior does have an
rc.weekstart
, but it makes no difference:This is leading to problems such as in GothenburgBitFactory/timewarrior#595 and GothenburgBitFactory/taskwarrior#2922 with no obvious fix.
I will keep digging into this as time permits. If anyone else knows anything more about this, it would be helpful.