Do somethnig like the following brute force approach:
int calulate_day_number_since_19000101(int year, int month, int day)
{
int days = 0;
for (int y = 1900; y < year; ++y)
{
days += 365;
if (is_leap_year(y)) days++;
}
for (int m = 1; m < month; ++m)
{
if (m == 2)
{
days += 28;
if (is_leap_year(year)) days++;
}
else if (m < 8)
{
days += m % 2 ? 31 : 30;
}
else
{
days += m % 2 ? 30 : 31;
}
}
days += day;
}
int is_leap_year(int year)
{
if (year % 400 == 0) return 1;
if (year % 100 == 0) return 0;
if (year % 4 == 0) return 1;
return 0;
}
calulate_day_number_since_19000101(1900, 1, 1);
returns 1.
calulate_day_number_since_19000101(2014, 4, 10);
returns 41738.
So, why 41739 is not clear to me... I guess the leap year calculation of your reference implementation is wrong: every 100th year is not a leap year, but every 400th year is a leap year again. If ignoring the above mentioned facts, I also get 41739.
Cheers
Andi
PS: Parsing the string into year, month, day is left as exercise ;-)