diff --git a/src/timescale.c b/src/timescale.c index fa6ddc23..9ffb25f1 100644 --- a/src/timescale.c +++ b/src/timescale.c @@ -253,7 +253,7 @@ double novas_get_time(const novas_timespec *time, enum novas_timescale timescale * @param[out] ijd [day] The integer part of the Julian date in the requested timescale. It may * be NULL if not required. * @return [day] The fractional part of the Julian date in the requested timescale or - * NAN is the time argument is NULL. + * NAN is the time argument is NULL (ijd will be set to -1 also). * * @sa novas_set_split_time() * @sa novas_get_time() @@ -265,6 +265,8 @@ double novas_get_split_time(const novas_timespec *time, enum novas_timescale tim static const char *fn = "novas_get_split_time"; double f; + if(ijd) *ijd = -1; + if(!time) { novas_error(-1, EINVAL, fn, "NULL input time specification"); return NAN; @@ -443,7 +445,7 @@ int novas_set_unix_time(time_t unix_time, long nanos, int leap, double dut1, nov * * @param time Pointer to the astronomical time specification data structure. * @param[out] nanos [ns] UTC sub-second component. It may be NULL if not required. - * @return [s] The integer UNIX time + * @return [s] The integer UNIX time, or -1 if the input time is NULL. * * @sa novas_set_unix_time() * @sa novas_get_time() @@ -457,8 +459,11 @@ time_t novas_get_unix_time(const novas_timespec *time, long *nanos) { time_t seconds; sod = novas_get_split_time(time, NOVAS_UTC, &ijd) * DAY; - if(isnan(sod)) - return novas_trace_nan("novas_get_unix_time"); + if(isnan(sod)) { + static const char *fn = "novas_get_unix_time"; + if(nanos) *nanos = novas_trace_nan(fn); + return novas_trace(fn, -1, 0); + } isod = (long) floor(sod); seconds = UNIX_J2000 + (ijd - IJD_J2000) * IDAY + isod; diff --git a/test/src/test-errors.c b/test/src/test-errors.c index 20d87c06..43d03d6f 100644 --- a/test/src/test-errors.c +++ b/test/src/test-errors.c @@ -1025,6 +1025,9 @@ static int test_time() { if(check_nan("time:get:scale:-1", novas_get_time(&time, -1))) n++; if(check_nan("time:get:scale:hi", novas_get_time(&time, NOVAS_TIMESCALES))) n++; + if(check("time:get_unix_time:time", -1, novas_offset_time(NULL, 0.1, &time))) n++; + if(check("time:get_unix_time:time+ijd", -1, novas_offset_time(NULL, 0.1, NULL))) n++; + if(check("time:offset:time", -1, novas_offset_time(NULL, 0.1, &time))) n++; if(check("time:offset:out", -1, novas_offset_time(&time, 0.1, NULL))) n++; if(check("time:offset:both", -1, novas_offset_time(NULL, 0.1, NULL))) n++; @@ -1033,6 +1036,15 @@ static int test_time() { if(check_nan("time:diff:t2", novas_diff_time(&time, NULL))) n++; if(check_nan("time:diff:both", novas_diff_time(NULL, NULL))) n++; + if(check_nan("time:diff_tcg:t1", novas_diff_tcg(NULL, &time))) n++; + if(check_nan("time:diff_tcg:t2", novas_diff_tcg(&time, NULL))) n++; + if(check_nan("time:diff_tcg:both", novas_diff_tcg(NULL, NULL))) n++; + + if(check_nan("time:diff_tcb:t1", novas_diff_tcb(NULL, &time))) n++; + if(check_nan("time:diff_tcb:t2", novas_diff_tcb(&time, NULL))) n++; + if(check_nan("time:diff_tcb:both", novas_diff_tcb(NULL, NULL))) n++; + + return n; }