Hi,
thanks to everybody for the support. I figured out how to do this stuff.
It's a bit tricky but this snippet should do the conversion:
(- {BTW I know it is ugly coding =;-P}
This code is provided as is and comes with no guaranty what so ever!
Feel free to avoid the pain I had by using this snippet.
-)
Thanks,
Martin
int isLeap(int year)
{
return ((year % 4) == 0 && ((year % 100) != 0 || (year % 400)==0));
}
void ConvertDate(long days, int &day, int &month, int &year)
{
long _days;
int yearlengths[] = {365,366};
int length[2][12];
length[1][0] = length[0][0] = 31;
length[0][1] = 28;
length[1][1] = 29;
length[1][2] = length[0][2] = 31;
length[1][3] = length[0][3] = 30;
length[1][4] = length[0][4] = 31;
length[1][5] = length[0][5] = 30;
length[1][6] = length[0][6] = 31;
length[1][7] = length[0][7] = 31;
length[1][8] = length[0][8] = 30;
length[1][9] = length[0][9] = 31;
length[1][10] = length[0][10] = 30;
length[1][11] = length[0][11] = 31;
_days = days & 0x7fffffff ;
_days--;
year = 1;
int *len;
int leap = 0;
while(_days<0 || _days >= yearlengths[leap = isLeap(year)])
{
int nyear = year + _days/365;
if(_days < 0)
{
nyear--;
}
_days -= (nyear - year)*365 + ((nyear-1)/4 - (nyear-1)/100 +
(nyear-1)/400) -
((year-1)/4 - (year-1)/100 + (year-1)/400);
year = nyear;
}
len = length[leap];
for(month = 0; _days >= len[month]; month++)
{
_days -= len[month];
}
month++;
_days++;
day = _days;
}