Commit 9380a061 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

julday_add_seconds: bug fix for adjusting negative seconds

parent 51bdc105
......@@ -35,7 +35,7 @@ void decode_time(int time, int *hour, int *minute, int *second)
int itime;
*hour = time / 10000;
itime = time - *hour*10000;
itime = time - *hour*10000;
*minute = itime / 100;
*second = itime - *minute*100;
}
......@@ -182,35 +182,39 @@ int sec_to_time(int secofday)
return (time);
}
void julday_add_seconds(int seconds, int *julday, int *secofday)
static
void adjust_seconds(int *julday, int *secofday)
{
int days;
int secperday = 86400;
*secofday += seconds;
while ( *secofday >= secperday )
{
*secofday -= secperday;
(*julday)++;
}
days = *secofday/86400;
while ( *secofday < 0 )
{
*secofday += secperday;
(*julday)--;
}
}
*secofday -= days*86400;
*julday += days;
void julday_add_seconds(int seconds, int *julday, int *secofday)
{
*secofday += seconds;
adjust_seconds(julday, secofday);
}
/* add days and secs to julday/secofday */
void julday_add(int days, int secs, int *julday, int *secofday)
{
int mdays;
*julday += days;
*julday += days;
*secofday += secs;
mdays = *secofday/86400;
if ( mdays > 0 )
{
*julday += mdays;
*secofday -= mdays*86400;
}
adjust_seconds(julday, secofday);
}
/* subtract julday1/secofday1 from julday2/secofday2 and returns the result in seconds */
......@@ -221,11 +225,7 @@ double julday_sub(int julday1, int secofday1, int julday2, int secofday2, int *d
*days = julday2 - julday1;
*secs = secofday2 - secofday1;
if ( *secs < 0 )
{
*days -= 1;
*secs += 86400;
}
adjust_seconds(days, secs);
seconds = *days*86400. + *secs;
......
......@@ -2,7 +2,7 @@
#define _TIMEBASE_H
/* date format: YYYYMMDD */
/* time format: hhmm */
/* time format: hhmmss */
void decode_date(int date, int *year, int *month, int *day);
int encode_date(int year, int month, int day);
......
Markdown is supported
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