Commit d7754f9e authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

timebase:encode_julday bug fix for years < 0

parent fad976e0
...@@ -79,28 +79,33 @@ void decode_julday( ...@@ -79,28 +79,33 @@ void decode_julday(
/* convert year, month, day into Julian calendar day */ /* convert year, month, day into Julian calendar day */
int encode_julday(int year, int month, int day) int encode_julday(int year, int month, int day)
{ {
int y; int iy;
int m; int im;
int ib; int ib;
int julday; int julday;
if ( month <= 2 ) if ( month <= 2 )
{ {
y = year - 1; iy = year - 1;
m = month + 12; im = month + 12;
} }
else else
{ {
y = year; iy = year;
m = month; im = month;
} }
if ( iy < 0 )
ib = (int)((iy+1)/400) - (int)((iy+1)/100);
else
ib = (int)(iy/400) - (int)(iy/100);
if ( year > 1582 || (year == 1582 && (month > 10 || (month == 10 && day >= 15))) ) if ( year > 1582 || (year == 1582 && (month > 10 || (month == 10 && day >= 15))) )
{ {
/* /*
** 15th October 1582 AD or later ** 15th October 1582 AD or later
*/ */
ib = (int)(y/400) - (int)(y/100);
} }
else else
{ {
...@@ -110,7 +115,7 @@ int encode_julday(int year, int month, int day) ...@@ -110,7 +115,7 @@ int encode_julday(int year, int month, int day)
ib = -2; ib = -2;
} }
julday = (int) (floor(365.25*y) + (int)(30.6001*(m+1)) + ib + 1720996.5 + day + 0.5); julday = (int) (floor(365.25*iy) + (int)(30.6001*(im+1)) + ib + 1720996.5 + day + 0.5);
return (julday); return (julday);
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment